@solvro/auth
Version:
AdonisJS Ally provider for Solvro Auth
144 lines (143 loc) • 5.54 kB
TypeScript
/**
|--------------------------------------------------------------------------
* Search keyword "SolvroAuthDriver" and replace it with a meaningful name
|--------------------------------------------------------------------------
*/
import { Oauth2Driver, type RedirectRequest } from "@adonisjs/ally";
import type { AllyDriverContract, AllyUserContract, ApiRequestContract } from "@adonisjs/ally/types";
import type { HttpContext } from "@adonisjs/core/http";
/**
*
* Access token returned by your driver implementation. An access
* token must have "token" and "type" properties and you may
* define additional properties (if needed)
*/
export type SolvroAuthDriverAccessToken = {
token: string;
type: "bearer";
};
/**
* Scopes accepted by the driver implementation.
*/
export type SolvroAuthDriverScopes = "openid profile";
/**
* The configuration accepted by the driver implementation.
*/
export type SolvroAuthDriverConfig = {
clientId: string;
solvroAuthUrl?: string;
realm?: string;
clientSecret: string;
callbackUrl: string;
authorizeUrl?: string;
accessTokenUrl?: string;
userInfoUrl?: string;
};
/**
* Driver implementation. It is mostly configuration driven except the API call
* to get user info.
*/
export declare class SolvroAuthDriver extends Oauth2Driver<SolvroAuthDriverAccessToken, SolvroAuthDriverScopes> implements AllyDriverContract<SolvroAuthDriverAccessToken, SolvroAuthDriverScopes> {
config: SolvroAuthDriverConfig;
/**
* The URL for the redirect request. The user will be redirected on this page
* to authorize the request.
*
* Do not define query strings in this URL.
*/
protected authorizeUrl: string;
/**
* The URL to hit to exchange the authorization code for the access token
*
* Do not define query strings in this URL.
*/
protected accessTokenUrl: string;
/**
* The URL to hit to get the user details
*
* Do not define query strings in this URL.
*/
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. For example:
* For example: "facebook_oauth_state"
*/
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: HttpContext, config: SolvroAuthDriverConfig);
protected configureRedirectRequest(request: RedirectRequest<SolvroAuthDriverScopes>): void;
/**
* 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.
*/
/**
* 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: ApiRequestContract) => void): Promise<AllyUserContract<SolvroAuthDriverAccessToken>>;
userFromToken(accessToken: string, callback?: (request: ApiRequestContract) => void): Promise<AllyUserContract<{
token: string;
type: "bearer";
}>>;
/**
* Returns the HTTP request with the authorization header set
*/
protected getAuthenticatedRequest(url: string, token: string): import("@adonisjs/ally").ApiRequest;
/**
* Fetches the user info from the SolvroAuth API
*/
protected getUserInfo(token: string, callback?: (request: ApiRequestContract) => void): Promise<Omit<AllyUserContract<{
token: string;
type: "bearer";
}>, "token">>;
/**
* Build solvroauth URL
*/
protected buildSolvroAuthUrl(action: string): string;
}
/**
* The factory function to reference the driver implementation
* inside the "config/ally.ts" file.
*/
export declare function SolvroAuthDriverService(config: SolvroAuthDriverConfig): (ctx: HttpContext) => SolvroAuthDriver;