mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-02 19:43:20 +08:00
Merge pull request #15387 from keita-nishimoto/api-gateway-custom-authorizer-event
add API Gateway CustomAuthorizerEvent
This commit is contained in:
@@ -5,12 +5,17 @@ var num: number = 5;
|
||||
var error: Error = new Error();
|
||||
var b: boolean = true;
|
||||
var apiGwEvt: AWSLambda.APIGatewayEvent;
|
||||
var customAuthorizerEvt: AWSLambda.CustomAuthorizerEvent;
|
||||
var clientCtx: AWSLambda.ClientContext;
|
||||
var clientContextEnv: AWSLambda.ClientContextEnv;
|
||||
var clientContextClient: AWSLambda.ClientContextClient;
|
||||
var context: AWSLambda.Context;
|
||||
var identity: AWSLambda.CognitoIdentity;
|
||||
var proxyResult: AWSLambda.ProxyResult;
|
||||
var authResponse: AWSLambda.AuthResponse;
|
||||
var policyDocument: AWSLambda.PolicyDocument;
|
||||
var statement: AWSLambda.Statement;
|
||||
var authResponseContext: AWSLambda.AuthResponseContext;
|
||||
var snsEvt: AWSLambda.SNSEvent;
|
||||
var snsEvtRecs: AWSLambda.SNSEventRecord[];
|
||||
var snsEvtRec: AWSLambda.SNSEventRecord;
|
||||
@@ -87,6 +92,11 @@ str = apiGwEvt.requestContext.resourceId;
|
||||
str = apiGwEvt.requestContext.resourcePath;
|
||||
str = apiGwEvt.resource;
|
||||
|
||||
/* API Gateway CustomAuthorizer Event */
|
||||
str = customAuthorizerEvt.type;
|
||||
str = customAuthorizerEvt.authorizationToken;
|
||||
str = customAuthorizerEvt.methodArn;
|
||||
|
||||
/* SNS Event */
|
||||
snsEvtRecs = snsEvt.Records;
|
||||
|
||||
@@ -119,6 +129,41 @@ proxyResult.headers["example"] = b;
|
||||
proxyResult.headers["example"] = num;
|
||||
str = proxyResult.body;
|
||||
|
||||
/* API Gateway CustomAuthorizer AuthResponse */
|
||||
authResponseContext = {
|
||||
stringKey: str,
|
||||
numberKey: num,
|
||||
booleanKey: b
|
||||
};
|
||||
|
||||
statement = {
|
||||
Action: str,
|
||||
Effect: str,
|
||||
Resource: str
|
||||
};
|
||||
|
||||
statement = {
|
||||
Action: [str, str],
|
||||
Effect: str,
|
||||
Resource: [str, str]
|
||||
};
|
||||
|
||||
policyDocument = {
|
||||
Version: str,
|
||||
Statement: [statement]
|
||||
};
|
||||
|
||||
authResponse = {
|
||||
principalId: str,
|
||||
policyDocument: policyDocument,
|
||||
context: authResponseContext
|
||||
};
|
||||
|
||||
authResponse = {
|
||||
principalId: str,
|
||||
policyDocument: policyDocument
|
||||
};
|
||||
|
||||
/* Context */
|
||||
b = context.callbackWaitsForEmptyEventLoop;
|
||||
str = context.functionName;
|
||||
@@ -170,6 +215,14 @@ function proxyCallback(cb: AWSLambda.ProxyCallback) {
|
||||
cb(null, proxyResult);
|
||||
}
|
||||
|
||||
/* CustomAuthorizerCallback */
|
||||
function customAuthorizerCallback(cb: AWSLambda.CustomAuthorizerCallback) {
|
||||
cb();
|
||||
cb(null);
|
||||
cb(error);
|
||||
cb(null, authResponse);
|
||||
}
|
||||
|
||||
/* Compatibility functions */
|
||||
context.done();
|
||||
context.done(error);
|
||||
@@ -183,3 +236,4 @@ context.fail(str);
|
||||
/* Handler */
|
||||
let handler: AWSLambda.Handler = (event: any, context: AWSLambda.Context, cb: AWSLambda.Callback) => { };
|
||||
let proxyHandler: AWSLambda.ProxyHandler = (event: AWSLambda.APIGatewayEvent, context: AWSLambda.Context, cb: AWSLambda.ProxyCallback) => { };
|
||||
let CustomAuthorizerHandler: AWSLambda.CustomAuthorizerHandler = (event: AWSLambda.CustomAuthorizerEvent, context: AWSLambda.Context, cb: AWSLambda.CustomAuthorizerCallback) => { };
|
||||
|
||||
46
types/aws-lambda/index.d.ts
vendored
46
types/aws-lambda/index.d.ts
vendored
@@ -39,6 +39,13 @@ interface APIGatewayEvent {
|
||||
resource: string;
|
||||
}
|
||||
|
||||
// API Gateway CustomAuthorizer "event"
|
||||
interface CustomAuthorizerEvent {
|
||||
type: string;
|
||||
authorizationToken: string;
|
||||
methodArn: string;
|
||||
}
|
||||
|
||||
// SNS "event"
|
||||
interface SNSMessageAttribute {
|
||||
Type: string;
|
||||
@@ -180,6 +187,43 @@ interface ProxyResult {
|
||||
body: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* API Gateway CustomAuthorizer AuthResponse.
|
||||
* http://docs.aws.amazon.com/apigateway/latest/developerguide/use-custom-authorizer.html#api-gateway-custom-authorizer-output
|
||||
*/
|
||||
interface AuthResponse {
|
||||
principalId: string;
|
||||
policyDocument: PolicyDocument;
|
||||
context?: AuthResponseContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* API Gateway CustomAuthorizer AuthResponse.PolicyDocument.
|
||||
* http://docs.aws.amazon.com/apigateway/latest/developerguide/use-custom-authorizer.html#api-gateway-custom-authorizer-output
|
||||
*/
|
||||
interface PolicyDocument {
|
||||
Version: string;
|
||||
Statement: [Statement];
|
||||
}
|
||||
|
||||
/**
|
||||
* API Gateway CustomAuthorizer AuthResponse.PolicyDocument.Statement.
|
||||
* http://docs.aws.amazon.com/apigateway/latest/developerguide/use-custom-authorizer.html#api-gateway-custom-authorizer-output
|
||||
*/
|
||||
interface Statement {
|
||||
Action: string | [string];
|
||||
Effect: string;
|
||||
Resource: string | [string];
|
||||
}
|
||||
|
||||
/**
|
||||
* API Gateway CustomAuthorizer AuthResponse.PolicyDocument.Statement.
|
||||
* http://docs.aws.amazon.com/apigateway/latest/developerguide/use-custom-authorizer.html#api-gateway-custom-authorizer-output
|
||||
*/
|
||||
interface AuthResponseContext {
|
||||
[name: string]: string | number | boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* AWS Lambda handler function.
|
||||
* http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html
|
||||
@@ -190,6 +234,7 @@ interface ProxyResult {
|
||||
*/
|
||||
export type Handler = (event: any, context: Context, callback?: Callback) => void;
|
||||
export type ProxyHandler = (event: APIGatewayEvent, context: Context, callback?: ProxyCallback) => void;
|
||||
export type CustomAuthorizerHandler = (event: CustomAuthorizerEvent, context: Context, callback?: CustomAuthorizerCallback) => void;
|
||||
|
||||
/**
|
||||
* Optional callback parameter.
|
||||
@@ -200,5 +245,6 @@ export type ProxyHandler = (event: APIGatewayEvent, context: Context, callback?:
|
||||
*/
|
||||
export type Callback = (error?: Error, result?: any) => void;
|
||||
export type ProxyCallback = (error?: Error, result?: ProxyResult) => void;
|
||||
export type CustomAuthorizerCallback = (error?: Error, result?: AuthResponse) => void;
|
||||
|
||||
export as namespace AWSLambda;
|
||||
|
||||
Reference in New Issue
Block a user