@types/passport-auth0: Add default export to type definition (#42315)

* Add default export to type definition

* Add my name

* Update test

* Commit to prevent bot from auto-closing

* Try other export format

* Add declare

* Change back to export

* Try `export default`

* Add module

* Remove module again

* Fix imports

* Upgrade imports

* Revert imports

* Revert imports

* Try using default instead

* Revert test

Cannot test for a default import

Ref: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/41948#issuecomment-585441968

* Try wrapping in namespace

* Fix or disable linting errors

* Try with different namespace merging

* Fix interface access
This commit is contained in:
Karl Horky 2020-02-18 23:17:03 +01:00 committed by GitHub
parent 42bb035f82
commit e73517f0d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 135 additions and 95 deletions

View File

@ -3,73 +3,85 @@
// Definitions by: John Umeh <https://github.com/johnbendi>
// Vishnu Sankar <https://github.com/iamvishnusankar>
// Duncan Hall <https://github.com/duncanhall>
// Karl Horky <https://github.com/karlhorky>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import passport = require('passport');
import express = require('express');
export interface Profile extends passport.Profile {
id: string;
displayName: string;
gender?: string;
ageRange?: {
min: number;
max?: number;
};
profileUrl?: string;
username?: string;
birthday: string;
_raw: string;
_json: any;
}
export interface AuthenticateOptions extends passport.AuthenticateOptions {
authType?: string;
}
export interface StrategyOption {
clientID: string;
clientSecret: string;
callbackURL: string;
domain: string;
scopeSeparator?: string;
enableProof?: boolean;
profileFields?: string[];
state?: boolean;
}
export interface StrategyOptionWithRequest extends StrategyOption {
passReqToCallback: true;
}
export interface ExtraVerificationParams {
audience?: string;
connection?: string;
prompt?: string;
}
export type VerifyFunction = (
accessToken: string,
refreshToken: string,
extraParams: ExtraVerificationParams,
profile: Profile,
done: (error: any, user?: any, info?: any) => void
) => void;
export type VerifyFunctionWithRequest = (
req: express.Request,
accessToken: string,
refreshToken: string,
extraParams: ExtraVerificationParams,
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);
declare class StrategyInternal extends passport.Strategy {
constructor(
options: StrategyInternal.StrategyOptionWithRequest,
verify: StrategyInternal.VerifyFunctionWithRequest,
);
constructor(options: StrategyInternal.StrategyOption, verify: StrategyInternal.VerifyFunction);
name: string;
authenticate(req: express.Request, options?: object): void;
}
declare namespace StrategyInternal {
interface Profile extends passport.Profile {
id: string;
displayName: string;
gender?: string;
ageRange?: {
min: number;
max?: number;
};
profileUrl?: string;
username?: string;
birthday: string;
_raw: string;
_json: any;
}
interface AuthenticateOptions extends passport.AuthenticateOptions {
authType?: string;
}
interface StrategyOption {
clientID: string;
clientSecret: string;
callbackURL: string;
domain: string;
scopeSeparator?: string;
enableProof?: boolean;
profileFields?: string[];
state?: boolean;
}
interface StrategyOptionWithRequest extends StrategyOption {
passReqToCallback: true;
}
interface ExtraVerificationParams {
audience?: string;
connection?: string;
prompt?: string;
}
type VerifyFunction = (
accessToken: string,
refreshToken: string,
extraParams: ExtraVerificationParams,
profile: Profile,
done: (error: any, user?: any, info?: any) => void,
) => void;
type VerifyFunctionWithRequest = (
req: express.Request,
accessToken: string,
refreshToken: string,
extraParams: ExtraVerificationParams,
profile: Profile,
done: (error: any, user?: any, info?: any) => void,
) => void;
// NOTE: not true for `export import` statements
// tslint:disable-next-line:strict-export-declare-modifiers
export import Strategy = StrategyInternal;
}
export = StrategyInternal;

View File

@ -9,45 +9,73 @@ import express = require('express');
const User = {
findOrCreate(id: string, provider: string, callback: (err: any, user: any) => void): void {
callback(null, { username: 'james' });
}
},
};
passport.use(new auth0.Strategy({
clientID: process.env.PASSPORT_AUTH0_CLIENT_ID as string,
clientSecret: process.env.PASSPORT_AUTH0_CLIENT_SECRET as string,
callbackURL: process.env.PASSPORT_AUTH0_CALLBACK_URL as string,
domain : process.env.PASSPORT_AUTH0_DOMAIN as string
},
(accessToken: string, refreshToken: string, extraParams: auth0.ExtraVerificationParams, profile: auth0.Profile, done: (error: any, user?: any) => void) => {
User.findOrCreate(profile.id, profile.provider, (err, user) => {
if (err) done(err);
else done(null, user);
});
})
passport.use(
new auth0(
{
clientID: process.env.PASSPORT_AUTH0_CLIENT_ID as string,
clientSecret: process.env.PASSPORT_AUTH0_CLIENT_SECRET as string,
callbackURL: process.env.PASSPORT_AUTH0_CALLBACK_URL as string,
domain: process.env.PASSPORT_AUTH0_DOMAIN as string,
},
(
accessToken: string,
refreshToken: string,
extraParams: auth0.ExtraVerificationParams,
profile: auth0.Profile,
done: (error: any, user?: any) => void,
) => {
User.findOrCreate(profile.id, profile.provider, (err, user) => {
if (err) done(err);
else done(null, user);
});
},
),
);
passport.use(new auth0.Strategy({
clientID: process.env.PASSPORT_AUTH0_CLIENT_ID as string,
clientSecret: process.env.PASSPORT_AUTH0_CLIENT_SECRET as string,
callbackURL: process.env.PASSPORT_AUTH0_CALLBACK_URL as string,
domain : process.env.PASSPORT_AUTH0_DOMAIN as string,
passReqToCallback: true
},
(req: express.Request, accessToken: string, refreshToken: string, extraParams: auth0.ExtraVerificationParams, profile: auth0.Profile, done: (error: any, user?: any) => void) => {
User.findOrCreate(profile.id, profile.provider, (err, user) => {
if (err) done(err);
else done(null, user);
});
})
passport.use(
new auth0.Strategy(
{
clientID: process.env.PASSPORT_AUTH0_CLIENT_ID as string,
clientSecret: process.env.PASSPORT_AUTH0_CLIENT_SECRET as string,
callbackURL: process.env.PASSPORT_AUTH0_CALLBACK_URL as string,
domain: process.env.PASSPORT_AUTH0_DOMAIN as string,
passReqToCallback: true,
},
(
req: express.Request,
accessToken: string,
refreshToken: string,
extraParams: auth0.ExtraVerificationParams,
profile: auth0.Profile,
done: (error: any, user?: any) => void,
) => {
User.findOrCreate(profile.id, profile.provider, (err, user) => {
if (err) done(err);
else done(null, user);
});
},
),
);
passport.use(new auth0.Strategy({
clientID: process.env.PASSPORT_AUTH0_CLIENT_ID as string,
clientSecret: process.env.PASSPORT_AUTH0_CLIENT_SECRET as string,
callbackURL: process.env.PASSPORT_AUTH0_CALLBACK_URL as string,
domain : process.env.PASSPORT_AUTH0_DOMAIN as string
},
(accessToken: string, refreshToken: string, extraParams: auth0.ExtraVerificationParams, profile: auth0.Profile, done: (error: any, user?: any, info?: any) => void) => {
done(null, false, { message: 'Some error.' });
})
passport.use(
new auth0.Strategy(
{
clientID: process.env.PASSPORT_AUTH0_CLIENT_ID as string,
clientSecret: process.env.PASSPORT_AUTH0_CLIENT_SECRET as string,
callbackURL: process.env.PASSPORT_AUTH0_CALLBACK_URL as string,
domain: process.env.PASSPORT_AUTH0_DOMAIN as string,
},
(
accessToken: string,
refreshToken: string,
extraParams: auth0.ExtraVerificationParams,
profile: auth0.Profile,
done: (error: any, user?: any, info?: any) => void,
) => {
done(null, false, { message: 'Some error.' });
},
),
);