UNPKG

@adonisjs/auth

Version:

Official authentication provider for Adonis framework

150 lines (149 loc) 4.37 kB
/// <reference types="@adonisjs/events/build/adonis-typings" /> import { EmitterContract } from '@ioc:Adonis/Core/Event'; import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'; import { OATGuardConfig, OATLoginOptions, OATGuardContract, UserProviderContract, ProviderTokenContract, TokenProviderContract } from '@ioc:Adonis/Addons/Auth'; import { BaseGuard } from '../Base'; /** * Exposes the API to generate and authenticate HTTP request using * opaque tokens */ export declare class OATGuard extends BaseGuard<any> implements OATGuardContract<any, any> { config: OATGuardConfig<any>; private emitter; private ctx; tokenProvider: TokenProviderContract; constructor(name: string, config: OATGuardConfig<any>, emitter: EmitterContract, provider: UserProviderContract<any>, ctx: HttpContextContract, tokenProvider: TokenProviderContract); /** * Reference to the parsed token */ private parsedToken?; /** * Length of the raw token. The hash length will vary */ private tokenLength; /** * Token type for the persistance store */ private tokenType; /** * Whether or not the authentication has been attempted * for the current request */ authenticationAttempted: boolean; /** * Find if the user has been logged out in the current request */ isLoggedOut: boolean; /** * A boolean to know if user is retrieved by authenticating * the current request or not */ isAuthenticated: boolean; /** * Logged in or authenticated user */ user?: any; /** * Token fetched as part of the authenticate or the login * call */ token?: ProviderTokenContract; /** * Accessor to know if user is logged in */ get isLoggedIn(): boolean; /** * Accessor to know if user is a guest. It is always opposite * of [[isLoggedIn]] */ get isGuest(): boolean; /** * Converts value to a sha256 hash */ private generateHash; /** * Converts expiry duration to an absolute date/time value */ private getExpiresAtDate; /** * Generates a new token + hash for the persistance */ private generateTokenForPersistance; /** * Returns data packet for the login event. Arguments are * * - The mapping identifier * - Logged in user * - HTTP context * - API token */ private getLoginEventData; /** * Returns data packet for the authenticate event. Arguments are * * - The mapping identifier * - Logged in user * - HTTP context * - A boolean to tell if logged in viaRemember or not */ private getAuthenticateEventData; /** * Parses the token received in the request. The method also performs * some initial level of sanity checks. */ private parsePublicToken; /** * Returns the bearer token */ private getBearerToken; /** * Returns the token by reading it from the token provider */ private getProviderToken; /** * Returns user from the user session id */ private getUserById; /** * Verify user credentials and perform login */ attempt(uid: string, password: string, options?: OATLoginOptions): Promise<any>; /** * Login user using their id */ loginViaId(id: string | number, options?: OATLoginOptions): Promise<any>; /** * Generate token for a user. It is merely an alias for `login` */ generate(user: any, options?: OATLoginOptions): Promise<any>; /** * Login a user */ login(user: any, options?: OATLoginOptions): Promise<any>; /** * Authenticates the current HTTP request by checking for the bearer token */ authenticate(): Promise<any>; /** * Same as [[authenticate]] but returns a boolean over raising exceptions */ check(): Promise<boolean>; /** * Alias for the logout method */ revoke(): Promise<void>; /** * Logout by removing the token from the storage */ logout(): Promise<void>; /** * Serialize toJSON for JSON.stringify */ toJSON(): { isLoggedIn: boolean; isGuest: boolean; authenticationAttempted: boolean; isAuthenticated: boolean; user: any; }; }