add type option to authorizer. implements #4325

This commit is contained in:
Jonathan Spies 2017-10-10 12:31:22 -05:00
parent 5e17b3e414
commit e75c783365
3 changed files with 22 additions and 2 deletions

View File

@ -277,6 +277,7 @@ functions:
resultTtlInSeconds: 0
identitySource: method.request.header.Authorization
identityValidationExpression: someRegex
type: token
authorizerFunc:
handler: handler.authorizerFunc
```
@ -313,6 +314,24 @@ functions:
identityValidationExpression: someRegex
```
You can also use the Request Type Authorizer by setting the `type` property. In this case, you
do not need the `identitySource`
```yml
functions:
create:
handler: posts.create
events:
- http:
path: posts/create
method: post
authorizer:
arn: xxx:xxx:Lambda-Name
resultTtlInSeconds: 0
identityValidationExpression: someRegex
type: request
```
You can also configure an existing Cognito User Pool as the authorizer, as shown
in the following example:

View File

@ -37,7 +37,7 @@ module.exports = {
'/invocations',
],
] };
authorizerProperties.Type = 'TOKEN';
authorizerProperties.Type = authorizer.type ? authorizer.type.toUpperCase() : 'TOKEN';
}
_.merge(this.serverless.service.provider.compiledCloudFormationTemplate.Resources, {

View File

@ -68,6 +68,7 @@ describe('#compileAuthorizers()', () => {
resultTtlInSeconds: 500,
identitySource: 'method.request.header.Custom',
identityValidationExpression: 'regex',
type: 'request',
},
},
}];
@ -92,7 +93,7 @@ describe('#compileAuthorizers()', () => {
expect(resource.Properties.IdentityValidationExpression).to.equal('regex');
expect(resource.Properties.Name).to.equal('authorizer');
expect(resource.Properties.RestApiId.Ref).to.equal('ApiGatewayRestApi');
expect(resource.Properties.Type).to.equal('TOKEN');
expect(resource.Properties.Type).to.equal('REQUEST');
});
});