Skip to content

Commit 1a86c0c

Browse files
Merge pull request #47 from vrtdev/bug/authorize-caching
Bugfix: do not cache authorize calls with new caching system
2 parents b9f217a + 1b50635 commit 1a86c0c

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

templates/authorizer.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Equals, route53, FindInMap, AWS_REGION, serverless, constants, awslambda, kms, iam, s3, dynamodb, \
44
ImportValue, Not, And, Condition, If, AWS_NO_VALUE
55
from troposphere.cloudfront import Origin, CustomOriginConfig, Distribution, \
6-
DistributionConfig, ViewerCertificate, DefaultCacheBehavior, ForwardedValues, Cookies
6+
DistributionConfig, ViewerCertificate, DefaultCacheBehavior
77
import custom_resources.ssm
88
import custom_resources.acm
99
import custom_resources.cognito
@@ -124,22 +124,21 @@
124124
))
125125
template.set_parameter_label(param_create_own_cloudfront, "Create own CloudFront distribution")
126126

127-
cookies = template.add_parameter(Parameter(
128-
"Cookies",
129-
Type=constants.COMMA_DELIMITED_LIST,
130-
Default="refresh_token",
131-
Description="Comma delimited list of Cookies that will be used in cache key and forwarded to the origin. \
132-
Stack will fail if list is empty while using 'Forward-list' as 'Cookie behaviour'",
127+
cache_policy_id = template.add_parameter(Parameter(
128+
"CachePolicyId",
129+
Type=constants.STRING,
130+
Default="4135ea2d-6df8-44a3-9df3-4b5a84be39ad", # Managed-CachingDisabled
131+
Description="Cache policy ID to use for the CloudFront distribution.",
133132
))
134-
template.set_parameter_label(cookies, "Comma delimited list of Cookies to forward.")
133+
template.set_parameter_label(cache_policy_id, "Cache policy ID to use for the CloudFront distribution.")
135134

136-
headers = template.add_parameter(Parameter(
137-
"Headers",
138-
Type=constants.COMMA_DELIMITED_LIST,
139-
Default="Authorization,Host",
140-
Description="Comma delimited list of Headers that will be used in cache key and forwarded to the origin.",
135+
origin_policy_id = template.add_parameter(Parameter(
136+
"OriginPolicyId",
137+
Type=constants.STRING,
138+
Default="216adef6-5c7f-47e4-b989-5492eafa07d3", # Managed-AllViewer
139+
Description="Origin policy ID to use for the CloudFront distribution.",
141140
))
142-
template.set_parameter_label(headers, "Comma delimited list of Headers to forward.")
141+
template.set_parameter_label(origin_policy_id, "Origin policy ID to use for the CloudFront distribution.")
143142

144143
use_domain_name = template.add_parameter(Parameter(
145144
"UseDomainName",
@@ -734,14 +733,8 @@
734733
DefaultCacheBehavior=DefaultCacheBehavior(
735734
ViewerProtocolPolicy='redirect-to-https', # HTTPS required. Cookies need to be sent securely
736735
TargetOriginId='default',
737-
ForwardedValues=ForwardedValues(
738-
Headers=Ref(headers),
739-
QueryString=True,
740-
Cookies=Cookies(
741-
Forward='whitelist',
742-
WhitelistedNames=Ref(cookies), # Cookies can be edited in the Cookies parameter
743-
),
744-
),
736+
CachePolicyId=Ref(cache_policy_id),
737+
OriginRequestPolicyId=Ref(origin_policy_id),
745738
AllowedMethods=['DELETE', 'GET', 'HEAD', 'OPTIONS', 'PATCH', 'POST', 'PUT'], # /delegate sends POST
746739
),
747740
ViewerCertificate=ViewerCertificate(

0 commit comments

Comments
 (0)