mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
add type option to authorizer. implements #4325
This commit is contained in:
parent
5e17b3e414
commit
e75c783365
@ -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:
|
||||
|
||||
|
||||
@ -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, {
|
||||
|
||||
@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user