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 | export interface APIGatewayRequestAuthorizerEventHeaders {
|
35 | [name: string]: string | undefined;
|
36 | }
|
37 |
|
38 | export interface APIGatewayRequestAuthorizerEventMultiValueHeaders {
|
39 | [name: string]: string[] | undefined;
|
40 | }
|
41 |
|
42 | export interface APIGatewayRequestAuthorizerEventPathParameters {
|
43 | [name: string]: string | undefined;
|
44 | }
|
45 |
|
46 | export interface APIGatewayRequestAuthorizerEventQueryStringParameters {
|
47 | [name: string]: string | undefined;
|
48 | }
|
49 |
|
50 | export interface APIGatewayRequestAuthorizerEventMultiValueQueryStringParameters {
|
51 | [name: string]: string[] | undefined;
|
52 | }
|
53 |
|
54 | export interface APIGatewayRequestAuthorizerEventStageVariables {
|
55 | [name: string]: string | undefined;
|
56 | }
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 | export interface APIGatewayRequestAuthorizerEvent {
|
64 | type: "REQUEST";
|
65 | methodArn: string;
|
66 | resource: string;
|
67 | path: string;
|
68 | httpMethod: string;
|
69 | headers: APIGatewayRequestAuthorizerEventHeaders | null;
|
70 | multiValueHeaders: APIGatewayRequestAuthorizerEventMultiValueHeaders | null;
|
71 | pathParameters: APIGatewayRequestAuthorizerEventPathParameters | null;
|
72 | queryStringParameters: APIGatewayRequestAuthorizerEventQueryStringParameters | null;
|
73 | multiValueQueryStringParameters: APIGatewayRequestAuthorizerEventMultiValueQueryStringParameters | null;
|
74 | stageVariables: APIGatewayRequestAuthorizerEventStageVariables | null;
|
75 | requestContext: APIGatewayEventRequestContextWithAuthorizer<undefined>;
|
76 | }
|
77 |
|
78 | export interface APIGatewayAuthorizerResult {
|
79 | principalId: string;
|
80 | policyDocument: PolicyDocument;
|
81 | context?: APIGatewayAuthorizerResultContext | null | undefined;
|
82 | usageIdentifierKey?: string | null | undefined;
|
83 | }
|
84 |
|
85 |
|
86 | export interface APIGatewayAuthorizerWithContextResult<TAuthorizerContext extends APIGatewayAuthorizerResultContext> {
|
87 | principalId: string;
|
88 | policyDocument: PolicyDocument;
|
89 | context: TAuthorizerContext;
|
90 | usageIdentifierKey?: string | null | undefined;
|
91 | }
|
92 |
|
93 |
|
94 |
|
95 |
|
96 | export type CustomAuthorizerHandler = Handler<CustomAuthorizerEvent, APIGatewayAuthorizerResult>;
|
97 |
|
98 |
|
99 | export type CustomAuthorizerCallback = APIGatewayAuthorizerCallback;
|
100 |
|
101 |
|
102 | export interface CustomAuthorizerEvent {
|
103 | type: string;
|
104 | methodArn: string;
|
105 | authorizationToken?: string | undefined;
|
106 | resource?: string | undefined;
|
107 | path?: string | undefined;
|
108 | httpMethod?: string | undefined;
|
109 | headers?: { [name: string]: string } | undefined;
|
110 | multiValueHeaders?: { [name: string]: string[] } | undefined;
|
111 | pathParameters?: { [name: string]: string } | null | undefined;
|
112 | queryStringParameters?: { [name: string]: string } | null | undefined;
|
113 | multiValueQueryStringParameters?: { [name: string]: string[] } | null | undefined;
|
114 | stageVariables?: { [name: string]: string } | undefined;
|
115 | requestContext?: APIGatewayEventRequestContextWithAuthorizer<APIGatewayEventDefaultAuthorizerContext> | undefined;
|
116 | domainName?: string | undefined;
|
117 | apiId?: string | undefined;
|
118 | }
|
119 |
|
120 | export type CustomAuthorizerResult = APIGatewayAuthorizerResult;
|
121 | export type AuthResponse = APIGatewayAuthorizerResult;
|
122 | export type AuthResponseContext = APIGatewayAuthorizerResultContext;
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 | export interface PolicyDocument {
|
130 | Version: string;
|
131 | Id?: string | undefined;
|
132 | Statement: Statement[];
|
133 | }
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 | export interface ConditionBlock {
|
141 | [condition: string]: Condition | Condition[];
|
142 | }
|
143 |
|
144 | export interface Condition {
|
145 | [key: string]: string | string[];
|
146 | }
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 | export type Statement = BaseStatement & StatementAction & (StatementResource | StatementPrincipal);
|
154 |
|
155 | export interface BaseStatement {
|
156 | Effect: string;
|
157 | Sid?: string | undefined;
|
158 | Condition?: ConditionBlock | undefined;
|
159 | }
|
160 |
|
161 | export type PrincipalValue = { [key: string]: string | string[] } | string | string[];
|
162 | export interface MaybeStatementPrincipal {
|
163 | Principal?: PrincipalValue | undefined;
|
164 | NotPrincipal?: PrincipalValue | undefined;
|
165 | }
|
166 | export interface MaybeStatementResource {
|
167 | Resource?: string | string[] | undefined;
|
168 | NotResource?: string | string[] | undefined;
|
169 | }
|
170 | export type StatementAction = { Action: string | string[] } | { NotAction: string | string[] };
|
171 | export type StatementResource = MaybeStatementPrincipal &
|
172 | ({ Resource: string | string[] } | { NotResource: string | string[] });
|
173 | export type StatementPrincipal = MaybeStatementResource &
|
174 | ({ Principal: PrincipalValue } | { NotPrincipal: PrincipalValue });
|