From 62bfb774fcdf9e7d239503bf0d6833e2967fcb51 Mon Sep 17 00:00:00 2001 From: Manuel Ruck Date: Wed, 16 Jan 2019 20:19:26 +0100 Subject: [PATCH 1/5] Update passport-saml type definitions. --- types/passport-github/index.d.ts | 27 +++++++++++++++---- .../passport-github/passport-github-tests.ts | 22 ++++++++++++--- .../passport-github2-tests.ts | 6 ++--- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/types/passport-github/index.d.ts b/types/passport-github/index.d.ts index 99c84bd391..9dfe73d382 100644 --- a/types/passport-github/index.d.ts +++ b/types/passport-github/index.d.ts @@ -1,33 +1,50 @@ // Type definitions for passport-github 1.1 // Project: https://github.com/jaredhanson/passport-github -// Definitions by: Yasunori Ohoka +// Definitions by: Yasunori Ohoka +// Manuel Ruck // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.8 import passport = require('passport'); import express = require('express'); +import OAuth2 = require('passport-oauth2'); +import { OutgoingHttpHeaders } from 'http'; export interface Profile extends passport.Profile { profileUrl: string; } -export interface StrategyOption { +export interface StrategyOptionBase { clientID: string; clientSecret: string; callbackURL: string; scope?: string[]; userAgent?: string; + state?: string; authorizationURL?: string; tokenURL?: string; scopeSeparator?: string; - customHeaders?: string; + customHeaders?: OutgoingHttpHeaders; userProfileURL?: string; } +export type OAuth2StrategyOptionsWithoutRequiredURLs = Pick< + OAuth2._StrategyOptionsBase, + Exclude +>; + +export interface StrategyOption extends StrategyOptionBase { + passReqToCallback?: false; +} +export interface StrategyOptionWithRequest extends StrategyOptionBase { + passReqToCallback: true; +} + export class Strategy extends passport.Strategy { - constructor(options: StrategyOption, verify: (accessToken: string, refreshToken: string, profile: Profile, done: (error: any, user?: any) => void) => void); + constructor(options: StrategyOption, verify: OAuth2.VerifyFunction); + constructor(options: StrategyOptionWithRequest, verify: OAuth2.VerifyFunctionWithRequest); userProfile: (accessToken: string, done?: (error: any, profile: Profile) => void) => void; name: string; diff --git a/types/passport-github/passport-github-tests.ts b/types/passport-github/passport-github-tests.ts index fb8dc73d76..11a7a8f328 100644 --- a/types/passport-github/passport-github-tests.ts +++ b/types/passport-github/passport-github-tests.ts @@ -3,6 +3,7 @@ */ import passport = require('passport'); import github = require('passport-github'); +import express = require('express'); // just some test model const User = { @@ -16,15 +17,15 @@ const clientID = process.env.PASSPORT_GITHUB_CONSUMER_KEY; const clientSecret = process.env.PASSPORT_GITHUB_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 github.Strategy( @@ -40,3 +41,18 @@ passport.use(new github.Strategy( }); }) ); + +passport.use(new github.Strategy( + { + callbackURL, + clientID, + clientSecret, + passReqToCallback: true + }, + (request: express.Request, accessToken: string, refreshToken: string, profile: github.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-github2/passport-github2-tests.ts b/types/passport-github2/passport-github2-tests.ts index c8126ee41a..6aa658af64 100644 --- a/types/passport-github2/passport-github2-tests.ts +++ b/types/passport-github2/passport-github2-tests.ts @@ -17,15 +17,15 @@ const clientID = process.env.PASSPORT_GITHUB_CONSUMER_KEY; const clientSecret = process.env.PASSPORT_GITHUB_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 github.Strategy( From 18c5e5c6148b523d51cd2f9c27a826ed96cf7097 Mon Sep 17 00:00:00 2001 From: Manuel Ruck Date: Wed, 16 Jan 2019 21:40:11 +0100 Subject: [PATCH 2/5] fix verify in constructor --- types/passport-github/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/passport-github/index.d.ts b/types/passport-github/index.d.ts index 9dfe73d382..4eaa13e359 100644 --- a/types/passport-github/index.d.ts +++ b/types/passport-github/index.d.ts @@ -43,8 +43,8 @@ export interface StrategyOptionWithRequest extends StrategyOptionBase { } export class Strategy extends passport.Strategy { - constructor(options: StrategyOption, verify: OAuth2.VerifyFunction); - constructor(options: StrategyOptionWithRequest, verify: OAuth2.VerifyFunctionWithRequest); + constructor(options: StrategyOption, verify: (accessToken: string, refreshToken: string, profile: Profile, done: (error: any, user?: any) => void) => void); + constructor(options: StrategyOptionWithRequest, verify: (req: express.Request, accessToken: string, refreshToken: string, profile: Profile, done: (error: any, user?: any) => void) => void); userProfile: (accessToken: string, done?: (error: any, profile: Profile) => void) => void; name: string; From 9e4bef07c73d5e2f690f3bcc0167987eda74921e Mon Sep 17 00:00:00 2001 From: Manuel Ruck Date: Wed, 16 Jan 2019 21:48:32 +0100 Subject: [PATCH 3/5] increase version --- types/passport-github/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/passport-github/index.d.ts b/types/passport-github/index.d.ts index 4eaa13e359..bf20ed7ea6 100644 --- a/types/passport-github/index.d.ts +++ b/types/passport-github/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for passport-github 1.1 +// Type definitions for passport-github 1.2 // Project: https://github.com/jaredhanson/passport-github // Definitions by: Yasunori Ohoka // Manuel Ruck From 702679027bea3b6d7a4c92bef621ae00b955c0ca Mon Sep 17 00:00:00 2001 From: ManAnRuck Date: Thu, 17 Jan 2019 12:09:05 +0100 Subject: [PATCH 4/5] revert spaces change in other types lib --- types/passport-github2/passport-github2-tests.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/passport-github2/passport-github2-tests.ts b/types/passport-github2/passport-github2-tests.ts index 6aa658af64..c8126ee41a 100644 --- a/types/passport-github2/passport-github2-tests.ts +++ b/types/passport-github2/passport-github2-tests.ts @@ -17,15 +17,15 @@ const clientID = process.env.PASSPORT_GITHUB_CONSUMER_KEY; const clientSecret = process.env.PASSPORT_GITHUB_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 github.Strategy( From 55948bf9cf178f8167d554282512e326ce056456 Mon Sep 17 00:00:00 2001 From: ManAnRuck Date: Wed, 23 Jan 2019 10:21:43 +0100 Subject: [PATCH 5/5] Update index.d.ts --- types/passport-github/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/passport-github/index.d.ts b/types/passport-github/index.d.ts index bf20ed7ea6..4eaa13e359 100644 --- a/types/passport-github/index.d.ts +++ b/types/passport-github/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for passport-github 1.2 +// Type definitions for passport-github 1.1 // Project: https://github.com/jaredhanson/passport-github // Definitions by: Yasunori Ohoka // Manuel Ruck