UNPKG

piral-oauth2

Version:

Plugin to integrate OAuth 2.0 authentication in Piral.

141 lines (140 loc) 3.91 kB
declare function defaultRequest(method: string, url: string, body: string, headers: Record<string, string>): Promise<{ status: number; body: string; }>; /** * Construct an object that can handle the multiple OAuth 2.0 flows. * * @param {Object} options */ export declare class ClientOAuth2 { options: any; private request; code: CodeFlow; token: TokenFlow; owner: OwnerFlow; credentials: CredentialsFlow; jwt: JwtBearerFlow; constructor(options: any, request?: typeof defaultRequest); /** * Create a new token from existing data. */ createToken(access: string, refresh: string, type: string, data?: any): ClientOAuth2Token; /** * Using the built-in request method, we'll automatically attempt to parse * the response. */ _request(options: { url: string; body: Record<string, string>; query: Record<string, string>; method: string; headers: Record<string, string>; }): Promise<any>; } /** * General purpose client token generator. * * @param {Object} client * @param {Object} data */ export declare class ClientOAuth2Token { client: ClientOAuth2; data: any; tokenType: string; accessToken: string; refreshToken: string; expires: Date; constructor(client: ClientOAuth2, data: any); /** * Expire the token after some time. */ expiresIn(duration: number | Date): Date; /** * Sign a standardised request object with user authentication information. */ sign(requestObject: any): any; /** * Refresh a user access token with the supplied token. */ refresh(opts?: any): Promise<ClientOAuth2Token>; /** * Check whether the token has expired. */ expired(): boolean; } /** * Support resource owner password credentials OAuth 2.0 grant. * * Reference: http://tools.ietf.org/html/rfc6749#section-4.3 */ declare class OwnerFlow { client: ClientOAuth2; constructor(client: ClientOAuth2); /** * Make a request on behalf of the user credentials to get an access token. */ getToken(username: string, password: string, opts?: any): Promise<ClientOAuth2Token>; } /** * Support implicit OAuth 2.0 grant. * * Reference: http://tools.ietf.org/html/rfc6749#section-4.2 */ declare class TokenFlow { client: ClientOAuth2; constructor(client: ClientOAuth2); /** * Get the uri to redirect the user to for implicit authentication. */ getUri(opts?: any): string; /** * Get the user access token from the uri. */ getToken(uri: string, opts?: any): Promise<ClientOAuth2Token>; } /** * Support client credentials OAuth 2.0 grant. * * Reference: http://tools.ietf.org/html/rfc6749#section-4.4 */ declare class CredentialsFlow { client: ClientOAuth2; constructor(client: ClientOAuth2); /** * Request an access token using the client credentials. */ getToken(opts?: any): Promise<ClientOAuth2Token>; } /** * Support authorization code OAuth 2.0 grant. * * Reference: http://tools.ietf.org/html/rfc6749#section-4.1 */ declare class CodeFlow { client: ClientOAuth2; constructor(client: ClientOAuth2); /** * Generate the uri for doing the first redirect. */ getUri(opts?: any): string; /** * Get the code token from the redirected uri and make another request for * the user access token. */ getToken(uri: string, opts?: any): Promise<ClientOAuth2Token>; } /** * Support JSON Web Token (JWT) Bearer Token OAuth 2.0 grant. * * Reference: https://tools.ietf.org/html/draft-ietf-oauth-jwt-bearer-12#section-2.1 */ declare class JwtBearerFlow { client: ClientOAuth2; constructor(client: ClientOAuth2); /** * Request an access token using a JWT token. */ getToken(token: string, opts?: any): Promise<ClientOAuth2Token>; } export {};