middy-middleware-jwt-auth
Version:
A middy JSON web token authorization middleware inspired by express-jwt.
62 lines (61 loc) • 3.92 kB
TypeScript
/** An event that can be checked for authorization with middly-middleware-jwt-auth */
export type IAuthorizedEvent<TokenPayload = any> = ILowerCaseAuthorizedEvent<TokenPayload> | IUpperCaseAuthorizedEvent<TokenPayload>;
export interface IAuthorizedEventBase<TokenPayload = any> {
/** Authorization information added by this middleware from a JWT. Has to be undefined before hitting the middleware. */
auth?: {
payload: TokenPayload;
token: string;
};
/** An object containing event headers */
headers: any;
/** The http request method of this event (for REST APIs) */
httpMethod?: any;
/** The metadata about this event (for HTTP APIs) */
requestContext?: any;
}
export interface IAuthorizedRestApiGatewayEvent<TokenPayload = any> extends IAuthorizedEventBase<TokenPayload> {
httpMethod: string;
}
export interface IAuthorizedHttpApiGatewayEvent<TokenPayload = any> extends IAuthorizedEventBase<TokenPayload> {
requestContext: {
/** The http request metadata about this event */
http: object;
};
}
export interface IAuthorizedWebsocketApiGatewayEvent<TokenPayload = any> extends IAuthorizedEventBase<TokenPayload> {
requestContext: {
/** The connectionId of the websocket connection */
connectionId: string;
/** The eventType of the websocket message */
eventType: string;
};
}
export type IAuthorizedApiGatewayEvent<TokenPayload = any> = IAuthorizedRestApiGatewayEvent<TokenPayload> | IAuthorizedHttpApiGatewayEvent<TokenPayload> | IAuthorizedWebsocketApiGatewayEvent<TokenPayload>;
/** An event with a lower case authorization header */
export type ILowerCaseAuthorizedEvent<TokenPayload = any> = {
headers: {
/**
* The authorization token to check. Can be a string or an array with exactly one string.
* @example "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
*/
authorization: string | string[];
};
} & IAuthorizedApiGatewayEvent<TokenPayload>;
/** An event with an upper case authorization header */
export type IUpperCaseAuthorizedEvent<TokenPayload = any> = {
headers: {
/**
* The authorization token to check. Can be a string or an array with exactly one string.
* @example "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
*/
Authorization: string | string[];
};
} & IAuthorizedApiGatewayEvent<TokenPayload>;
export declare function isAuthorizedEvent<P>(event: any, isTokenPayload?: (payload: any) => payload is P): event is IAuthorizedEvent<P>;
export declare function isAuthorizedEventBase<P>(event: any, isTokenPayload?: (payload: any) => payload is P): event is IAuthorizedEventBase;
export declare function isAuthorizedRestApiGatewayEvent<P>(event: any, isTokenPayload?: (payload: any) => payload is P): event is IAuthorizedRestApiGatewayEvent<P>;
export declare function isAuthorizedHttpApiGatewayEvent<P>(event: any, isTokenPayload?: (payload: any) => payload is P): event is IAuthorizedHttpApiGatewayEvent<P>;
export declare function isAuthorizedWebsocketApiGatewayEvent<P>(event: any, isTokenPayload?: (payload: any) => payload is P): event is IAuthorizedHttpApiGatewayEvent<P>;
export declare function isAuthorizedApiGatewayEvent<P>(event: any, isTokenPayload?: (payload: any) => payload is P): event is IAuthorizedApiGatewayEvent<P>;
export declare function isUpperCaseAuthorizedEvent<P>(event: any, isTokenPayload?: (payload: any) => payload is P): event is IUpperCaseAuthorizedEvent<P>;
export declare function isLowerCaseAuthorizedEvent<P>(event: any, isTokenPayload?: (payload: any) => payload is P): event is ILowerCaseAuthorizedEvent<P>;