UNPKG

ally-42-oauth

Version:

AdonisJS Ally driver for 42 School's Intra OAuth2 authentication

75 lines (74 loc) 2.53 kB
import { Oauth2Driver } from '@adonisjs/ally'; import type { HttpContext } from '@adonisjs/core/http'; import type { AllyDriverContract, AllyUserContract, ApiRequestContract } from '@adonisjs/ally/types'; /** * Access token returned by the 42 OAuth driver. */ export type FortyTwoDriverAccessToken = { token: string; type: 'bearer'; expires_in?: number; scope?: string; created_at?: number; }; /** * Scopes accepted by the 42 OAuth driver implementation. */ export type FortyTwoDriverScopes = 'public' | string; /** * The configuration accepted by the 42 OAuth driver implementation. */ export type FortyTwoDriverConfig = { clientId: string; clientSecret: string; callbackUrl: string; authorizeUrl?: string; accessTokenUrl?: string; userInfoUrl?: string; }; /** * 42 School OAuth driver implementation for AdonisJS Ally. */ export declare class FortyTwoDriver extends Oauth2Driver<FortyTwoDriverAccessToken, FortyTwoDriverScopes> implements AllyDriverContract<FortyTwoDriverAccessToken, FortyTwoDriverScopes> { config: FortyTwoDriverConfig; /** * The URL for the redirect request. */ protected authorizeUrl: string; /** * The URL to exchange the authorization code for the access token. */ protected accessTokenUrl: string; /** * The URL to get the user details. */ protected userInfoUrl: string; protected codeParamName: string; protected errorParamName: string; protected stateCookieName: string; protected stateParamName: string; protected scopeParamName: string; protected scopesSeparator: string; constructor(ctx: HttpContext, config: FortyTwoDriverConfig); /** * Configure the authorization redirect request. */ protected configureRedirectRequest(request: any): void; /** * Check if the error received during redirect means "ACCESS DENIED". */ accessDenied(): boolean; /** * Get the user details by querying the 42 API. */ user(callback?: (request: ApiRequestContract) => void): Promise<AllyUserContract<FortyTwoDriverAccessToken>>; userFromToken(accessToken: string, callback?: (request: ApiRequestContract) => void): Promise<AllyUserContract<{ token: string; type: 'bearer'; }>>; } /** * The factory function to reference the driver implementation * inside the "config/ally.ts" file. */ export declare function FortyTwoDriverService(config: FortyTwoDriverConfig): (ctx: HttpContext) => FortyTwoDriver;