Cognito - 用户池应用程序集成和联合 - ¿如何刷新 id_token?

Cognito - User Pools App Integration and Federation - ¿How refresh id_token?

我正在使用 AWS Cognito 的一项新功能,它是一个与用户池集成的应用程序,有关更多详细信息,请参阅 https://github.com/aws/amazon-cognito-auth-js。这里有一个例子,在这个例子中我可以得到 id 令牌,访问令牌但是刷新令牌是空的。

我查看了 Amazon Congito 中的文档 --> Amazon Cognito API 参考 --> Amazon Cognito Auth API 参考 --> AUTHORIZATION 端点

"The Amazon Cognito authorization server redirects back to your app with access token. Since openid scope was not requested, an ID token is not returned. A refresh token is never returned in this flow. Token and state are returned in the fragment and not in the query string".

"The authorization server redirects back to your app with access token and ID token (because openid scope was included)."

注意:这里没有说刷新令牌,但是它的响应这个端点是

"https://YOUR_APP/redirect_ur#id_token=ID_TOKEN&access_token=ACCESS_TOKEN&token_type=bearer&expires_in=3600&state=STATE"

那我不知道怎么刷新我的id_token使用一个多小时? (whit openid 范围)

有两个认证流程

  • 隐式流程:仅向 tokenId 发送访问令牌
  • 授权flow:At首先你会得到一个代码,你可以用它来交换三元组令牌(TokenId、访问令牌和刷新令牌)

我正在使用隐式流,为此我无法获得刷新令牌。在示例中,在 index.html 文件中,有一行 "auth.useCodeGrantFlow();" 如果您取消注释该行,您将切换隐式流 --> 授权流。 此时有一个拉取请求,因为此流程中存在错误。有关更多详细信息 enter link description here(拉取请求 #32)

我已更改 dist/amazon-cognito-auth.js 文件以获取拉取请求中的同一文件,它工作正常

注意:在没有 Secret 的 Cognito 用户池中配置您的应用程序很重要,因为如果您不这样做,就会出现 "invalid_client" 错误。这是因为 sdk 不考虑 header "Authorization" 什么时候 post 到 /oauth/token 端点在 Auth 授权流

这个问答中有很多内容。我会说对我来说,切换到没有密钥的用户池 成功了。