首页 文章

使用API网关请求问题的临时凭证进行签名

提问于
浏览
0

我'm trying to invoke my API Gateway with authenticated users with the REST API. For this I' m使用:Cognito UserPool + Cognito Identity Pool + API Gateway + AWS_IAM Authorization + Cognito Credentials . 根据我收集的内容,我需要用(临时凭证)签署我的请求 . 基于this thread我想用以下键签署我的请求:

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

如果我使用IAM控制台中的关联用户并使用相应的SecretKey AccesKeyID,一切正常 . 但是,我想使用 Unauthenticated and Authenticated roles from my Identity Pools 根据经过身份验证或未经身份验证的用户应用IAM策略 . 仅供参考:我可以从this part of the documentation.调用经过身份验证的功能

我'm building a React-Native app, and because of that I want to keep the native SDK to a minimum and I'只使用了 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.进行设置

我(错误地?)试图用我的请求签名
从上面的CredentialsProvider检索的AccessKey,SecretKey,SessionKey .

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

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

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

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

谢谢你的帮助 :)

1 回答

  • 0

    像迈克尔 - sqlbot,指出,它应该是 SessionToken 而不是 SessionKey . 我在how to get credentials from Cognito找到了更好的指令 .

相关问题