Scopes can also be used with custom authorizers and built-in authorizers. These authorizers will need to inspect the access token to determine if access should be granted based on the scopes configured for the authorizer and route.
from chalice import Blueprint
extra_routes = Blueprint(__name__)
@extra_routes.authorizer()
def demo_auth(auth_request):
token = auth_request.token
# we can decode token in this part, and get scope that sets in token payload,
# then how to get scopes from authorizer that sets in route using with_scopes.
if token == 'allow':
return AuthResponse(routes=['/'], principal_id='user')
else:
return AuthResponse(routes=[], principal_id='user')
@extra_routes.route('/', methods=['GET'], authorizer=demo_auth.with_scopes(["author", "editor"]))
def index():
return {'context': app.current_request.context}
According to Doc, it said