diff --git a/types/passport-auth0/index.d.ts b/types/passport-auth0/index.d.ts index 600ef57d71..bf4f70ebb9 100644 --- a/types/passport-auth0/index.d.ts +++ b/types/passport-auth0/index.d.ts @@ -3,73 +3,85 @@ // Definitions by: John Umeh // Vishnu Sankar // Duncan Hall +// Karl Horky // 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; diff --git a/types/passport-auth0/passport-auth0-tests.ts b/types/passport-auth0/passport-auth0-tests.ts index d6cf42d302..ee3d3a03f9 100644 --- a/types/passport-auth0/passport-auth0-tests.ts +++ b/types/passport-auth0/passport-auth0-tests.ts @@ -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.' }); + }, + ), );