Skip to content

Commit 4dc4bfd

Browse files
authored
Merge pull request #55 from erezrokah/fix/custom_auth_type_cognito
fix(cognito_auth): allow setting authorizerId for cognito
2 parents 68191ce + 4c5c8a0 commit 4dc4bfd

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

lib/apiGateway/schema.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const authorizationScopes = Joi.array()
5151
const authorizationType = Joi.alternatives().when('authorizerId', {
5252
is: authorizerId.required(),
5353
then: Joi.string()
54-
.valid('CUSTOM')
54+
.valid('CUSTOM', 'COGNITO_USER_POOLS')
5555
.required(),
5656
otherwise: Joi.alternatives().when('authorizationScopes', {
5757
is: authorizationScopes.required(),
@@ -103,12 +103,7 @@ const proxy = Joi.object({
103103
authorizationScopes,
104104
roleArn,
105105
acceptParameters
106-
})
107-
.oxor('authorizerId', 'authorizationScopes') // can have one of them, but not required
108-
.error(
109-
customErrorBuilder('object.oxor', 'cannot set both "authorizerId" and "authorizationScopes"')
110-
)
111-
.required()
106+
}).required()
112107

113108
const stringOrRef = Joi.alternatives().try([
114109
Joi.string(),

lib/apiGateway/validate.test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ describe('#validateServiceProxies()', () => {
453453
)
454454
})
455455

456-
it('should throw if "authorizationType" is not set to "CUSTOM" when the "authorizerId" property is set', () => {
456+
it('should throw if "authorizationType" is not set to "CUSTOM" or "COGNITO_USER_POOLS" when the "authorizerId" property is set', () => {
457457
serverlessApigatewayServiceProxy.serverless.service.custom = {
458458
apiGatewayServiceProxies: [
459459
{
@@ -470,7 +470,7 @@ describe('#validateServiceProxies()', () => {
470470

471471
expect(() => serverlessApigatewayServiceProxy.validateServiceProxies()).to.throw(
472472
serverless.classes.Error,
473-
'child "kinesis" fails because [child "authorizationType" fails because ["authorizationType" must be one of [CUSTOM]]]'
473+
'child "kinesis" fails because [child "authorizationType" fails because ["authorizationType" must be one of [CUSTOM, COGNITO_USER_POOLS]]]'
474474
)
475475
})
476476

@@ -564,6 +564,7 @@ describe('#validateServiceProxies()', () => {
564564
path: '/kinesis',
565565
streamName: 'streamName',
566566
authorizationType: 'COGNITO_USER_POOLS',
567+
authorizerId: { Ref: 'SomeAuthorizerId' },
567568
authorizationScopes: ['editor', 'owner'],
568569
method: 'post'
569570
}
@@ -575,6 +576,7 @@ describe('#validateServiceProxies()', () => {
575576

576577
expect(json.events[0].http.auth).to.deep.equal({
577578
authorizationType: 'COGNITO_USER_POOLS',
579+
authorizerId: { Ref: 'SomeAuthorizerId' },
578580
authorizationScopes: ['editor', 'owner']
579581
})
580582
})

0 commit comments

Comments
 (0)