Skip to content

Commit 4169ae1

Browse files
authored
feat(AWS API Gateway): Allow CF funcs in authorizer.scopes (#11505)
1 parent 7847b20 commit 4169ae1

File tree

2 files changed

+38
-1
lines changed
  • lib/plugins/aws/package/compile/events/api-gateway
  • test/unit/lib/plugins/aws/package/compile/events/api-gateway/lib/method

2 files changed

+38
-1
lines changed

lib/plugins/aws/package/compile/events/api-gateway/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ const authorizerSchema = {
6363
managedExternally: { type: 'boolean' },
6464
name: { type: 'string' },
6565
resultTtlInSeconds: { type: 'integer', minimum: 0, maximum: 3600 },
66-
scopes: { type: 'array', items: { type: 'string' } },
66+
scopes: {
67+
type: 'array',
68+
items: {
69+
anyOf: [{ type: 'string' }, { $ref: '#/definitions/awsCfInstruction' }],
70+
},
71+
},
6772
type: {
6873
anyOf: ['token', 'cognito_user_pools', 'request', 'aws_iam', 'custom'].map(
6974
caseInsensitive

test/unit/lib/plugins/aws/package/compile/events/api-gateway/lib/method/index.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,38 @@ describe('#compileMethods()', () => {
749749
).to.not.have.property('AuthorizationScopes');
750750
});
751751

752+
it('should pass on import functions for a cognito user pool authorizer scopes', () => {
753+
awsCompileApigEvents.validated.events = [
754+
{
755+
functionName: 'First',
756+
http: {
757+
authorizer: {
758+
name: 'authorizer',
759+
type: 'COGNITO_USER_POOLS',
760+
authorizerId: { Ref: 'CognitoAuthorizer' },
761+
scopes: [
762+
{
763+
'Fn::ImportValue': 'ImportedScope',
764+
},
765+
],
766+
},
767+
integration: 'AWS',
768+
path: 'users/create',
769+
method: 'post',
770+
},
771+
},
772+
];
773+
774+
awsCompileApigEvents.compileMethods();
775+
const resource =
776+
awsCompileApigEvents.serverless.service.provider.compiledCloudFormationTemplate.Resources
777+
.ApiGatewayMethodUsersCreatePost;
778+
779+
expect(resource.Properties.AuthorizationScopes[0]).to.deep.equal({
780+
'Fn::ImportValue': 'ImportedScope',
781+
});
782+
});
783+
752784
it('should set claims for a cognito user pool', () => {
753785
awsCompileApigEvents.validated.events = [
754786
{

0 commit comments

Comments
 (0)