@antelopejs/auth-jwt
Version:
Authentication and authorization module that implements the Auth interface of antelopejs with JWT
44 lines (43 loc) • 3.01 kB
TypeScript
import { IncomingMessage, ServerResponse } from 'http';
export type AuthSource = (req: IncomingMessage, res: ServerResponse) => string | undefined;
export type AuthVerifier<T = unknown> = (data?: string, options?: VerifyOptions) => Promise<T> | T;
export type AuthValidator<T = unknown, R = unknown> = (data: T) => Promise<R> | R;
export interface CookieOptions {
maxAge?: number;
signed?: boolean;
expires?: Date;
httpOnly?: boolean;
path?: string;
domain?: string;
secure?: boolean;
}
export interface SignOptions {
expiresIn?: string | number;
notBefore?: string | number;
}
export interface VerifyOptions {
ignoreExpiration?: boolean;
ignoreNotBefore?: boolean;
maxAge?: string | number;
}
export declare const Verify: (data?: string | undefined, options?: VerifyOptions | undefined) => Promise<any>;
export declare const Sign: (data: any, options?: SignOptions | undefined) => Promise<string>;
export declare const AttachAuthDecorator: (target: any, key: PropertyKey | undefined, index: number | PropertyDescriptor | undefined, callbacks: {
source?: AuthSource;
authenticator?: AuthVerifier<any>;
authenticatorOptions?: VerifyOptions;
validator?: AuthValidator<any, any>;
}, validator?: AuthValidator<unknown, unknown> | undefined) => Promise<void>;
export declare function ValidateRaw<T = any>(token: string, options?: VerifyOptions): Promise<T>;
export declare function SignRaw(data: any, options?: SignOptions): Promise<string>;
export declare function defaultSource(req: IncomingMessage): string | undefined;
export declare const defaultAuthenticator: AuthVerifier<any>;
export declare function CheckAuthentication<T = unknown, R = unknown>(req: IncomingMessage, res: ServerResponse, source?: AuthSource | undefined, authenticator?: AuthVerifier<T> | undefined, authenticatorOptions?: VerifyOptions | undefined, validator?: AuthValidator<T, R> | undefined): Promise<any>;
export declare function SignServerResponse(res: ServerResponse, data: any, signOptions?: SignOptions, cookieOptions?: CookieOptions): Promise<ServerResponse<IncomingMessage>>;
export declare function CreateAuthDecorator<R = unknown, T = unknown>(callbacks: {
source?: AuthSource;
authenticator?: AuthVerifier<T>;
authenticatorOptions?: VerifyOptions;
validator?: AuthValidator<T, R>;
}): (validator?: AuthValidator<T, R> | undefined) => import("@ajs/core/1/decorators").ClassDecorator<import("@ajs/core/1/decorators").Class<any, any[]>> & import("@ajs/core/1/decorators").PropertyDecorator & import("@ajs/core/1/decorators").MethodDecorator & import("@ajs/core/1/decorators").ParameterDecorator;
export declare const Authentication: (validator?: AuthValidator<unknown, unknown> | undefined) => import("@ajs/core/1/decorators").ClassDecorator<import("@ajs/core/1/decorators").Class<any, any[]>> & import("@ajs/core/1/decorators").PropertyDecorator & import("@ajs/core/1/decorators").MethodDecorator & import("@ajs/core/1/decorators").ParameterDecorator;