amazon-web-services - 如何为 AWS Cognito 用户生成访问 token ?

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

我使用 Cognito 用户池来保护我的 API 网关。现在我想使用 postman 向我的 API 发出请求,但我需要传入授权 token ,因为 API 是安全的。是否有任何 AWS CLI 命令或 REST API 来生成身份验证 token (通过传递用户名/密码)?我搜索了文档,但找不到任何示例。谢谢你的帮助。

最佳答案

您可以使用以下 CLI 命令执行此操作:

注册用户
aws cognito-idp sign-up --region {your-aws-region} --client-id {your-client-id} --username admin@example.com --password password123
确认用户注册
aws cognito-idp admin-confirm-sign-up --region {your-aws-region} --user-pool-id {your-user-pool-id} --username admin@example.com
验证(获取 token )
aws cognito-idp admin-initiate-auth --region {your-aws-region} --cli-input-json file://auth.json
auth.json 在哪里:

{
    "UserPoolId": "{your-user-pool-id}",
    "ClientId": "{your-client-id}",
    "AuthFlow": "ADMIN_NO_SRP_AUTH",
    "AuthParameters": {
        "USERNAME": "admin@example.com",
        "PASSWORD": "password123"
    }
}

如果一切设置正确,您应该得到这样的响应:
{
    "AuthenticationResult": {
        "ExpiresIn": 3600,
        "IdToken": "{your-idtoken}",
        "RefreshToken": "{your-refresh-token}",
        "TokenType": "Bearer",
        "AccessToken": "{your-access-token}"
    },
    "ChallengeParameters": {}
}

关于amazon-web-services - 如何为 AWS Cognito 用户生成访问 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49063292/

相关文章:

amazon-web-services - AWS Oracle RDS 实例需要花费大量时间来创建(约 2 小时)

vue.js - 无法使用 Vue 和 Axios 查询 AWS API

amazon-web-services - 如何在速度模板中添加生成随机 UUID 等功能,用于 API 网关中的请求/响应映射

oauth - AWS API Gateway - 将访问 token 与 Cognito 用户池授权方一起使用?

node.js - Cognito - 检查 idToken 的有效性

aws-lambda - 如何动态地将 arn cognito 添加到 lambda?

amazon-web-services - AWS Cloudformation 输出 ElastiCacheCluster

amazon-web-services - AWS ECS Fargate 未创建任务 AmazonECSTaskExecutionRole 错误

python - 无法在 AWS Rest API 请求中使用 "Filter"

amazon-web-services - AWS lambda : Passing data from custom authorizer to business lambda