【问题标题】:Signing with temporary credentials for API gateway request problems使用临时凭证签名以解决 API 网关请求问题
【发布时间】:2016-09-03 02:54:31
【问题描述】:

我正在尝试使用经过身份验证的用户通过 REST API 调用我的 API 网关。为此,我正在使用:Cognito UserPool + Cognito Identity Pool + API Gateway + AWS_IAM Authorization + Cognito Credentials。根据我收集到的信息,我需要使用(临时凭据)签署我的请求。基于this thread,我想使用以下密钥签署我的请求:

{
 SecretKey: '', 
 AccesKeyId: '',
 SessionKey: ''
}

如果我使用 IAM 控制台中的关联用户并使用相应的 SecretKey + AccesKeyID,一切正常。但是,我想使用 我的身份池中的未验证和已验证角色来应用基于已验证或未验证用户的 IAM 策略。 仅供参考:我可以从 this part of the documentation. 调用经过身份验证的函数

我正在构建一个 React-Native 应用程序,因此我希望将原生 SDK 保持在最低限度,并且我只使用 AWSCognitoIdentityProvider 部分。供用户处理。

我尝试使用此 Objective-C 代码接收正确的密钥:

 [[self.credentialsProvider credentials] continueWithBlock:^id(AWSTask *task) {
    if (task.error) {
      NSLog(@"Error: %@", task.error);
    }
    else {
      AWSCredentials *response = task.result;

      NSString *accessKey = response.accessKey;
      NSString *secretKey = response.secretKey;
      NSString *sessionKey = response.sessionKey;
      NSDictionary *responseData = @{
                                     @"AccessKey" : accessKey,
                                     @"SecretKey" : secretKey,
                                     @"SessionKey": sessionKey
                                     };
        }

    return nil;
  }];

我使用relevant docs. 设置了其余部分

我(错误地?)尝试使用从 中检索到的
AccessKeySecretKeySessionKey 签署我的请求CredentialsProvider
上面。

  {
     SecretKey: credentials.SecretKey, 
     AccesKeyId: credentials.AccessKey,
     SessionKey: credentials.SessionKey
   }

签名失败并出现以下错误:

{ message: 'The security token included in the request is invalid.' }

所以我的问题是:我应该使用哪些密钥来签署我对经过身份验证的用户的请求,以便我可以从我的 Cognito 设置应用附加的 IAM 策略?

感谢您的帮助:)

【问题讨论】:

  • SessionKey?不是SessionToken?

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


【解决方案1】:

像 Michael - sqlbot,指出,它应该是 SessionToken 而不是 SessionKey。我在how to get credentials from Cognito 上找到了更好的说明。

【讨论】:

    猜你喜欢
    • 2016-04-27
    • 2021-10-30
    • 2018-01-22
    • 1970-01-01
    • 2014-08-23
    • 2015-02-07
    • 2023-04-07
    • 2017-12-17
    • 1970-01-01
    相关资源
    最近更新 更多