【问题标题】:Sign AWS requests using Cognito Your User Pool user using Postman使用 Cognito 签署 AWS 请求 您的用户池用户使用 Postman
【发布时间】:2016-12-18 05:54:24
【问题描述】:

我正在尝试向 AWS API Gateway 发送经过身份验证的请求。客户端将针对 Cognito 您的用户池进行身份验证,然后从与用户池中已登录用户对应的关联 Cognito 身份池获取令牌。我正在尝试使用 Postman 模拟这样的请求。

This post 建议可以使用命令aws cognito-identity get-credentials-for-identity 来获取 Postman 签署请求所需的 AccessKeyId 和 SecretKey。但是,当我尝试使用 Cognito 用户池控制台中的用户使用 sub 属性运行它时:

$ aws cognito-identity get-credentials-for-identity --identity-id aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee

An error occurred (ValidationException) when calling the GetCredentialsForIdentity operation: 1 validation error detected: Value 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' at 'identityId' failed to satisfy constraint: Member must satisfy regular expression pattern: [\w-]+:[0-9a-f-]+

$ aws cognito-identity get-credentials-for-identity --identity-id us-east-1:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee

An error occurred (ResourceNotFoundException) when calling the GetCredentialsForIdentity operation: Identity 'us-east-1:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' not found.

如果我尝试使用 AWS 控制台中显示的关联身份池中的身份 ID(我选择了一个具有 2 个“链接登录”的身份 ID),也会发生同样的事情。

【问题讨论】:

    标签: amazon-web-services postman amazon-iam amazon-cognito aws-api-gateway


    【解决方案1】:

    您需要传递登录地图:

    --logins (map)
    A  set  of  optional  name-value  pairs  that  map provider names to
    provider tokens.
    
    Shorthand Syntax:
    
        KeyName1=string,KeyName2=string
    
    JSON Syntax:
    
        {"string": "string"
            ...}
    

    这个语法对我有用:

    aws cognito-identity get-credentials-for-identity \
        --identity-id us-east-1:aaaa-bbb-ccc-bc54-rrrrrrr \
        --logins graph.facebook.com=kdajbdjkabkjbkjbkdbsckslcjxb
    

    注意:--identity-id 不是身份池 id,它是来自身份浏览器的身份。

    【讨论】:

      【解决方案2】:

      API 网关现在与“Cognito Your User Pool”进行原生集成,因此您可以直接传递身份令牌 - api gateway docs。您链接的帖子已过时

      【讨论】:

      • 它本身并没有过时,因为它对于我们正在使用的 IAM 身份验证仍然有效,并且 IAM 身份验证仍然用于社交登录(Facebook 等)
      • 这个答案更接近我的问题 - 如何以编程方式从邮递员或 shell 获取 JWT,以便邮递员/新人将其放入身份验证标头。
      猜你喜欢
      • 2019-05-18
      • 2021-09-05
      • 2018-03-25
      • 1970-01-01
      • 2023-03-09
      • 2020-06-14
      • 2017-04-19
      • 2018-01-31
      • 2018-11-07
      相关资源
      最近更新 更多