Skip to content

Commit 484486d

Browse files
Merge pull request #212 from horike37/feature/fix_missing_scopes
fix: scopes is now passed through validation
2 parents f72f3bd + 091534e commit 484486d

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lib/deploy/events/apiGateway/validate.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ module.exports = {
151151
let identityValidationExpression;
152152
let claims;
153153
let authorizerId;
154+
let scopes;
154155

155156
if (typeof authorizer === 'string') {
156157
if (authorizer.toUpperCase() === 'AWS_IAM') {
@@ -186,6 +187,10 @@ module.exports = {
186187
type = authorizer.type;
187188
}
188189

190+
if (Array.isArray(authorizer.scopes)) {
191+
scopes = authorizer.scopes;
192+
}
193+
189194
resultTtlInSeconds = Number.parseInt(authorizer.resultTtlInSeconds, 10);
190195
resultTtlInSeconds = Number.isNaN(resultTtlInSeconds) ? 300 : resultTtlInSeconds;
191196
claims = authorizer.claims || [];
@@ -226,6 +231,7 @@ module.exports = {
226231
identitySource,
227232
identityValidationExpression,
228233
claims,
234+
scopes,
229235
};
230236
},
231237

lib/deploy/events/apiGateway/validate.test.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,38 @@ describe('#httpValidate()', () => {
450450
expect(authorizer.identityValidationExpression).to.equal('foo');
451451
});
452452

453+
it('should accept authorizer config with scopes', () => {
454+
serverlessStepFunctions.serverless.service.functions = {
455+
foo: {},
456+
};
457+
458+
serverlessStepFunctions.serverless.service.stepFunctions = {
459+
stateMachines: {
460+
first: {
461+
events: [
462+
{
463+
http: {
464+
method: 'GET',
465+
path: 'foo/bar',
466+
integration: 'MOCK',
467+
authorizer: {
468+
name: 'authorizer',
469+
arn: 'arn:aws:cognito-idp:eu-west-1:xxxxxxxxxx',
470+
identitySouce: 'method.request.header.Authorization',
471+
scopes: ['scope1', 'scope2'],
472+
},
473+
},
474+
},
475+
],
476+
},
477+
},
478+
};
479+
480+
const validated = serverlessStepFunctions.httpValidate();
481+
const authorizer = validated.events[0].http.authorizer;
482+
expect(authorizer.scopes).to.deep.equal(['scope1', 'scope2']);
483+
});
484+
453485
it('should accept authorizer config with a type', () => {
454486
serverlessStepFunctions.serverless.service.functions = {
455487
foo: {},
@@ -509,7 +541,6 @@ describe('#httpValidate()', () => {
509541
expect(validated.events[0].http.authorizer.authorizerId).to.equal('12345');
510542
});
511543

512-
513544
it('should accept authorizer config with a lambda arn', () => {
514545
serverlessStepFunctions.serverless.service.stepFunctions = {
515546
stateMachines: {

0 commit comments

Comments
 (0)