Repository: serverless/serverless (JavaScript)
Date: 2016-08-30 21:06:46+00:00
Task type: Bug Fix

Issue:
Custom Authorizer default header should be Authorization instead of Auth
# This is a Bug Report
## Description

The default header for custom authorizers seems to be "Auth": 
https://github.com/serverless/serverless/blob/7715c014fd34fc9b48401231c16ffe6c2467eed3/lib/plugins/aws/deploy/compile/events/apiGateway/lib/authorizers.js#L30
https://github.com/serverless/serverless/blob/7715c014fd34fc9b48401231c16ffe6c2467eed3/lib/plugins/aws/deploy/compile/events/apiGateway/lib/authorizers.js#L47

I think the default header should be "Authorization" like it is in AWS API Gateway, and in the HTTP protocol in general. When it's called "Authorization", it will be included all kinds of defaults like CORS configurations and CloudFront headers, making life easier.



Issue discussion:
Yup that sounds good, added it to the next milestone and a help-wanted-easy label if somebody picks it up for a PR before us.


Solution patch:
diff --git a/lib/plugins/aws/deploy/compile/events/apiGateway/README.md b/lib/plugins/aws/deploy/compile/events/apiGateway/README.md
index 649e0d89660..3e426103cfa 100644
--- a/lib/plugins/aws/deploy/compile/events/apiGateway/README.md
+++ b/lib/plugins/aws/deploy/compile/events/apiGateway/README.md
@@ -85,7 +85,7 @@ functions:
           authorizer:
             name: authorizerFunc
             resultTtlInSeconds: 0
-            identitySource: method.request.header.Auth
+            identitySource: method.request.header.Authorization
             identityValidationExpression: someRegex
   authorizerFunc:
     handler: handlers.authorizerFunc
@@ -122,7 +122,7 @@ functions:
           authorizer:
             arn: xxx:xxx:Lambda-Name
             resultTtlInSeconds: 0
-            identitySource: method.request.header.Auth
+            identitySource: method.request.header.Authorization
             identityValidationExpression: someRegex
 ```
 
diff --git a/lib/plugins/aws/deploy/compile/events/apiGateway/lib/authorizers.js b/lib/plugins/aws/deploy/compile/events/apiGateway/lib/authorizers.js
index b2c2f0a4bf4..af11e3e7104 100644
--- a/lib/plugins/aws/deploy/compile/events/apiGateway/lib/authorizers.js
+++ b/lib/plugins/aws/deploy/compile/events/apiGateway/lib/authorizers.js
@@ -27,7 +27,7 @@ module.exports = {
               authorizerName = splittedLambdaName[splittedLambdaName.length - 1];
             }
             resultTtlInSeconds = 300;
-            identitySource = 'method.request.header.Auth';
+            identitySource = 'method.request.header.Authorization';
           } else if (typeof authorizer === 'object') {
             if (authorizer.arn) {
               authorizerArn = authorizer.arn;
@@ -44,7 +44,7 @@ module.exports = {
                 .Error('Please provide either an authorizer name or ARN');
             }
             resultTtlInSeconds = Number.parseInt(authorizer.resultTtlInSeconds, 10) || 300;
-            identitySource = authorizer.identitySource || 'method.request.header.Auth';
+            identitySource = authorizer.identitySource || 'method.request.header.Authorization';
           } else {
             const errorMessage = [
               `authorizer property in function ${functionName} is not an object nor a string.`,


Test patch:
diff --git a/lib/plugins/aws/deploy/compile/events/apiGateway/tests/authorizers.js b/lib/plugins/aws/deploy/compile/events/apiGateway/tests/authorizers.js
index d921e934927..d1faafb2ebf 100644
--- a/lib/plugins/aws/deploy/compile/events/apiGateway/tests/authorizers.js
+++ b/lib/plugins/aws/deploy/compile/events/apiGateway/tests/authorizers.js
@@ -71,7 +71,7 @@ describe('#compileAuthorizers()', () => {
       expect(
         awsCompileApigEvents.serverless.service.provider.compiledCloudFormationTemplate
           .Resources.authorizerAuthorizer.Properties.IdentitySource
-      ).to.equal('method.request.header.Auth');
+      ).to.equal('method.request.header.Authorization');
 
       expect(
         awsCompileApigEvents.serverless.service.provider.compiledCloudFormationTemplate