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.
This commit is contained in:
Eitan Levi
2020-01-24 16:22:49 -08:00
committed by Ben Lichtman
parent 642907bf7b
commit bc1087ecf1
4 changed files with 72 additions and 0 deletions

22
types/passport-microsoft/index.d.ts vendored Normal file
View File

@@ -0,0 +1,22 @@
// Type definitions for passport-microsoft 0.0
// Project: https://github.com/seanfisher/passport-microsoft#readme
// Definitions by: Eitan Levi <https://github.com/skrud>
// 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<oauth2.StrategyOptions, OptionalOptionParameters> & Partial<oauth2.StrategyOptions>;
export type MicrosoftStrategyOptionsWithRequest = Omit<oauth2.StrategyOptionsWithRequest, OptionalOptionParameters> & Partial<oauth2.StrategyOptionsWithRequest>;
export class Strategy extends oauth2.Strategy {
constructor(options: MicrosoftStrategyOptions, verify: oauth2.VerifyFunction);
constructor(options: MicrosoftStrategyOptionsWithRequest, verify: oauth2.VerifyFunctionWithRequest);
}

View File

@@ -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);
});
}
));

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }