44import json
55import logging
66from datetime import datetime
7- from typing import List , Optional , Union
7+ from typing import List , Optional , TypedDict , Union
88from urllib import parse as urlparse
99
1010from 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