UNPKG

passport-descope

Version:

Passport strategy for Descope authentication service

43 lines (40 loc) 1.69 kB
import { Request } from 'express'; import { StrategyCreatedStatic } from 'passport'; import DescopeClient from '@descope/node-sdk'; type VerifyCallback = (payload: any, verifyCallback: (err?: Error | null, user?: Object, info?: any) => void, req: Request) => void; interface Options { /** Descope project id to use */ projectId: string; /** Descope optional management key to retrieve extra user details */ managementKey?: string; /** The callback to load the user details if stored outside of Descope */ verify: VerifyCallback; /** The realm for the challenge */ realm?: string; /** The scopes for the challenge */ scope?: [string] | string; } type DescopeSdk = ReturnType<typeof DescopeClient>; /** * DescopeStrategy for PassportJS verifies that the given JWT token in either Authorization Bearer or DS cookie is valid. * It requires the Descope project ID and a verify function is there to allow the app to manipulate user details. */ declare class DescopeStrategy { private _options; name: string; _descopeClient: DescopeSdk; _realm: string; _scope: [string]; constructor(_options: Options); authenticate(this: StrategyCreatedStatic & DescopeStrategy, req: Request, options?: any): Promise<void>; /** * Generate a challenge response in case of failure * @param this the Descope strategy * @param code error code * @param desc error description * @param uri relevant uri for the error * @returns the challenge string */ _challenge(this: StrategyCreatedStatic & DescopeStrategy, code?: number, desc?: string, uri?: string): string; } export { DescopeStrategy as default };