@@ -459,7 +459,7 @@ def add_apikey_security_definition(self):
459
459
self .security_definitions .update (api_key_security_definition )
460
460
461
461
def set_path_default_authorizer (self , path , default_authorizer , authorizers ,
462
- add_default_auth_to_preflight = True ):
462
+ add_default_auth_to_preflight = True , api_authorizers = None ):
463
463
"""
464
464
Adds the default_authorizer to the security block for each method on this path unless an Authorizer
465
465
was defined at the Function/Path/Method level. This is intended to be used to set the
@@ -531,7 +531,8 @@ def set_path_default_authorizer(self, path, default_authorizer, authorizers,
531
531
# No existing Authorizer found; use default
532
532
else :
533
533
security_dict = {}
534
- security_dict [default_authorizer ] = []
534
+ security_dict [default_authorizer ] = self ._get_authorization_scopes (api_authorizers ,
535
+ default_authorizer )
535
536
authorizer_security = [security_dict ]
536
537
537
538
security = existing_non_authorizer_security + authorizer_security
@@ -622,14 +623,17 @@ def add_auth_to_method(self, path, method_name, auth, api):
622
623
:param dict api: Reference to the related Api's properties as defined in the template.
623
624
"""
624
625
method_authorizer = auth and auth .get ('Authorizer' )
626
+ method_scopes = auth and auth .get ('AuthorizationScopes' )
627
+ api_auth = api and api .get ('Auth' )
628
+ authorizers = api_auth and api_auth .get ('Authorizers' )
625
629
if method_authorizer :
626
- self ._set_method_authorizer (path , method_name , method_authorizer )
630
+ self ._set_method_authorizer (path , method_name , method_authorizer , authorizers , method_scopes )
627
631
628
632
method_apikey_required = auth and auth .get ('ApiKeyRequired' )
629
633
if method_apikey_required is not None :
630
634
self ._set_method_apikey_handling (path , method_name , method_apikey_required )
631
635
632
- def _set_method_authorizer (self , path , method_name , authorizer_name ):
636
+ def _set_method_authorizer (self , path , method_name , authorizer_name , authorizers = {}, method_scopes = None ):
633
637
"""
634
638
Adds the authorizer_name to the security block for each method on this path.
635
639
This is used to configure the authorizer for individual functions.
@@ -656,6 +660,13 @@ def _set_method_authorizer(self, path, method_name, authorizer_name):
656
660
# This assumes there are no autorizers already configured in the existing security block
657
661
security = existing_security + authorizer_security
658
662
663
+ if authorizer_name != 'NONE' and authorizers :
664
+ method_auth_scopes = authorizers .get (authorizer_name , {}).get ("AuthorizationScopes" )
665
+ if method_scopes is not None :
666
+ method_auth_scopes = method_scopes
667
+ if authorizers .get (authorizer_name ) is not None and method_auth_scopes is not None :
668
+ security_dict [authorizer_name ] = method_auth_scopes
669
+
659
670
if security :
660
671
method_definition ['security' ] = security
661
672
@@ -1100,6 +1111,19 @@ def gen_skeleton():
1100
1111
}
1101
1112
}
1102
1113
1114
+ @staticmethod
1115
+ def _get_authorization_scopes (authorizers , default_authorizer ):
1116
+ """
1117
+ Returns auth scopes for an authorizer if present
1118
+ :param authorizers: authorizer definitions
1119
+ :param default_authorizer: name of the default authorizer
1120
+ """
1121
+ if authorizers is not None :
1122
+ if authorizers .get (default_authorizer ) \
1123
+ and authorizers [default_authorizer ].get ("AuthorizationScopes" ) is not None :
1124
+ return authorizers [default_authorizer ].get ("AuthorizationScopes" )
1125
+ return []
1126
+
1103
1127
@staticmethod
1104
1128
def _normalize_method_name (method ):
1105
1129
"""
0 commit comments