1 | import {
|
2 | APIGatewayAuthorizerResultContext,
|
3 | APIGatewayEventDefaultAuthorizerContext,
|
4 | APIGatewayEventRequestContextWithAuthorizer,
|
5 | } from "../common/api-gateway";
|
6 | import { Callback, Handler } from "../handler";
|
7 |
|
8 | export type APIGatewayAuthorizerHandler = Handler<APIGatewayAuthorizerEvent, APIGatewayAuthorizerResult>;
|
9 | export type APIGatewayAuthorizerWithContextHandler<TAuthorizerContext extends APIGatewayAuthorizerResultContext> =
|
10 | Handler<APIGatewayAuthorizerEvent, APIGatewayAuthorizerWithContextResult<TAuthorizerContext>>;
|
11 |
|
12 | export type APIGatewayAuthorizerCallback = Callback<APIGatewayAuthorizerResult>;
|
13 | export type APIGatewayAuthorizerWithContextCallback<TAuthorizerContext extends APIGatewayAuthorizerResultContext> =
|
14 | Callback<APIGatewayAuthorizerWithContextResult<TAuthorizerContext>>;
|
15 |
|
16 | export type APIGatewayTokenAuthorizerHandler =
|
17 | Handler<APIGatewayTokenAuthorizerEvent, APIGatewayAuthorizerResult>;
|
18 | export type APIGatewayTokenAuthorizerWithContextHandler<TAuthorizerContext extends APIGatewayAuthorizerResultContext> =
|
19 | Handler<APIGatewayTokenAuthorizerEvent, APIGatewayAuthorizerWithContextResult<TAuthorizerContext>>;
|
20 |
|
21 | export type APIGatewayRequestAuthorizerHandler =
|
22 | Handler<APIGatewayRequestAuthorizerEvent, APIGatewayAuthorizerResult>;
|
23 | export type APIGatewayRequestAuthorizerWithContextHandler<TAuthorizerContext extends APIGatewayAuthorizerResultContext> =
|
24 | Handler<APIGatewayRequestAuthorizerEvent, APIGatewayAuthorizerWithContextResult<TAuthorizerContext>>;
|
25 |
|
26 | export type APIGatewayAuthorizerEvent = APIGatewayTokenAuthorizerEvent | APIGatewayRequestAuthorizerEvent;
|
27 |
|
28 | export interface APIGatewayTokenAuthorizerEvent {
|
29 | type: "TOKEN";
|
30 | methodArn: string;
|
31 | authorizationToken: string;
|
32 | }
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | export interface APIGatewayRequestAuthorizerEvent {
|
40 | type: "REQUEST";
|
41 | methodArn: string;
|
42 | resource: string;
|
43 | path: string;
|
44 | httpMethod: string;
|
45 | headers: { [name: string]: string } | null;
|
46 | multiValueHeaders: { [name: string]: string[] } | null;
|
47 | pathParameters: { [name: string]: string } | null;
|
48 | queryStringParameters: { [name: string]: string } | null;
|
49 | multiValueQueryStringParameters: { [name: string]: string[] } | null;
|
50 | stageVariables: { [name: string]: string } | null;
|
51 | requestContext: APIGatewayEventRequestContextWithAuthorizer<undefined>;
|
52 | }
|
53 |
|
54 | export interface APIGatewayAuthorizerResult {
|
55 | principalId: string;
|
56 | policyDocument: PolicyDocument;
|
57 | context?: APIGatewayAuthorizerResultContext | null;
|
58 | usageIdentifierKey?: string | null;
|
59 | }
|
60 |
|
61 |
|
62 | export interface APIGatewayAuthorizerWithContextResult<TAuthorizerContext extends APIGatewayAuthorizerResultContext> {
|
63 | principalId: string;
|
64 | policyDocument: PolicyDocument;
|
65 | context: TAuthorizerContext;
|
66 | usageIdentifierKey?: string | null;
|
67 | }
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | export type CustomAuthorizerHandler = Handler<CustomAuthorizerEvent, APIGatewayAuthorizerResult>;
|
73 |
|
74 |
|
75 | export type CustomAuthorizerCallback = APIGatewayAuthorizerCallback;
|
76 |
|
77 |
|
78 | export interface CustomAuthorizerEvent {
|
79 | type: string;
|
80 | methodArn: string;
|
81 | authorizationToken?: string;
|
82 | resource?: string;
|
83 | path?: string;
|
84 | httpMethod?: string;
|
85 | headers?: { [name: string]: string };
|
86 | multiValueHeaders?: { [name: string]: string[] };
|
87 | pathParameters?: { [name: string]: string } | null;
|
88 | queryStringParameters?: { [name: string]: string } | null;
|
89 | multiValueQueryStringParameters?: { [name: string]: string[] } | null;
|
90 | stageVariables?: { [name: string]: string };
|
91 | requestContext?: APIGatewayEventRequestContextWithAuthorizer<APIGatewayEventDefaultAuthorizerContext>;
|
92 | domainName?: string;
|
93 | apiId?: string;
|
94 | }
|
95 |
|
96 | export type CustomAuthorizerResult = APIGatewayAuthorizerResult;
|
97 | export type AuthResponse = APIGatewayAuthorizerResult;
|
98 | export type AuthResponseContext = APIGatewayAuthorizerResultContext;
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | export interface PolicyDocument {
|
106 | Version: string;
|
107 | Id?: string;
|
108 | Statement: Statement[];
|
109 | }
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 | export interface ConditionBlock {
|
117 | [condition: string]: Condition | Condition[];
|
118 | }
|
119 |
|
120 | export interface Condition {
|
121 | [key: string]: string | string[];
|
122 | }
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 | export type Statement = BaseStatement & StatementAction & (StatementResource | StatementPrincipal);
|
130 |
|
131 | export interface BaseStatement {
|
132 | Effect: string;
|
133 | Sid?: string;
|
134 | Condition?: ConditionBlock;
|
135 | }
|
136 |
|
137 | export type PrincipalValue = { [key: string]: string | string[] } | string | string[];
|
138 | export interface MaybeStatementPrincipal {
|
139 | Principal?: PrincipalValue;
|
140 | NotPrincipal?: PrincipalValue;
|
141 | }
|
142 | export interface MaybeStatementResource {
|
143 | Resource?: string | string[];
|
144 | NotResource?: string | string[];
|
145 | }
|
146 | export type StatementAction = { Action: string | string[] } | { NotAction: string | string[] };
|
147 | export type StatementResource = MaybeStatementPrincipal &
|
148 | ({ Resource: string | string[] } | { NotResource: string | string[] });
|
149 | export type StatementPrincipal = MaybeStatementResource &
|
150 | ({ Principal: PrincipalValue } | { NotPrincipal: PrincipalValue });
|