我一直在寻找有关如何交换authorization_code以实用地从cognito获取访问令牌的解决方案。我创建了认知池和集成应用程序客户端。因此,当我以以下格式调用登录域时,我会获取登录页面并能够登录/注册
https://<your_domain>/login?response_type=code&client_id=<your_app_client_id>&redirect_uri=<your_callback_url>
Run Code Online (Sandbox Code Playgroud)
现在上面的url将返回authorization_code作为参数。我使用 post man 通过以下查询获取结果,该查询返回 id 令牌、访问令牌、刷新令牌。
POST https://mydomain.auth.us-east-1.amazoncognito.com/oauth2/token&
Content-Type='application/x-www-form-urlencoded'
grant_type=authorization_code&
client_id=myid&
code=AUTHORIZATION_CODE&
redirect_uri=http://localhost:5000/login
Run Code Online (Sandbox Code Playgroud)
现在我需要在我的应用程序中实现相同的方法来获取访问令牌下面是我尝试过的代码
response = requests.post(url + '/oauth2/token',
auth=(App_client_id),
data={'grant_type': grant_type, 'code': accessCode, 'client_id': App_client_id,
"redirect_uri":'http://localhost:5000/login'})
print(response.json())
Run Code Online (Sandbox Code Playgroud)
但我没有得到任何回应。
2.在我的应用程序 - Flask 应用程序中,我想以这样的方式放置一个逻辑:一旦用户在登录后通过用户池进行身份验证,它就会在redirect_uri中返回authorization_code。
感谢有人可以帮助解决这个问题吗?
谢谢