UNPKG

@lunoxjs/auth

Version:

Lunox Authentication

136 lines (128 loc) 4.74 kB
import { Trait, ServiceProvider, SessionManager } from '@lunoxjs/core'; import { A as AuthManager, S as StatefulGuard, a as Authenticatable$1, U as UserProvider, C as Credentials } from './AuthManager-3309f32c.js'; export { _ as AuthManager } from './AuthManager-3309f32c.js'; import * as _lunoxjs_core_dist_Application_3c340b18 from '@lunoxjs/core/dist/Application-3c340b18'; import { Request } from '@lunoxjs/core/contracts'; declare const Authenticatable: Trait<any>; declare class AuthenticationException extends Error { protected _guards: any[]; protected _redirectTo?: string; constructor(message?: string, guards?: never[], redirectTo?: string); guards(): any[]; redirectTo(): string | undefined; } declare class AuthServiceProvider extends ServiceProvider { register(): Promise<void>; boot(): Promise<void>; } declare module "@lunoxjs/core/contracts" { interface Request { auth(): AuthManager & StatefulGuard; } } declare abstract class GuardHelper { protected _user?: Authenticatable$1; protected provider: UserProvider; user<T = Authenticatable$1>(): Promise<T | undefined>; protected authenticate(): Authenticatable$1; check(): Promise<boolean>; guest(): Promise<boolean>; id(): Promise<string | undefined>; getProvider(): UserProvider; setProvider(provider: UserProvider): void; } declare class Recaller { protected recaller: string; constructor(recaller: string); /** * Determine if the recaller is valid. */ valid(): boolean; /** * Determine if the recaller is an valid string. */ protected properString(): boolean; /** * Determine if the recaller has all segments. */ protected hasAllSegments(): boolean; /** * Get the user ID from the recaller */ id(): string; /** * Get the "remember token" from the recaller */ token(): string; } declare class SessionGuard extends GuardHelper implements StatefulGuard { name: string; session: SessionManager; request: Request; lastAttempted: Authenticatable$1 | undefined; /** * The number of minutes that the "remember me" cookie should be valid for. */ protected rememberDuration: number; protected loggedOut: boolean; /** * Indicates if a token user retrieval has been attempted. */ protected recallAttempted: boolean; /** * Indicates if the user was authenticated via a recaller cookie. */ protected viaRemember: boolean; constructor(name: string, provider: UserProvider, request: Request); validate(credentials: Credentials): Promise<boolean>; once(credentials: Credentials): Promise<boolean>; attempt(credentials?: Credentials, remember?: boolean): Promise<boolean>; protected hasValidCredentials(user: Authenticatable$1 | undefined, credentials: Credentials): boolean; login(user: Authenticatable$1, remember?: boolean): Promise<void>; /** * Queue the recaller cookie into the cookie jar. */ protected queueRecallerCookie(user: Authenticatable$1): void; /** * Create a "remember me" cookie for a given ID. */ protected createRecaller(value: string): _lunoxjs_core_dist_Application_3c340b18.b; /** * Get the number of minutes the remember me cookie should be valid for. */ protected getRememberDuration(): number; /** * Set the number of minutes the remember me cookie should be valid for. */ setRememberDuration(minutes: number): this; /** * Create a new "remember me" token for the user if one doesn't already exist. */ protected ensureRememberTokenIsSet(user: Authenticatable$1): Promise<void>; /** * Refresh the "remember me" token for the user. */ protected cycleRememberToken(user: Authenticatable$1): Promise<void>; logout(): Promise<void>; setUser(user: Authenticatable$1): this; getName(): string; protected updateSession(id: string): Promise<void>; user<T = Authenticatable$1>(): Promise<T | undefined>; /** * Pull a user from the repository by its "remember me" cookie token. */ protected userFromRecaller(recaller: Recaller): Promise<Authenticatable$1 | undefined>; /** * Get the decrypted recaller cookie for the request. */ protected recaller(): Recaller | undefined; /** * Get the name of the cookie used to store the "recaller". */ protected getRecallerName(): string; /** * Remove the user data from the session and cookies. */ protected clearUserDataFromStorage(): void; } export { AuthServiceProvider, Authenticatable, AuthenticationException, GuardHelper, Recaller, SessionGuard };