tl-shared-security
Version:
Enterprise-grade security module for frontend and backend applications with comprehensive protection against XSS, CSRF, SQL injection, and other security vulnerabilities
57 lines • 1.72 kB
TypeScript
export interface JwtPayload {
[key: string]: any;
iat?: number;
exp?: number;
sub?: string;
iss?: string;
}
export interface JwtOptions {
expiresIn?: number;
issuer?: string;
subject?: string;
algorithm?: string;
}
export declare class JwtService {
private readonly defaultOptions;
/**
* Signs a JWT token
* @param payload - Data to include in the token
* @param secret - Secret key to sign the token
* @param options - JWT options
* @returns Signed JWT token
*/
sign(payload: JwtPayload, secret: string, options?: JwtOptions): string;
/**
* Verifies a JWT token
* @param token - JWT token to verify
* @param secret - Secret key to verify the token
* @param options - JWT options
* @returns Decoded payload if token is valid
* @throws Error if token is invalid
*/
verify(token: string, secret: string, options?: JwtOptions): JwtPayload;
/**
* Decodes a JWT token without verification
* @param token - JWT token to decode
* @returns Decoded payload
* @throws Error if token format is invalid
*/
decode(token: string): {
header: any;
payload: JwtPayload;
};
/**
* Refreshes a JWT token
* @param token - JWT token to refresh
* @param secret - Secret key to sign the new token
* @param options - JWT options
* @returns New JWT token
*/
refresh(token: string, secret: string, options?: JwtOptions): string;
private base64UrlEncode;
private base64UrlDecode;
private createSignature;
private verifySignature;
}
export declare const jwtService: JwtService;
//# sourceMappingURL=jwt.service.d.ts.map