Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#64222 passport-oauth2: enable provider spe…
Browse files Browse the repository at this point in the history
…cific profile and results by @joelklint
  • Loading branch information
joelklint authored Feb 9, 2023
1 parent e9daf07 commit 0229bb7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
32 changes: 26 additions & 6 deletions types/passport-oauth2/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Eduardo AC <https://github.com/EduardoAC>
// Ivan Fernandes <https://github.com/ivan94>
// Daphne Smit <https://github.com/daphnesmit>
// Joel Klint <https://github.com/JoelKlint>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3

Expand Down Expand Up @@ -54,12 +55,31 @@ declare namespace OAuth2Strategy {

type VerifyCallback = (err?: Error | null, user?: Express.User, info?: object) => void;

type VerifyFunction =
((accessToken: string, refreshToken: string, profile: any, verified: VerifyCallback) => void) |
((accessToken: string, refreshToken: string, results: any, profile: any, verified: VerifyCallback) => void);
type VerifyFunctionWithRequest =
((req: Request, accessToken: string, refreshToken: string, profile: any, verified: VerifyCallback) => void) |
((req: Request, accessToken: string, refreshToken: string, results: any, profile: any, verified: VerifyCallback) => void);
type VerifyFunction<TProfile = any, TResults = any> =
| ((accessToken: string, refreshToken: string, profile: TProfile, verified: VerifyCallback) => void)
| ((
accessToken: string,
refreshToken: string,
results: TResults,
profile: TProfile,
verified: VerifyCallback,
) => void);
type VerifyFunctionWithRequest<TProfile = any, TResults = any> =
| ((
req: Request,
accessToken: string,
refreshToken: string,
profile: TProfile,
verified: VerifyCallback,
) => void)
| ((
req: Request,
accessToken: string,
refreshToken: string,
results: TResults,
profile: TProfile,
verified: VerifyCallback,
) => void);

interface _StrategyOptionsBase {
authorizationURL: string;
Expand Down
21 changes: 21 additions & 0 deletions types/passport-oauth2/passport-oauth2-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,24 @@ const strategyOptions3: StrategyOptions = {
};

const strategy5: Strategy = new Strategy(strategyOptions3, verifyFunction2);

interface ProviderSpecificProfile {
someProviderProfileField: string;
}
interface ProviderSpecificResults {
someProviderResultField: string;
}
const providerSpecificVerifyFunction: OAuth2Strategy.VerifyFunction<
ProviderSpecificProfile,
ProviderSpecificResults
> = (accessToken, refreshToken, results, profile, verified) => {
results.someProviderResultField;
profile.someProviderProfileField;
};
const providerSpecificVerifyFunctionWithRequest: OAuth2Strategy.VerifyFunctionWithRequest<
ProviderSpecificProfile,
ProviderSpecificResults
> = (req, accessToken, refreshToken, results, profile, verified) => {
results.someProviderResultField;
profile.someProviderProfileField;
};

0 comments on commit 0229bb7

Please sign in to comment.