[passport-google-oauth20] Extend Strategy constructor overloads (#46492)

* Extend constructor overloads

Allow for verify callbacks that include `params` returned by `getOAuthAccessToken`.

* Remove unused import

* Fix import pattern

* Revert import pattern
This commit is contained in:
Raghuvir Kasturi 2020-09-12 03:49:32 +12:00 committed by GitHub
parent 8258289db3
commit 6836850295
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 73 additions and 1 deletions

View File

@ -10,7 +10,6 @@
import * as passport from "passport";
import * as express from "express";
import * as oauth2 from "passport-oauth2";
import { OutgoingHttpHeaders } from "http";
export type OAuth2StrategyOptionsWithoutRequiredURLs = Pick<
oauth2._StrategyOptionsBase,
@ -54,6 +53,16 @@ export class Strategy extends oauth2.Strategy {
done: VerifyCallback
) => void
);
constructor(
options: StrategyOptions,
verify: (
accessToken: string,
refreshToken: string,
params: any,
profile: Profile,
done: VerifyCallback
) => void
);
constructor(
options: StrategyOptionsWithRequest,
verify: (
@ -64,6 +73,17 @@ export class Strategy extends oauth2.Strategy {
done: VerifyCallback
) => void
);
constructor(
options: StrategyOptionsWithRequest,
verify: (
req: express.Request,
accessToken: string,
refreshToken: string,
params: any,
profile: Profile,
done: VerifyCallback
) => void
);
}
// additional Google-specific options

View File

@ -78,3 +78,55 @@ passport.use(
}
)
);
passport.use(
new google.Strategy(
{
callbackURL,
clientID,
clientSecret,
passReqToCallback: true
},
(
request: express.Request,
accessToken: string,
refreshToken: string,
params: any,
profile: google.Profile,
done: (error: any, user?: any) => void
) => {
User.findOrCreate(profile.id, profile.provider, (err, user) => {
if (err) {
done(err);
return;
}
done(null, user);
});
}
)
);
passport.use(
new google.Strategy(
{
callbackURL,
clientID,
clientSecret,
},
(
accessToken: string,
refreshToken: string,
params: any,
profile: google.Profile,
done: (error: any, user?: any) => void
) => {
User.findOrCreate(profile.id, profile.provider, (err, user) => {
if (err) {
done(err);
return;
}
done(null, user);
});
}
)
);