我将AWS Cognito与托管UI一起使用,我将Lambda回调(由AWS调用)收到的交换收到code令牌.它工作,但有时在日志中我看到event如下所示:
{'code': '', 'state': '305598223734340355033510307010'}
Run Code Online (Sandbox Code Playgroud)
也许通过谷歌,亚马逊或Facebook认证有些问题...我不知道如何检查一些东西.
我的一部分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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
169 次 |
| 最近记录: |