【问题标题】:Using AWS Cognito Id Token from generated UI in a website (vue.js) to authenticate HTTP Requests to AWS Gateway使用网站 (vue.js) 中生成的 UI 中的 AWS Cognito Id 令牌对 AWS 网关的 HTTP 请求进行身份验证
【发布时间】:2020-06-12 23:24:22
【问题描述】:

我在 AWS API 网关中有一个带有 cognito 用户池授权方的 API。目前我们已经通过移动应用程序推出了它,他们使用 cognito SDK 创建了自己的身份验证流程。

我想使用他们自动生成的 UI 并获取 #id_token 来验证我正在创建的网站中的用户。

但是,我对周围的所有文档都感到有些困惑,似乎没有一篇关于使用适用于 JS 的 AWS SDK 或适用于 JS 的 aws-amplify-sdk 使用 #id-Token 启动用户会话。

生成的 UI 吐出这个 http://localhost:8080/#id_token=uyiuiubii-huge-Token-goes-here&expires_in=3600&token_type=Bearer

我想获取该 id_token 值以登录并在 cognito 中启动会话。

然后要求 id_token 的会话管理器使用标准 http 客户端(例如 Ajax 调用或 axios)向在 API 网关中使用 cognito 保护的端点发出 http 请求,手动将令牌添加到标头中。

感谢任何帮助。

【问题讨论】:

    标签: javascript authentication amazon-cognito


    【解决方案1】:

    the Amplify header customization docs 呢?具体来说:

    当使用custom authorizer 时,您可以使用 Authentication API 提供的 JWT 令牌直接针对 API Gateway 进行身份验证。您可以通过从 (await Auth.currentSession()).getIdToken().getJwtToken() 检索 JWT 令牌来实现此目的

    注意the Cognito JWT referenced by the docs is the id_token returned in the URL by a successful Cognito User Pool auth

    【讨论】:

      【解决方案2】:

      如果您使用的是他们在此处提到的 API REST 服务

      https://docs.amplify.aws/lib/restapi/authz/q/platform/js#request-headers

      我同意您如何从自定义身份验证 UI 和您可以从中获得的 JWT 到将其传递给这些其他 API 客户端的方式令人困惑......

      “withAuthenticator”的反应似乎以某种方式神奇地做到了,但如果不使用它,它会令人困惑。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-06-23
        • 2019-02-04
        • 2016-04-11
        • 2019-03-25
        • 1970-01-01
        • 2016-06-25
        • 2017-10-29
        • 2018-03-14
        相关资源
        最近更新 更多