Merge pull request #31600 from AndrewVetovitz/master

Adding type definition for passport-linkedin-oauth2
This commit is contained in:
Wesley Wigham
2018-12-24 21:31:43 -08:00
committed by GitHub
4 changed files with 119 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
// Type definitions for passport-linkedin-oauth2 1.5
// Project: https://github.com/auth0/passport-linkedin-oauth2
// Definitions by: Andrew Vetovitz <https://github.com/andrewvetovitz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import { Profile as passportProfile, AuthenticateOptions, Strategy as passportStrategy } from 'passport';
import { Request } from 'express';
export interface Profile extends passportProfile {
id: string;
displayName: string;
name: {
familyName: string;
givenName: string;
};
emails: [{ value: string }];
photos: [{ value: string }];
_raw: string;
_json: any;
}
export interface AuthenticateOptions extends AuthenticateOptions {
authType?: string;
}
export interface StrategyOption {
clientID: string;
clientSecret: string;
callbackURL: string;
scopeSeparator?: string;
enableProof?: boolean;
profileFields?: string[];
}
export interface StrategyOptionWithRequest extends StrategyOption {
passReqToCallback: true;
}
export type VerifyFunction =
(accessToken: string, refreshToken: string, profile: Profile, done: (error: any, user?: any, info?: any) => void) => void;
export type VerifyFunctionWithRequest =
(req: Request, accessToken: string, refreshToken: string, profile: Profile, done: (error: any, user?: any, info?: any) => void) => void;
export class Strategy extends passportStrategy {
constructor(options: StrategyOptionWithRequest, verify: VerifyFunctionWithRequest);
constructor(options: StrategyOption, verify: VerifyFunction);
name: string;
authenticate(req: Request, options?: object): void;
}
@@ -0,0 +1,42 @@
/**
* Created by andrewvetovitz on 12/21/2018.
*/
import passport = require('passport');
import linkedin = require('passport-linkedin-oauth2');
// just some test model
const User = {
findOrCreate(id: string, provider: string, callback: (err: any, user: any) => void): void {
callback(null, { username: 'james' });
}
};
const callbackURL = process.env.PASSPORT_LINKEDIN_CALLBACK_URL;
const clientID = process.env.PASSPORT_LINKEDIN_CONSUMER_KEY;
const clientSecret = process.env.PASSPORT_LINKEDIN_CONSUMER_SECRET;
if (typeof callbackURL === "undefined") {
throw new Error("callbackURL is undefined");
}
if (typeof clientID === "undefined") {
throw new Error("clientID is undefined");
}
if (typeof clientSecret === "undefined") {
throw new Error("clientSecret is undefined");
}
passport.use(new linkedin.Strategy(
{
callbackURL,
clientID,
clientSecret
},
(accessToken: string, refreshToken: string, profile: linkedin.Profile, done: (error: any, user?: any) => void) => {
User.findOrCreate(profile.id, profile.provider, (err, user) => {
if (err) { done(err); return; }
done(null, user);
});
})
);
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"passport-linkedin-oauth2-tests.ts"
]
}
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }