@intrasoft/auth-core
Version:
A robust and customizable authentication package for Node.js applications, providing JWT-based authentication and token management
75 lines (72 loc) • 1.88 kB
text/typescript
/**
* A JSON Web Token (JWT).
*/
interface IntrasoftJwtPayload {
/**
* The actual payload sign at authentication
*/
payload: unknown;
/**
* A boolean flag indicating a refresh
*/
_r?: boolean;
/**
* The time this token was issued in (milliseconds)
*/
iat: number;
/**
* The expiration time of this token in (milliseconds)
*/
exp: number;
}
/**
* A JSON Web Token (JWT).
*/
interface IntrasoftJwtTokens {
/**
* The access token for authentication.
*/
access: string;
/**
* The refresh token for rotating the access token.
*/
refresh?: string;
}
/**
* Configuration options for Intrasoft authentication.
*/
interface IntrasoftAuthConfig {
/**
* The secret key used for signing tokens.
*/
secretKey: string;
/**
* The lifetime of the access token in seconds.
*/
accessLifetime: number;
/**
* The optional lifetime of the refresh token in seconds.
*/
refreshLifetime?: number;
}
/**
* Create a JSON Web Token (JWT).
*
* @param {unknown} payload - The payload to include in the token.
* @returns {IntrasoftJwtTokens} The signed JWT.
*/
declare function createToken(payload: unknown): Promise<IntrasoftJwtTokens>;
/**
* Refresh a JSON Web Token (JWT).
*
* @param {string} refreshToken - The refresh token to verify.
* @returns {IntrasoftJwtTokens} The signed JWT.
*/
declare function refreshToken(refreshToken: string): Promise<IntrasoftJwtTokens>;
/**
* Decodes the access token sign the jwt creator function
* @param {string} token The encrypted access token to decode
* @returns {IntrasoftJwtPayload}
*/
declare function decodeJwt(token: string): Promise<IntrasoftJwtPayload>;
export { type IntrasoftAuthConfig, type IntrasoftJwtPayload, type IntrasoftJwtTokens, createToken, decodeJwt, refreshToken };