Skip to content

Commit e4367a0

Browse files
fix(apigateway): authorization scope is not added when not explicitly defining authorization type in method or root api (#30822)
### Issue # (if applicable) Closes #30444 ### Reason for this change The original PR caused a breaking change, we can't rollback because it was released in v2.142.0 and it fixes customers issues (partially). Simply doing a revert will be breaking for those customers again. ### Description of changes Identified the root cause and we should use `AuthorizationType` instead of `AuthorizationTypeOption`. `AuthorizationType` defaults to find the authorization type from the authorizer, falling back to use the auth type defined in the `Method` construct's options property and falling back to `None`. `AuthorizationTypeOptions` on the other hand tries to find the auth type from `Method` construct's options property which can be None because it's optional. ### Description of how you validated changes New unit tests covering the changes and new integration tests covering it. ### Checklist - [ ] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 727e886 commit e4367a0

12 files changed

+1028
-5
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/authorizers/integ.api-with-authorizer-and-method.js.snapshot/apigatewaywithauthorizerandproxyDefaultTestDeployAssertDBEA1774.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/authorizers/integ.api-with-authorizer-and-method.js.snapshot/apigatewaywithauthorizerandproxyDefaultTestDeployAssertDBEA1774.template.json

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/authorizers/integ.api-with-authorizer-and-method.js.snapshot/cdk.out

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/authorizers/integ.api-with-authorizer-and-method.js.snapshot/integ.json

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/authorizers/integ.api-with-authorizer-and-method.js.snapshot/integtest-restapi-with-authorizer-and-proxy.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
{
2+
"Resources": {
3+
"UserPool6BA7E5F2": {
4+
"Type": "AWS::Cognito::UserPool",
5+
"Properties": {
6+
"AccountRecoverySetting": {
7+
"RecoveryMechanisms": [
8+
{
9+
"Name": "verified_phone_number",
10+
"Priority": 1
11+
},
12+
{
13+
"Name": "verified_email",
14+
"Priority": 2
15+
}
16+
]
17+
},
18+
"AdminCreateUserConfig": {
19+
"AllowAdminCreateUserOnly": true
20+
},
21+
"EmailVerificationMessage": "The verification code to your new account is {####}",
22+
"EmailVerificationSubject": "Verify your new account",
23+
"SmsVerificationMessage": "The verification code to your new account is {####}",
24+
"VerificationMessageTemplate": {
25+
"DefaultEmailOption": "CONFIRM_WITH_CODE",
26+
"EmailMessage": "The verification code to your new account is {####}",
27+
"EmailSubject": "Verify your new account",
28+
"SmsMessage": "The verification code to your new account is {####}"
29+
}
30+
},
31+
"UpdateReplacePolicy": "Retain",
32+
"DeletionPolicy": "Retain"
33+
},
34+
"AuthorizerBD825682": {
35+
"Type": "AWS::ApiGateway::Authorizer",
36+
"Properties": {
37+
"IdentitySource": "method.request.header.Authorization",
38+
"Name": "integtestrestapiwithauthorizerandproxyAuthorizer5142DDC8",
39+
"ProviderARNs": [
40+
{
41+
"Fn::GetAtt": [
42+
"UserPool6BA7E5F2",
43+
"Arn"
44+
]
45+
}
46+
],
47+
"RestApiId": {
48+
"Ref": "CdkTestStack0AE13CA5"
49+
},
50+
"Type": "COGNITO_USER_POOLS"
51+
}
52+
},
53+
"CdkTestStack0AE13CA5": {
54+
"Type": "AWS::ApiGateway::RestApi",
55+
"Properties": {
56+
"Name": "CdkTestStack"
57+
}
58+
},
59+
"CdkTestStackDeployment201712E9c8d53ab4e4cdcaa7ab0f70bb7f6ce970": {
60+
"Type": "AWS::ApiGateway::Deployment",
61+
"Properties": {
62+
"Description": "Automatically created by the RestApi construct",
63+
"RestApiId": {
64+
"Ref": "CdkTestStack0AE13CA5"
65+
}
66+
},
67+
"DependsOn": [
68+
"AuthorizerBD825682",
69+
"CdkTestStackotherPOST3BA23287",
70+
"CdkTestStackother6044D106",
71+
"CdkTestStackuserGET1317379E",
72+
"CdkTestStackuser7876F2D4"
73+
]
74+
},
75+
"CdkTestStackDeploymentStageprod296E6472": {
76+
"Type": "AWS::ApiGateway::Stage",
77+
"Properties": {
78+
"DeploymentId": {
79+
"Ref": "CdkTestStackDeployment201712E9c8d53ab4e4cdcaa7ab0f70bb7f6ce970"
80+
},
81+
"RestApiId": {
82+
"Ref": "CdkTestStack0AE13CA5"
83+
},
84+
"StageName": "prod"
85+
}
86+
},
87+
"CdkTestStackuser7876F2D4": {
88+
"Type": "AWS::ApiGateway::Resource",
89+
"Properties": {
90+
"ParentId": {
91+
"Fn::GetAtt": [
92+
"CdkTestStack0AE13CA5",
93+
"RootResourceId"
94+
]
95+
},
96+
"PathPart": "user",
97+
"RestApiId": {
98+
"Ref": "CdkTestStack0AE13CA5"
99+
}
100+
}
101+
},
102+
"CdkTestStackuserGET1317379E": {
103+
"Type": "AWS::ApiGateway::Method",
104+
"Properties": {
105+
"AuthorizationScopes": [
106+
"profile"
107+
],
108+
"AuthorizationType": "COGNITO_USER_POOLS",
109+
"AuthorizerId": {
110+
"Ref": "AuthorizerBD825682"
111+
},
112+
"HttpMethod": "GET",
113+
"Integration": {
114+
"Type": "MOCK"
115+
},
116+
"ResourceId": {
117+
"Ref": "CdkTestStackuser7876F2D4"
118+
},
119+
"RestApiId": {
120+
"Ref": "CdkTestStack0AE13CA5"
121+
}
122+
}
123+
},
124+
"CdkTestStackother6044D106": {
125+
"Type": "AWS::ApiGateway::Resource",
126+
"Properties": {
127+
"ParentId": {
128+
"Fn::GetAtt": [
129+
"CdkTestStack0AE13CA5",
130+
"RootResourceId"
131+
]
132+
},
133+
"PathPart": "other",
134+
"RestApiId": {
135+
"Ref": "CdkTestStack0AE13CA5"
136+
}
137+
}
138+
},
139+
"CdkTestStackotherPOST3BA23287": {
140+
"Type": "AWS::ApiGateway::Method",
141+
"Properties": {
142+
"AuthorizationScopes": [
143+
"openid"
144+
],
145+
"AuthorizationType": "COGNITO_USER_POOLS",
146+
"AuthorizerId": {
147+
"Ref": "AuthorizerBD825682"
148+
},
149+
"HttpMethod": "POST",
150+
"Integration": {
151+
"Type": "MOCK"
152+
},
153+
"ResourceId": {
154+
"Ref": "CdkTestStackother6044D106"
155+
},
156+
"RestApiId": {
157+
"Ref": "CdkTestStack0AE13CA5"
158+
}
159+
}
160+
}
161+
},
162+
"Outputs": {
163+
"CdkTestStackEndpoint7DDDB759": {
164+
"Value": {
165+
"Fn::Join": [
166+
"",
167+
[
168+
"https://",
169+
{
170+
"Ref": "CdkTestStack0AE13CA5"
171+
},
172+
".execute-api.",
173+
{
174+
"Ref": "AWS::Region"
175+
},
176+
".",
177+
{
178+
"Ref": "AWS::URLSuffix"
179+
},
180+
"/",
181+
{
182+
"Ref": "CdkTestStackDeploymentStageprod296E6472"
183+
},
184+
"/"
185+
]
186+
]
187+
}
188+
}
189+
},
190+
"Parameters": {
191+
"BootstrapVersion": {
192+
"Type": "AWS::SSM::Parameter::Value<String>",
193+
"Default": "/cdk-bootstrap/hnb659fds/version",
194+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
195+
}
196+
},
197+
"Rules": {
198+
"CheckBootstrapVersion": {
199+
"Assertions": [
200+
{
201+
"Assert": {
202+
"Fn::Not": [
203+
{
204+
"Fn::Contains": [
205+
[
206+
"1",
207+
"2",
208+
"3",
209+
"4",
210+
"5"
211+
],
212+
{
213+
"Ref": "BootstrapVersion"
214+
}
215+
]
216+
}
217+
]
218+
},
219+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
220+
}
221+
]
222+
}
223+
}
224+
}

0 commit comments

Comments
 (0)