@feathersjs/authentication-client
Version:
The authentication plugin for feathers-client
84 lines (83 loc) • 3.27 kB
TypeScript
import { FeathersError } from '@feathersjs/errors';
import { Application, Params } from '@feathersjs/feathers';
import { AuthenticationRequest, AuthenticationResult } from '@feathersjs/authentication';
import { Storage } from './storage';
export type ClientConstructor = new (app: Application, options: AuthenticationClientOptions) => AuthenticationClient;
export interface AuthenticationClientOptions {
storage: Storage;
header: string;
scheme: string;
storageKey: string;
locationKey: string;
locationErrorKey: string;
jwtStrategy: string;
path: string;
Authentication: ClientConstructor;
}
export declare class AuthenticationClient {
app: Application;
authenticated: boolean;
options: AuthenticationClientOptions;
constructor(app: Application, options: AuthenticationClientOptions);
get service(): import("@feathersjs/feathers").FeathersService<Application<any, any>, import("@feathersjs/feathers").Service<any, Partial<any>, Params<import("@feathersjs/feathers").Query>, Partial<Partial<any>>>>;
get storage(): Storage;
handleSocket(socket: any): void;
/**
* Parse the access token or authentication error from the window location hash. Will remove it from the hash
* if found.
*
* @param location The window location
* @returns The access token if available, will throw an error if found, otherwise null
*/
getFromLocation(location: Location): Promise<any>;
/**
* Set the access token in storage.
*
* @param accessToken The access token to set
* @returns
*/
setAccessToken(accessToken: string): any;
/**
* Returns the access token from storage or the window location hash.
*
* @returns The access token from storage or location hash
*/
getAccessToken(): Promise<string | null>;
/**
* Remove the access token from storage
* @returns The removed access token
*/
removeAccessToken(): any;
/**
* Reset the internal authentication state. Usually not necessary to call directly.
*
* @returns null
*/
reset(): Promise<any>;
handleError(error: FeathersError, type: 'authenticate' | 'logout'): any;
/**
* Try to reauthenticate using the token from storage. Will do nothing if already authenticated unless
* `force` is true.
*
* @param force force reauthentication with the server
* @param strategy The name of the strategy to use. Defaults to `options.jwtStrategy`
* @param authParams Additional authentication parameters
* @returns The reauthentication result
*/
reAuthenticate(force?: boolean, strategy?: string, authParams?: Params): Promise<AuthenticationResult>;
/**
* Authenticate using a specific strategy and data.
*
* @param authentication The authentication data
* @param params Additional parameters
* @returns The authentication result
*/
authenticate(authentication?: AuthenticationRequest, params?: Params): Promise<AuthenticationResult>;
/**
* Log out the current user and remove their token. Will do nothing
* if not authenticated.
*
* @returns The log out result.
*/
logout(): Promise<AuthenticationResult | null>;
}