UNPKG

lbx-jwt

Version:

Provides JWT authentication for loopback applications. Includes storing roles inside tokens and handling refreshing. Built-in reuse detection.

41 lines (40 loc) 1.48 kB
/// <reference types="node" /> import { Secret, SignOptions, JwtHeader } from 'jsonwebtoken'; import { JwtPayload } from '../models/jwt.model'; /** * An encoded token. */ export interface EncodedJwt<RoleType extends string> { /** * The header of the jwt, contains mostly metadata. */ header: JwtHeader; /** * The payload of the jwt, everything that was put inside the token when generating it can be found here. */ payload: JwtPayload<RoleType>; /** * The signature of the jwt. */ signature: string; } /** * Encapsulates functionality of the jsonwebtoken package. */ export declare abstract class JwtUtilities { /** * Asynchronously sign the given payload into a JSON Web Token string payload. * @param payload - Any info that should be put inside the token. * @param secret - The secret used to encrypt the token. * @param options - Additional options like "expiresIn". * @returns A promise of the jwt. */ static signAsync(payload: string | Buffer | object, secret: Secret, options?: SignOptions): Promise<string>; /** * Asynchronously verify given token using a secret or a public key to get a decoded token. * @param token - The token to encode. * @param secret - The secret to encode the token with. * @returns The encoded token. */ static verifyAsync<RoleType extends string>(token: string, secret: Secret): Promise<EncodedJwt<RoleType>>; }