Skip to content

Commit c2b8d6b

Browse files
fix: Add support for passing authorization_scopes on routes with JWT authorizer (#67)
Co-authored-by: Jeffrey Schilperoord <jschilperoord@schubergphilis.com>
1 parent bafb534 commit c2b8d6b

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

examples/complete-http/main.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@ module "api_gateway" {
8181
authorizer_key = "cognito"
8282
}
8383

84+
"GET /some-route-with-authorizer-and-scope" = {
85+
lambda_arn = module.lambda_function.lambda_function_arn
86+
payload_format_version = "2.0"
87+
authorizer_key = "cognito"
88+
authorization_scopes = "tf/something.relevant.read,tf/something.relevant.write" # Should comply with the resource server configuration part of the cognito user pool
89+
}
90+
91+
"GET /some-route-with-authorizer-and-different-scope" = {
92+
lambda_arn = module.lambda_function.lambda_function_arn
93+
payload_format_version = "2.0"
94+
authorizer_key = "cognito"
95+
authorization_scopes = "tf/something.relevant.write" # Should comply with the resource server configuration part of the cognito user pool
96+
}
97+
8498
"POST /start-step-function" = {
8599
integration_type = "AWS_PROXY"
86100
integration_subtype = "StepFunctions-StartExecution"

main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,16 @@ resource "aws_apigatewayv2_route" "this" {
125125
route_key = each.key
126126

127127
api_key_required = try(each.value.api_key_required, null)
128+
authorization_scopes = try(split(",", each.value.authorization_scopes), null)
128129
authorization_type = try(each.value.authorization_type, "NONE")
129130
authorizer_id = try(aws_apigatewayv2_authorizer.this[each.value.authorizer_key].id, each.value.authorizer_id, null)
130131
model_selection_expression = try(each.value.model_selection_expression, null)
131132
operation_name = try(each.value.operation_name, null)
132133
route_response_selection_expression = try(each.value.route_response_selection_expression, null)
133134
target = "integrations/${aws_apigatewayv2_integration.this[each.key].id}"
134135

135-
# Not sure what structure is allowed for these arguments...
136-
# authorization_scopes = try(each.value.authorization_scopes, null)
137-
# request_models = try(each.value.request_models, null)
136+
# Have been added to the docs. But is WEBSOCKET only(not yet supported)
137+
# request_models = try(each.value.request_models, null)
138138
}
139139

140140
resource "aws_apigatewayv2_integration" "this" {

0 commit comments

Comments
 (0)