From 82af2f0af96d7b831fcacc7d8e537aeec1fe67bb Mon Sep 17 00:00:00 2001 From: Andrew Vetovitz Date: Fri, 21 Dec 2018 00:40:26 -0500 Subject: [PATCH 1/8] added passport-linkedin-oauth2 --- types/passport-linkedin-oauth2/index.d.ts | 53 +++++++++++++++++++ .../passport-linkedin-oauth2-tests.ts | 42 +++++++++++++++ types/passport-linkedin-oauth2/tsconfig.json | 23 ++++++++ types/passport-linkedin-oauth2/tslint.json | 1 + 4 files changed, 119 insertions(+) create mode 100644 types/passport-linkedin-oauth2/index.d.ts create mode 100644 types/passport-linkedin-oauth2/passport-linkedin-oauth2-tests.ts create mode 100644 types/passport-linkedin-oauth2/tsconfig.json create mode 100644 types/passport-linkedin-oauth2/tslint.json diff --git a/types/passport-linkedin-oauth2/index.d.ts b/types/passport-linkedin-oauth2/index.d.ts new file mode 100644 index 0000000000..e3668d6840 --- /dev/null +++ b/types/passport-linkedin-oauth2/index.d.ts @@ -0,0 +1,53 @@ +// Type definitions for passport-linkedin +// Project: https://github.com/TOOD/passport-linkedin +// Definitions by: Andrew Vetovitz +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.2 + +import passport = require('passport'); +import express = require('express'); + +export interface Profile extends passport.Profile { + id: string; + displayName: string; + name: { + familyName: string; + givenName: string; + }; + emails: [{ value: string }]; + photos: [ { value: string }]; + _raw: string; + _json: any; +} + +export interface AuthenticateOptions extends passport.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: express.Request, accessToken: string, refreshToken: string, profile: Profile, done: (error: any, user?: any, info?: any) => void) => void; + +export class Strategy extends passport.Strategy { + constructor(options: StrategyOptionWithRequest, verify: VerifyFunctionWithRequest); + constructor(options: StrategyOption, verify: VerifyFunction); + + name: string; + authenticate(req: express.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..faa2e83264 --- /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..637a5dbe30 --- /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" } From b0fce1c897536cfe5fd4ab86f385def20edfd771 Mon Sep 17 00:00:00 2001 From: Andrew Vetovitz Date: Fri, 21 Dec 2018 19:56:18 -0500 Subject: [PATCH 2/8] commiting small changes to passport linkedin --- types/passport-linkedin-oauth2/index.d.ts | 24 ++++++++++--------- .../passport-linkedin-oauth2-tests.ts | 6 ++--- types/passport-linkedin-oauth2/tsconfig.json | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/types/passport-linkedin-oauth2/index.d.ts b/types/passport-linkedin-oauth2/index.d.ts index e3668d6840..af4ee8f416 100644 --- a/types/passport-linkedin-oauth2/index.d.ts +++ b/types/passport-linkedin-oauth2/index.d.ts @@ -1,13 +1,15 @@ -// Type definitions for passport-linkedin -// Project: https://github.com/TOOD/passport-linkedin +// Type definitions for passport-linkedin-oauth2 +// Project: https://github.com/auth0/passport-linkedin-oauth2 // Definitions by: Andrew Vetovitz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 3.2 +// TypeScript Version: 2.8 -import passport = require('passport'); -import express = require('express'); +/// -export interface Profile extends passport.Profile { +import { Profile as passportProfile, AuthenticateOptions, Strategy as passportStrategy } from 'passport'; +import { Request } from 'express'; + +export interface Profile extends passportProfile { id: string; displayName: string; name: { @@ -15,12 +17,12 @@ export interface Profile extends passport.Profile { givenName: string; }; emails: [{ value: string }]; - photos: [ { value: string }]; + photos: [{ value: string }]; _raw: string; _json: any; } -export interface AuthenticateOptions extends passport.AuthenticateOptions { +export interface AuthenticateOptions extends AuthenticateOptions { authType?: string; } @@ -42,12 +44,12 @@ export type VerifyFunction = (accessToken: string, refreshToken: string, profile: Profile, done: (error: any, user?: any, info?: any) => void) => void; export type VerifyFunctionWithRequest = - (req: express.Request, accessToken: string, refreshToken: string, profile: Profile, done: (error: any, user?: any, info?: any) => void) => void; + (req: Request, accessToken: string, refreshToken: string, profile: Profile, done: (error: any, user?: any, info?: any) => void) => void; -export class Strategy extends passport.Strategy { +export class Strategy extends passportStrategy { constructor(options: StrategyOptionWithRequest, verify: VerifyFunctionWithRequest); constructor(options: StrategyOption, verify: VerifyFunction); name: string; - authenticate(req: express.Request, options?: object): void; + 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 index faa2e83264..18184386b0 100644 --- a/types/passport-linkedin-oauth2/passport-linkedin-oauth2-tests.ts +++ b/types/passport-linkedin-oauth2/passport-linkedin-oauth2-tests.ts @@ -16,15 +16,15 @@ 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"); + throw new Error("callbackURL is undefined"); } if (typeof clientID === "undefined") { - throw new Error("clientID is undefined"); + throw new Error("clientID is undefined"); } if (typeof clientSecret === "undefined") { - throw new Error("clientSecret is undefined"); + throw new Error("clientSecret is undefined"); } passport.use(new linkedin.Strategy( diff --git a/types/passport-linkedin-oauth2/tsconfig.json b/types/passport-linkedin-oauth2/tsconfig.json index 637a5dbe30..9ab4616fe8 100644 --- a/types/passport-linkedin-oauth2/tsconfig.json +++ b/types/passport-linkedin-oauth2/tsconfig.json @@ -15,7 +15,7 @@ "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true - }, + }, "files": [ "index.d.ts", "passport-linkedin-oauth2-tests.ts" From e2b5e6a3776a10930ea7f8b7b9a47425245c739c Mon Sep 17 00:00:00 2001 From: Andrew Vetovitz Date: Fri, 21 Dec 2018 19:59:35 -0500 Subject: [PATCH 3/8] update headers for passport-linkedin --- types/passport-linkedin-oauth2/index.d.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/types/passport-linkedin-oauth2/index.d.ts b/types/passport-linkedin-oauth2/index.d.ts index af4ee8f416..da777b7b41 100644 --- a/types/passport-linkedin-oauth2/index.d.ts +++ b/types/passport-linkedin-oauth2/index.d.ts @@ -1,11 +1,9 @@ -// Type definitions for passport-linkedin-oauth2 +// Type definitions for passport-linkedin-oauth2 1.5.0 // Project: https://github.com/auth0/passport-linkedin-oauth2 // Definitions by: Andrew Vetovitz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 -/// - import { Profile as passportProfile, AuthenticateOptions, Strategy as passportStrategy } from 'passport'; import { Request } from 'express'; From 5f3eac430fe99ffc4aa8e9922190edb429e2b222 Mon Sep 17 00:00:00 2001 From: Andrew Vetovitz Date: Fri, 21 Dec 2018 20:01:12 -0500 Subject: [PATCH 4/8] updating patch version again --- types/passport-linkedin-oauth2/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/passport-linkedin-oauth2/index.d.ts b/types/passport-linkedin-oauth2/index.d.ts index da777b7b41..4262f0512a 100644 --- a/types/passport-linkedin-oauth2/index.d.ts +++ b/types/passport-linkedin-oauth2/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for passport-linkedin-oauth2 1.5.0 +// 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 From 893234f7e518815e522425c154825680d70b72f5 Mon Sep 17 00:00:00 2001 From: Andrew Vetovitz Date: Fri, 21 Dec 2018 20:01:21 -0500 Subject: [PATCH 5/8] updating patch version again --- types/passport-linkedin-oauth2/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/passport-linkedin-oauth2/index.d.ts b/types/passport-linkedin-oauth2/index.d.ts index 4262f0512a..a440b49528 100644 --- a/types/passport-linkedin-oauth2/index.d.ts +++ b/types/passport-linkedin-oauth2/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/auth0/passport-linkedin-oauth2 // Definitions by: Andrew Vetovitz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.8 +// TypeScript Version: 3.2 import { Profile as passportProfile, AuthenticateOptions, Strategy as passportStrategy } from 'passport'; import { Request } from 'express'; From a887e760ca19bbab8fec59ffe1795e7b4cffdbd9 Mon Sep 17 00:00:00 2001 From: Andrew Vetovitz Date: Fri, 21 Dec 2018 20:02:46 -0500 Subject: [PATCH 6/8] updating typescript version --- types/passport-linkedin-oauth2/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/passport-linkedin-oauth2/index.d.ts b/types/passport-linkedin-oauth2/index.d.ts index a440b49528..6065c44a28 100644 --- a/types/passport-linkedin-oauth2/index.d.ts +++ b/types/passport-linkedin-oauth2/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/auth0/passport-linkedin-oauth2 // Definitions by: Andrew Vetovitz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 3.2 +// typesVerisons: 3.2 import { Profile as passportProfile, AuthenticateOptions, Strategy as passportStrategy } from 'passport'; import { Request } from 'express'; From 033c8608e375a15bf4fae18a5046426a2dd52f57 Mon Sep 17 00:00:00 2001 From: Andrew Vetovitz Date: Fri, 21 Dec 2018 20:05:04 -0500 Subject: [PATCH 7/8] updating typescript version once again for compatability --- types/passport-linkedin-oauth2/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/passport-linkedin-oauth2/index.d.ts b/types/passport-linkedin-oauth2/index.d.ts index 6065c44a28..4262f0512a 100644 --- a/types/passport-linkedin-oauth2/index.d.ts +++ b/types/passport-linkedin-oauth2/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/auth0/passport-linkedin-oauth2 // Definitions by: Andrew Vetovitz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// typesVerisons: 3.2 +// TypeScript Version: 2.8 import { Profile as passportProfile, AuthenticateOptions, Strategy as passportStrategy } from 'passport'; import { Request } from 'express'; From 6ec50109f4ce52cd66611abffec3bcb1d4c4cfd2 Mon Sep 17 00:00:00 2001 From: Andrew Vetovitz Date: Fri, 21 Dec 2018 20:07:01 -0500 Subject: [PATCH 8/8] downgrading typescript version againj --- types/passport-linkedin-oauth2/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/passport-linkedin-oauth2/index.d.ts b/types/passport-linkedin-oauth2/index.d.ts index 4262f0512a..36d7d76779 100644 --- a/types/passport-linkedin-oauth2/index.d.ts +++ b/types/passport-linkedin-oauth2/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/auth0/passport-linkedin-oauth2 // Definitions by: Andrew Vetovitz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.8 +// TypeScript Version: 2.3 import { Profile as passportProfile, AuthenticateOptions, Strategy as passportStrategy } from 'passport'; import { Request } from 'express';