from uuid import uuid4 from authlib.oauth2 import OAuth2Error from authlib.oauth2.rfc6749 import errors from aws_lambda_powertools.event_handler.api_gateway import Router from oauth2 import authorization router = Router() @router.get('/authorize') def authorize(): user = { 'id': str(uuid4()), 'sub': 'sergio@somosbeta.com.br', } try: grant = authorization.get_consent_grant( request=router.current_event, end_user=user, ) except OAuth2Error as err: return dict(err.get_body()) try: return authorization.create_authorization_response( request=router.current_event, grant_user=user, grant=grant, ) except errors.OAuth2Error: return {}