diff --git a/types/passport-linkedin-oauth2/index.d.ts b/types/passport-linkedin-oauth2/index.d.ts new file mode 100644 index 0000000000..36d7d76779 --- /dev/null +++ b/types/passport-linkedin-oauth2/index.d.ts @@ -0,0 +1,53 @@ +// Type definitions for passport-linkedin-oauth2 1.5 +// Project: https://github.com/auth0/passport-linkedin-oauth2 +// Definitions by: Andrew Vetovitz +// 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; +} diff --git a/types/passport-linkedin-oauth2/passport-linkedin-oauth2-tests.ts b/types/passport-linkedin-oauth2/passport-linkedin-oauth2-tests.ts new file mode 100644 index 0000000000..18184386b0 --- /dev/null +++ b/types/passport-linkedin-oauth2/passport-linkedin-oauth2-tests.ts @@ -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); + }); + }) +); diff --git a/types/passport-linkedin-oauth2/tsconfig.json b/types/passport-linkedin-oauth2/tsconfig.json new file mode 100644 index 0000000000..9ab4616fe8 --- /dev/null +++ b/types/passport-linkedin-oauth2/tsconfig.json @@ -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" + ] +} \ No newline at end of file diff --git a/types/passport-linkedin-oauth2/tslint.json b/types/passport-linkedin-oauth2/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/passport-linkedin-oauth2/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }