UNPKG

@carllewi2/sapcdc-ally-driver

Version:
147 lines (146 loc) 5.61 kB
/// <reference types="@adonisjs/ally" /> /// <reference types="@adonisjs/http-server/build/adonis-typings" /> import type { AllyUserContract, ApiRequestContract } from '@ioc:Adonis/Addons/Ally'; import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'; import { Oauth2Driver, ApiRequest, RedirectRequest } from '@adonisjs/ally/build/standalone'; /** * Define the access token object properties in this type. It * must have "token" and "type" and you are free to add * more properties. * * ------------------------------------------------ * Change "YourDriver" to something more relevant * ------------------------------------------------ */ export declare type SapcdcDriverAccessToken = { token: string; type: 'bearer'; }; /** * Define a union of scopes your driver accepts. Here's an example of same * https://github.com/adonisjs/ally/blob/develop/adonis-typings/ally.ts#L236-L268 * * ------------------------------------------------ * Change "YourDriver" to something more relevant * ------------------------------------------------ */ export declare type SapcdcDriverScopes = string; /** * Define the configuration options accepted by your driver. It must have the following * properties and you are free add more. * * ------------------------------------------------ * Change "YourDriver" to something more relevant * ------------------------------------------------ */ export declare type SapcdcDriverConfig = { driver: 'sapcdc'; clientId: string; clientSecret: string; callbackUrl: string; authorizeUrl: string; accessTokenUrl: string; userInfoUrl: string; scopes: string; responseType: string; }; /** * Driver implementation. It is mostly configuration driven except the user calls * * ------------------------------------------------ * Change "YourDriver" to something more relevant * ------------------------------------------------ */ export declare class SapcdcDriver extends Oauth2Driver<SapcdcDriverAccessToken, SapcdcDriverScopes> { config: SapcdcDriverConfig; /** * The URL for the redirect request. The user will be redirected on this page * to authorize the request. */ protected authorizeUrl: string; /** * The URL to hit to exchange the authorization code for the access token */ protected accessTokenUrl: string; /** * The URL to hit to get the user details */ protected userInfoUrl: string; /** * The param name for the authorization code. Read the documentation of your oauth * provider and update the param name to match the query string field name in * which the oauth provider sends the authorization_code post redirect. */ protected codeParamName: string; /** * The param name for the error. Read the documentation of your oauth provider and update * the param name to match the query string field name in which the oauth provider sends * the error post redirect */ protected errorParamName: string; /** * Cookie name for storing the CSRF token. Make sure it is always unique. So a better * approach is to prefix the oauth provider name to `oauth_state` value. */ protected stateCookieName: string; /** * Parameter name to be used for sending and receiving the state from. * Read the documentation of your oauth provider and update the param * name to match the query string used by the provider for exchanging * the state. */ protected stateParamName: string; /** * Parameter name for sending the scopes to the oauth provider. */ protected scopeParamName: string; /** * The separator indentifier for defining multiple scopes */ protected scopesSeparator: string; constructor(ctx: HttpContextContract, config: SapcdcDriverConfig); /** * Optionally configure the authorization redirect request. The actual request * is made by the base implementation of "Oauth2" driver and this is a * hook to pre-configure the request. */ protected configureRedirectRequest(request: RedirectRequest<SapcdcDriverScopes>): void; /** * Returns the HTTP request with the authorization header set */ protected getAuthenticatedRequest(url: string, token: string): ApiRequest; /** * Fetches the user info from the Google API */ protected getUserInfo(token: string, callback?: (request: ApiRequestContract) => void): Promise<{ id: any; nickName: any; name: any; email: any; avatarUrl: any; emailVerificationState: "verified" | "unverified"; original: any; }>; /** * Optionally configure the access token request. The actual request is made by * the base implementation of "Oauth2" driver and this is a hook to pre-configure * the request */ /** * Update the implementation to tell if the error received during redirect * means "ACCESS DENIED". */ accessDenied(): boolean; /** * Get the user details by query the provider API. This method must return * the access token and the user details both. Checkout the google * implementation for same. * * https://github.com/adonisjs/ally/blob/develop/src/Drivers/Google/index.ts#L191-L199 */ user(callback?: (request: ApiRequest) => void): Promise<AllyUserContract<SapcdcDriverAccessToken>>; userFromToken(accessToken: string, callback?: (request: ApiRequest) => void): Promise<AllyUserContract<{ token: string; type: 'bearer'; }>>; }