I use AWS Cognito with the hosted UI, I have Lambda callback (called by AWS) that exchange received code to tokens. It works, but sometimes in logs I see that event looks like this:
{'code': '', 'state': '305598223734340355033510307010'}
Maybe some problem with auth through the Google, Amazon or Facebook... I do not know how can I check something.
Part of my auth_cognito.py:
payload = {
'grant_type': 'authorization_code',
'client_id': client_id,
'code': event['code'],
'redirect_uri': url_redirect
}
tryis = 3
tokens: typing.Dict[str, str] = {}
while 'id_token' not in tokens and tryis > 0:
# Retry for case when resp == {'error': 'Internal Error'}; TODO use SDK?
tryis -= 1
tokens = botocore.vendored.requests.post(
url='https://intelligentspeaker.auth.us-east-1.amazoncognito.com/oauth2/token',
headers={'Content-Type': 'application/x-www-form-urlencoded'},
data=payload).json()
try:
id_token_gwt = _get_payload_json(tokens['id_token'])
except KeyError:
print(f'ERROR: KeyError - no `id_token` in this json: {tokens}', file=sys.stderr)