AWS Cognito身份验证令牌如何刷新

时间:2020-05-14 00:00:06

标签: amazon-web-services amazon-cognito

我对Amazon Cognito并不了解。如果JWT令牌只能使用一个小时,那么它们需要刷新,但是我的应用程序应该怎么做?这是怎么发生的?您是否只是请求新令牌,它会记住您所在的会话?另外,您是否在状态中存储JWT令牌?我不明白这一点,如果有人可以提供帮助,我将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:1)

在请求令牌时,如果grant_type是authorization_code,则令牌端点将返回refresh_token

示例:

HTTP/1.1 200 OK
Content-Type: application/json

{
 "access_token":"eyJz9sdfsdfsdfsd",
 "refresh_token":"dn43ud8uj32nk2je",
 "id_token":"dmcxd329ujdmkemkd349r",
 "token_type":"Bearer", 
 "expires_in":3600
}

然后,您可以在令牌端点交换刷新令牌以获取另一个令牌

POST https://mydomain.auth.us-east-1.amazoncognito.com/oauth2/token >
Content-Type='application/x-www-form-urlencoded'
Authorization=Basic aSdxd892iujendek328uedj

grant_type=refresh_token&
client_id=djc98u3jiedmi283eu928&
refresh_token=REFRESH_TOKEN

Additional documentation can be found here