From 5a634f7fdb5b593c50b229c5a14507789c888be7 Mon Sep 17 00:00:00 2001 From: KeitaNishimoto Date: Sun, 26 Mar 2017 01:45:51 +0900 Subject: [PATCH 1/4] add API Gateway CustomAuthorizerEvent --- types/aws-lambda/aws-lambda-tests.ts | 7 +++++++ types/aws-lambda/index.d.ts | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/types/aws-lambda/aws-lambda-tests.ts b/types/aws-lambda/aws-lambda-tests.ts index 3aede36d4c..07908b2677 100644 --- a/types/aws-lambda/aws-lambda-tests.ts +++ b/types/aws-lambda/aws-lambda-tests.ts @@ -5,6 +5,7 @@ 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; @@ -87,6 +88,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; @@ -183,3 +189,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.Callback) => { }; diff --git a/types/aws-lambda/index.d.ts b/types/aws-lambda/index.d.ts index c5e49d54c6..f388302d24 100644 --- a/types/aws-lambda/index.d.ts +++ b/types/aws-lambda/index.d.ts @@ -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; @@ -190,6 +197,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?: Callback) => void; /** * Optional callback parameter. From 60bda6cf4f8cd130f8a47a3dc3cdcd71bbffc6ea Mon Sep 17 00:00:00 2001 From: keita-nishimoto Date: Mon, 27 Mar 2017 14:15:05 +0900 Subject: [PATCH 2/4] add CustomAuthorizerCallback & AuthResponse --- types/aws-lambda/aws-lambda-tests.ts | 49 +++++++++++++++++++++++++++- types/aws-lambda/index.d.ts | 42 +++++++++++++++++++++++- 2 files changed, 89 insertions(+), 2 deletions(-) diff --git a/types/aws-lambda/aws-lambda-tests.ts b/types/aws-lambda/aws-lambda-tests.ts index 07908b2677..3c22a88cbc 100644 --- a/types/aws-lambda/aws-lambda-tests.ts +++ b/types/aws-lambda/aws-lambda-tests.ts @@ -12,6 +12,10 @@ 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; @@ -125,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, + 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; @@ -176,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); @@ -189,4 +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.Callback) => { }; +let CustomAuthorizerHandler: AWSLambda.CustomAuthorizerHandler = (event: AWSLambda.CustomAuthorizerEvent, context: AWSLambda.Context, cb: AWSLambda.CustomAuthorizerCallback) => { }; diff --git a/types/aws-lambda/index.d.ts b/types/aws-lambda/index.d.ts index f388302d24..d8507ef7de 100644 --- a/types/aws-lambda/index.d.ts +++ b/types/aws-lambda/index.d.ts @@ -187,6 +187,45 @@ 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; + 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 { + stringKey: string; + numberKey: number; + booleanKey: boolean; +} + /** * AWS Lambda handler function. * http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html @@ -197,7 +236,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?: Callback) => void; +export type CustomAuthorizerHandler = (event: CustomAuthorizerEvent, context: Context, callback?: CustomAuthorizerCallback) => void; /** * Optional callback parameter. @@ -208,5 +247,6 @@ export type CustomAuthorizerHandler = (event: CustomAuthorizerEvent, context: Co */ 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; From 1436b17cd246b68dc7e1434d682ebe8bf2a327a1 Mon Sep 17 00:00:00 2001 From: KeitaNishimoto Date: Tue, 28 Mar 2017 22:46:35 +0900 Subject: [PATCH 3/4] fix Corrected the structure of "AuthResponseContext" was wrong --- types/aws-lambda/index.d.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/types/aws-lambda/index.d.ts b/types/aws-lambda/index.d.ts index d8507ef7de..4e94e5782c 100644 --- a/types/aws-lambda/index.d.ts +++ b/types/aws-lambda/index.d.ts @@ -221,9 +221,7 @@ interface Statement { * http://docs.aws.amazon.com/apigateway/latest/developerguide/use-custom-authorizer.html#api-gateway-custom-authorizer-output */ interface AuthResponseContext { - stringKey: string; - numberKey: number; - booleanKey: boolean; + [name: string]: string | number | boolean; } /** From 96666eee57ff5ebd734a3d7c72cf45ad74327f9c Mon Sep 17 00:00:00 2001 From: KeitaNishimoto Date: Thu, 30 Mar 2017 00:09:43 +0900 Subject: [PATCH 4/4] fix type Statement.Action(I responded to the review) --- types/aws-lambda/aws-lambda-tests.ts | 2 +- types/aws-lambda/index.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/types/aws-lambda/aws-lambda-tests.ts b/types/aws-lambda/aws-lambda-tests.ts index 3c22a88cbc..e793442177 100644 --- a/types/aws-lambda/aws-lambda-tests.ts +++ b/types/aws-lambda/aws-lambda-tests.ts @@ -143,7 +143,7 @@ statement = { }; statement = { - Action: str, + Action: [str, str], Effect: str, Resource: [str, str] }; diff --git a/types/aws-lambda/index.d.ts b/types/aws-lambda/index.d.ts index 4e94e5782c..a5fa271699 100644 --- a/types/aws-lambda/index.d.ts +++ b/types/aws-lambda/index.d.ts @@ -211,7 +211,7 @@ interface PolicyDocument { * http://docs.aws.amazon.com/apigateway/latest/developerguide/use-custom-authorizer.html#api-gateway-custom-authorizer-output */ interface Statement { - Action: string; + Action: string | [string]; Effect: string; Resource: string | [string]; }