mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
@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:
parent
42bb035f82
commit
e73517f0d5
132
types/passport-auth0/index.d.ts
vendored
132
types/passport-auth0/index.d.ts
vendored
@ -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;
|
||||
|
||||
@ -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.' });
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user