Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

Commit 93e614f

Browse files
committed
Added authorizer_scopes to add_method
1 parent 645b097 commit 93e614f

File tree

1 file changed

+13
-5
lines changed
  • localstack-core/localstack/services/apigateway

1 file changed

+13
-5
lines changed

localstack-core/localstack/services/apigateway/helpers.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import json
55
import logging
66
from datetime import datetime
7-
from typing import List, Optional, Union
7+
from typing import List, Optional, TypedDict, Union
88
from urllib import parse as urlparse
99

1010
from jsonpatch import apply_patch
@@ -91,6 +91,11 @@ class OpenAPIExt:
9191
TAG_VALUE = "x-amazon-apigateway-tag-value"
9292

9393

94+
class AuthorizerConfig(TypedDict):
95+
authorizer: Authorizer
96+
authorization_scopes: Optional[list[str]]
97+
98+
9499
# TODO: make the CRUD operations in this file generic for the different model types (authorizes, validators, ...)
95100

96101

@@ -564,14 +569,14 @@ def create_authorizers(security_schemes: dict) -> None:
564569

565570
authorizers[security_scheme_name] = authorizer
566571

567-
def get_authorizer(path_payload: dict) -> Optional[Authorizer]:
572+
def get_authorizer(path_payload: dict) -> Optional[AuthorizerConfig]:
568573
if not (security_schemes := path_payload.get("security")):
569574
return None
570575

571576
for security_scheme in security_schemes:
572-
for security_scheme_name in security_scheme.keys():
577+
for security_scheme_name, scopes in security_scheme.items():
573578
if authorizer := authorizers.get(security_scheme_name):
574-
return authorizer
579+
return AuthorizerConfig(authorizer=authorizer, authorization_scopes=scopes)
575580

576581
def get_or_create_path(abs_path: str, base_path: str):
577582
parts = abs_path.rstrip("/").replace("//", "/").split("/")
@@ -815,7 +820,7 @@ def create_method_resource(child, method, method_schema):
815820
kwargs = {}
816821

817822
if authorizer := get_authorizer(method_schema) or default_authorizer:
818-
method_authorizer = authorizer or default_authorizer
823+
method_authorizer = authorizer["authorizer"]
819824
# override the authorizer_type if it's a TOKEN or REQUEST to CUSTOM
820825
if (authorizer_type := method_authorizer["type"]) in ("TOKEN", "REQUEST"):
821826
authorization_type = "CUSTOM"
@@ -824,6 +829,9 @@ def create_method_resource(child, method, method_schema):
824829

825830
kwargs["authorizer_id"] = method_authorizer["id"]
826831

832+
if authorization_scopes := authorizer.get("authorization_scopes"):
833+
kwargs["authorization_scopes"] = authorization_scopes
834+
827835
return child.add_method(
828836
method,
829837
api_key_required=api_key_required,

0 commit comments

Comments
 (0)