From bc1087ecf17988200704ce2503cc6d5caefebd3a Mon Sep 17 00:00:00 2001 From: Eitan Levi Date: Fri, 24 Jan 2020 16:22:49 -0800 Subject: [PATCH] Add types for passport-microsoft (#41827) This adds types for the passport-microsoft package, which is a library for authenticating with Microsoft's GraphQL API over OAuth2 using PassportJs. --- types/passport-microsoft/index.d.ts | 22 ++++++++++++++++ .../passport-microsoft-tests.ts | 26 +++++++++++++++++++ types/passport-microsoft/tsconfig.json | 23 ++++++++++++++++ types/passport-microsoft/tslint.json | 1 + 4 files changed, 72 insertions(+) create mode 100644 types/passport-microsoft/index.d.ts create mode 100644 types/passport-microsoft/passport-microsoft-tests.ts create mode 100644 types/passport-microsoft/tsconfig.json create mode 100644 types/passport-microsoft/tslint.json diff --git a/types/passport-microsoft/index.d.ts b/types/passport-microsoft/index.d.ts new file mode 100644 index 0000000000..0a799442b8 --- /dev/null +++ b/types/passport-microsoft/index.d.ts @@ -0,0 +1,22 @@ +// Type definitions for passport-microsoft 0.0 +// Project: https://github.com/seanfisher/passport-microsoft#readme +// Definitions by: Eitan Levi +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.5 + +import * as oauth2 from 'passport-oauth2'; + +// Disable automatic exporting +export {}; + +// The passport-microsoft library provides defaults for these fields, so they become optional +// when calling the constructor. (No need to export this). +type OptionalOptionParameters = 'authorizationURL' | 'tokenURL' | 'scopeSeparator' | 'customHeaders'; + +export type MicrosoftStrategyOptions = Omit & Partial; +export type MicrosoftStrategyOptionsWithRequest = Omit & Partial; + +export class Strategy extends oauth2.Strategy { + constructor(options: MicrosoftStrategyOptions, verify: oauth2.VerifyFunction); + constructor(options: MicrosoftStrategyOptionsWithRequest, verify: oauth2.VerifyFunctionWithRequest); +} diff --git a/types/passport-microsoft/passport-microsoft-tests.ts b/types/passport-microsoft/passport-microsoft-tests.ts new file mode 100644 index 0000000000..1384a8d782 --- /dev/null +++ b/types/passport-microsoft/passport-microsoft-tests.ts @@ -0,0 +1,26 @@ +import passport = require('passport'); +import { Strategy as MicrosoftStrategy } from 'passport-microsoft'; + +// Just some test model. +const User = { + findOrCreate( + id: string, + provider: string, + callback: (err: any, user: any) => void + ): void { + callback(null, { username: "arnold" }); + } +}; + +passport.use(new MicrosoftStrategy( + { + clientID: 'thisIsMyClientId', + clientSecret: 'thisIsMyClientSecret' + }, + (accessToken: string, refreshToken: string, profile: passport.Profile, done: (error: any, user?: any) => void) => { + User.findOrCreate(profile.id, profile.provider, (err, user) => { + if (err) { done(err); return; } + done(null, user); + }); + } +)); diff --git a/types/passport-microsoft/tsconfig.json b/types/passport-microsoft/tsconfig.json new file mode 100644 index 0000000000..0e4dd480d2 --- /dev/null +++ b/types/passport-microsoft/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "passport-microsoft-tests.ts" + ] +} diff --git a/types/passport-microsoft/tslint.json b/types/passport-microsoft/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/passport-microsoft/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }