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