From 60bda6cf4f8cd130f8a47a3dc3cdcd71bbffc6ea Mon Sep 17 00:00:00 2001 From: keita-nishimoto Date: Mon, 27 Mar 2017 14:15:05 +0900 Subject: [PATCH] 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;