【问题标题】:What to do with the token from AWS cognito如何处理来自 AWS cognito 的令牌
【发布时间】:2020-10-17 12:30:11
【问题描述】:

这个想法是使用 AWS Cognito 和 Google Login 作为联合实体来执行登录/身份验证 + 自动化。

一切都在客户端使用 AWS javascript SDK 完成。

我可以使用https://.auth.eu-central-1.amazoncognito.com/oauth2/authorize?identity_provider=Google&redirect_uri=https://&response_type=token&client_id=<Client_id> 登录。我将我重定向到我的网站并在 URL 中添加 access_token。我可以使用 CognitoIdentityCredentials 函数取回 AWS 访问权限和密钥。

问题:

  1. 如何处理这个 access_token
  2. 我需要调用哪个函数来获取当前用户?
  3. 我需要access_keysecret_key吗?

【问题讨论】:

  • 看来你混淆了很多点。请再次查看有关 Cognito Userpool 和 Cognito Identity 的文档。
  • 我听取了您的建议,看来我不需要身份部分。但我不明白如何使用令牌。我正在使用 API Gateway sdk

标签: javascript authentication amazon-cognito google-signin


【解决方案1】:

好吧,看来我有点糊涂了……

使用 Cognito 登录时,URL 中有两个 JWT 令牌(这部分很重要):

  1. access_token
  2. id_token

在调用 API Gateway 授权请求时,必须在 Authorization 标头中发送 id_token。如果您使用 AWS Amplify SDK,则会自动设置标头。

当我设法实现从登录/注册到 API 网关请求的完整流程时,我将添加更多信息。

旁注:当我在线阅读所有代码片段(Github、Medium 等)时,我感到很困惑,他们在登录部分后都使用 Cognito 身份池。

【讨论】:

    猜你喜欢
    • 2016-05-19
    • 2019-11-16
    • 2018-03-23
    • 2015-09-19
    • 2023-03-25
    • 2023-03-16
    • 2018-07-30
    • 2020-11-01
    • 2019-10-16
    相关资源
    最近更新 更多