@interopio/gateway
Version:
[](https://www.npmjs.com/package/@interopio/gateway)
119 lines (103 loc) • 2.9 kB
TypeScript
type ValidatorFn = (value: unknown, claims: JwtPayload, header: JwsHeaderParameters) => boolean
type Validator
= ValidatorFn
| string
| false
| undefined;
interface Validators {
alg: Validator;
typ: Validator;
iss: Validator;
aud: Validator;
exp: Validator;
iat: Validator;
sub: Validator;
jti: Validator;
[key: string]: Validator;
}
export type JwtVerifierOptions = {
issuerBaseUri?: string,
audience?: string | string[],
issuer?: string,
jwksUri?: string,
timeout?: number,
cacheMaxAge?: number,
validators?: Partial<Validators>,
clockTolerance?: number,
maxTokenAge?: number,
strict?: boolean,
secret?: string,
tokenSigningAlg?: string,
fetchFn?: typeof fetch,
}
export interface JoseHeaderParameters {
/** "kid" (Key ID) Header Parameter. */
kid?: string;
x5t?: string;
x5c?: string[];
/** "typ" (Type) Header Parameter. */
typ?: string;
/** "cty" (Content Type) Header Parameter. */
cty?: string;
}
/**
* Recognized JWS Header Parameters, any other JWS header member may also be present.
*/
export interface JwsHeaderParameters extends JoseHeaderParameters {
/**
* JWS "alg" (Algorithm) Header Parameter.
*/
alg?: string;
/**
* Any other JWS header member.
*/
[key: string]: unknown;
}
export interface JwtPayload {
/**
* JWT Issuer, the principal that issued the JWT
* This claim is optional, but if present, it must be a string.
*/
iss?: string; // Issuer
/**
* JWT Subject, the principal that is the subject of the JWT
* This claim is optional, but if present, it must be a string.
*/
sub?: string; // Subject
/**
* JWT Audience, the recipients that the JWT is intended for
* This claim can be a single string or an array of strings.
*/
aud?: string | string[]; // Audience
/**
* JWT Expiration Time, the time at which the JWT expires
* This claim is optional, but if present, it must be a number representing seconds since the epoch.
*/
exp?: number; // Expiration Time
/**
* JWT Issued At, the time at which the JWT was issued
*/
iat?: number; // Issued At
/**
* JWT Not Before, the time before which the JWT must not be accepted for processing
*/
nbf?: number; // Not Before
/**
* JWT ID, a unique identifier for the token
*/
jti?: string;
/**
* Any other custom claims set member.
*/
[key: string]: unknown;
}
type VerifyJwtResult = Readonly<{
header: JwsHeaderParameters,
payload: JwtPayload,
token: string,
}>
type VerifyJwt = (token: string) => Promise<VerifyJwtResult>;
declare const jwtVerifier: (options: JwtVerifierOptions) => VerifyJwt;
declare class JwtVerifyError extends Error {
constructor(message?: string);
}