【问题标题】:API gateway how to pass AWS IAM authorization from rest clientAPI网关如何从REST客户端传递AWS IAM授权
【发布时间】:2015-12-26 07:19:56
【问题描述】:

我正在尝试从 REST 客户端测试经过身份验证的 API 网关端点。发出请求时如何生成/设置“AWS_IAM”授权标头?

【问题讨论】:

    标签: amazon-iam aws-api-gateway


    【解决方案1】:

    您必须复制 API Gateway AWS v4 request signature 逻辑才能做到这一点。理想情况下,您应该查看为您的 API 生成的 Javascript/Java SDK,以了解如何计算这些请求签名。我建议您为您的测试请求关闭身份验证。

    【讨论】:

      【解决方案2】:

      您可以将 Cognito 与“公共”池 ID 一起使用,然后将角色附加到 Cognito 池 ID,该角色正在访问您的 API GATEWAY

      AWS.config.credentials = new AWS.CognitoIdentityCredentials({
          IdentityPoolId: 'REGION:YOUR_POOL_ID',
      });
      

      使用 AWS STS 获取具有有限权限的临时凭证。之后,您可以将 API Gateway 与 AWS_IAM 身份验证一起使用

      生成的 SDK 接受 AMI 凭证,您必须使用从 STS 获得的凭证启动客户端:

      var apigClient = apigClientFactory.newClient({
          accessKey: 'ACCESS_KEY',
          secretKey: 'SECRET_KEY',
          sessionToken: 'SESSION_TOKEN', //OPTIONAL: If you are using temporary credentials you must include the session token
          region: 'eu-west-1' // OPTIONAL: The region where the API is deployed, by default this parameter is set to us-east-1
      });
      

      注意:在您的池中设置严格的最低角色,即公开可用的 id,每个人都可以使用它来获取临时或固定(跨设备跟踪用户)user_/app_ id。

      2016 年 4 月更新: 对于 Christine 的评论:Documentation 了解如何使用 STS。

      TL;DR:基本上在您的身份提供商给您回电(在我的情况下是谷歌)之后,您将拥有一个令牌(在我的情况下是 OpenID),只需将其提供给 STS:

      AWS.config.credentials = new AWS.WebIdentityCredentials({
        RoleArn: 'arn:aws:iam::<AWS_ACCOUNT_ID>:role/<WEB_IDENTITY_ROLE_NAME>',
        ProviderId: 'graph.facebook.com|www.amazon.com', // Omit this for Google
        WebIdentityToken: ACCESS_TOKEN
      });
      

      【讨论】:

      • 您能否举例说明如何“使用 AWS STS 获取具有有限权限的临时凭证”。在浏览器 JavaScript 中。我不知道如何让这一切与 Cognito Identities 一起工作。谢谢。
      猜你喜欢
      • 2021-09-23
      • 1970-01-01
      • 2018-09-06
      • 2022-01-18
      • 1970-01-01
      • 2021-04-13
      • 2018-07-28
      • 2014-09-05
      • 2017-10-18
      相关资源
      最近更新 更多