lbx-jwt
Version:
Provides JWT authentication for loopback applications. Includes storing roles inside tokens and handling refreshing. Built-in reuse detection.
34 lines (33 loc) • 1.71 kB
TypeScript
/// <reference types="express" />
import { AuthenticationMetadata, AuthenticationStrategy, TokenService } from '@loopback/authentication';
import { Request } from '@loopback/rest';
import { TwoFactorService } from './two-factor.service';
import { BaseUser, BaseUserProfile } from '../models';
import { BaseUserRepository } from '../repositories';
/**
* The jwt authentication strategy.
*/
export declare class JwtAuthenticationStrategy implements AuthenticationStrategy {
private readonly accessTokenService;
private readonly metadataArray;
private readonly baseUserRepository;
private readonly forceTwoFactor;
private readonly forceTwoFactorAllowedRoutes;
private readonly twoFactorService;
readonly name: string;
constructor(accessTokenService: TokenService, metadataArray: AuthenticationMetadata[], baseUserRepository: BaseUserRepository<string>, forceTwoFactor: boolean, forceTwoFactorAllowedRoutes: string[], twoFactorService: TwoFactorService<string>);
authenticate(request: Request): Promise<BaseUserProfile<string> | undefined>;
/**
* Checks if the request requires 2fa and validates accordingly.
* @param user - The currently logged in user.
* @param request - The request, is used to extract the two factor code from the custom header.
*/
protected validate2FA(user: BaseUser<string>, request: Request): Promise<void>;
/**
* Extracts the token from the given request.
* @param request - The request to get the token from.
* @returns The found token. An error otherwise.
* @throws An Http-Unauthorized-Error when no token could be found.
*/
protected extractTokenFromRequest(request: Request): string;
}