balena-auth
Version:
Balena session authentication utilities
83 lines (82 loc) • 1.86 kB
TypeScript
import type { Token } from './token';
import { TokenType } from './token';
export interface JWTData {
iat?: number;
exp?: number;
twoFactorRequired?: boolean;
}
export declare class JWT implements Token {
static parse(key: string): JWTData;
static isValid(key: string): boolean;
/**
* @member type
* @summary Get the type of token
* @public
*
* @returns {TokenType} the type of token
*
* @example
* console.log(token.type)
*/
readonly type = TokenType.JWT;
/**
* @member key
* @summary Get the original string key
* @public
*
* @returns {string} string
*
* @example
* console.log(token.key())
*/
readonly key: string;
constructor(key: string);
/**
* @member isValid
* @summary Check if a token is valid
* @function
* @public
*
* @returns {boolean} is valid
*
* @example
* console.log(token.isValid());
*/
isValid: () => boolean;
/**
* @member getAge
* @summary Get the token age
* @function
* @public
*
* @returns {number | undefined}
*
* @example
* console.log(token.getAge());
*/
getAge: () => number | undefined;
/**
* @member isExpired
* @summary Check whether the token has expired
* @function
* @public
*
* @returns {boolean}
*
* @example
* console.log(token.isExpired());
*/
isExpired: () => boolean;
/**
* @member get2FAStatus
* @summary Gets whether passing a 2FA challenge is pending, passed or not required.
* @function
* @public
*
* @returns {'not_required'|'pending'|'passed'}
*
* @example
* console.log(token.get2FAStatus())
*/
get2FAStatus: () => "pending" | "not_required" | "passed";
}