amazon-web-services - 使用 API 网关测试 Cognito 用户池身份验证

标签 amazon-web-services aws-api-gateway amazon-cognito

我希望我的客户端应用程序使用受 Cognito 用户池保护的 API 网关在我的 dynamoDb 实例中插入记录。

我已创建用户池并将其作为授权者添加到我的 API 网关方法调用中。使用 AWS Cli,我运行了以下命令,该命令为我提供了访问 token :

aws cognito-idp 发起身份验证 ...

我的基础设施似乎正在运行,现在我需要朝哪个方向实际实现以用户池中的用户身份登录、获取 token 并调用我的 API 方法?

最佳答案

嗯,这并不难。您需要遵循某些步骤。

  1. 在 Cognito 用户池中创建用户。通过您选择的激活消息进行确认。根据用户池设置,它可以是短信或电子邮件。

  2. 确认用户后,您需要从 Cognito SDK 调用登录 API。由于我对 NodeJS 很熟悉,所以让我获取方法名称 - https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_InitiateAuth.html 。将 AuthFLow 设置为 ADMIN_NO_SRP_AUTH 。此 APi 的响应将具有 1 个 idToken、1 个 accessToken 和 1 个刷新 token 。由于您的客户端需要这些凭据,因此请使用您的首选语言编写 API,将其公开给您的客户端并返回 token 。

  3. 使用 idToken 对您的 API Gateway 授权方进行 API 调用。这是使用 Postman 传递 token 的方式 -

enter image description here

您可以使用任何客户端复制相同的内容。如果您遇到任何错误,最好向我展示您的 APIG 授权者配置。

关于amazon-web-services - 使用 API 网关测试 Cognito 用户池身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60818188/

相关文章:

amazon-web-services - API 网关 : Mixing of REST APIs and HTTP APIs on the same domain name can only be accomplished through API Gateway's V2 DomainName interface error

aws-api-gateway - 尝试通过 Cloudformation 创建 AWS API 网关时出现错误

amazon-web-services - Terraform 不同步

android - 亚马逊服务异常 : User is not authorized to perform: dynamodb:DescribeTable Status Code: 400; Error Code: AccessDeniedException

amazon-web-services - 谷歌应用程序脚本 : Getting Orders from Amazon Selling Partner API (Signing Requests)

Tomcat 在 AWS ELB 上重启

amazon-web-services - 将HTTP://请求重定向到AWS API Gateway上的https://(使用自定义域)

amazon-web-services - AWS API Gateway token 测试响应代码 : 401

java - DynamoDB 用户管理的用户组

amazon-web-services - 是否有 Amazon.com API 来检索产品评论?