2015-07-20 86 views
2

我得到使用来自亚马逊开放ID令牌兑换从cognito访问密钥无效使用错误的凭据

这里凭据Invalid access key错误是我在做什么

  1. 找开发商确认打开ID令牌

    cognito.getOpenIdTokenForDeveloperIdentity(参数,可以函数(ERR,数据){

    Ø penIdToken = data.credentials });

  2. 为安全证书兑换开放ID标记,我将params设置为congnito Auth角色并设置任意角色会话名称。我使用步骤1中的令牌没有地方,我设置的身份ID从步骤1

    it('should be able to exchange temporary open id token for auth credentials', function (done) { 
    
        var sts = new AWS.STS(); 
        var params = { 
         RoleArn: roleArn, 
         RoleSessionName: 'photo-upload-session', 
         WebIdentityToken: openIdToken.Token 
        }; 
        sts.assumeRoleWithWebIdentity(params, function(err, data) { 
         should.not.exist(err); 
    
         should.exist(data.Credentials.AccessKeyId); 
         should.exist(data.Credentials.SecretAccessKey); 
         should.exist(data.Credentials.SessionToken); 
         credentials = data.Credentials; 
    
         done(); 
        }); 
    
    
    }); 
    
  3. 我更新当前凭据

    AWS.config.update({accessKeyId : credentials.AccessKeyId, secretAccessKey:credentials.SecretAccessKey});

  4. 我将文件上传到s3并得到[InvalidAccessKeyId: The AWS Access Key Id you provided does not exist in our records.]错误

*编辑使用Bob Kinney的建议我尝试了两种方法 - 设置sessionTo肯(工作),并使用Congito证书给TypeError不是缓冲区错误。 CognitoIdentityCredentials示例如下。

AWS.config.credentials = new AWS.CognitoIdentityCredentials({ 
     IdentityPoolId:config.get('aws_identity_pool_id'), 
     Logins: { 
     'cognito-identity.amazonaws.com': openIdToken.Token 
     } 
    }); 

    var body = fs.createReadStream(__dirname + '/test_photo.jpg'); 

    var s3obj = new AWS.S3({params: {Bucket: 'test-uploads', Key: 'test'}}); 

    s3obj.upload({Body: body}). 
     on('httpUploadProgress', function(evt) { console.log(evt); }). 
     send(function(err, data) { 
      should.not.exist(err); 
      done(); 

     }); 

**更新

所以移动回Java客户端错误,我们使用的是OpenID的令牌(该测试将与sts.assumeRoleWithWebIdentity正常工作),并通过该令牌为扩展的AWSAbstractCognitoIdentityProvider(此链接http://docs.aws.amazon.com/cognito/devguide/identity/developer-authenticated-identities/采取代码) - 然后使用该身份上传到S3收到错误

CustomAwsIdentityProvider provider = CustomAwsIdentityProvider.newInstance(this, BuildConfig.AWS_COGNITO_POOL_ID, Regions.US_EAST_1); 

CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(this, provider, Regions.US_EAST_1); 

TransferManager tm = new TransferManager(credentialsProvider); 
tm.upload("my-upload", uuid.toString(), file); 
+0

您能否包括您用于每个步骤的完整代码?请确保您查看http://docs.aws.amazon.com/cognito/devguide/identity/concepts/authentication-flow/上的“开发者身份验证身份验证”。这说明了对Cognito的每次呼叫以及呼叫是来自设备还是来自您的后端服务器。 –

+0

确定更新了步骤2的示例 – MonkeyBonkey

+0

您确定您的政策授予读/写权限吗? – f1lt3r

回答

2

对不起,我的问题。看起来您正在使用JavaScript SDK。使用此流程时,可以使用developer guide中提到的标准AWS.CognitoIdentityCredentials对象,使用cognito-identity.amazonaws.com的密钥和该值作为从getOpenIdTokenForDeveloperIdentity调用返回的OpenId Connect令牌。

您所看到的错误的原因是您没有从STS结果中包含sessionToken。使用AWS.CognitoIdentityCredentials对象应该解决这个问题。

更新2015年7月21日:存在这样会防止不幸从AWS.CognitoIdentityCredentials工作作为我描述它的SDK一个小问题。我们正在努力缓解这个问题。

更新2015年7月24日:您应该可以使用以下方法来使用AWS.CognitoIdentityCredentials与开发者认证identiity:

AWS.config.credentials = new AWS.CognitoIdentityCredentials({ 
    IdentityPoolId: 'MY_IDENTITY_POOL', 
    IdentityId: data.IdentityId, 
    Logins: { 
    'cognito-identity.amazonaws.com': data.Token 
    } 
}); 

如果数据是从GetOpenIdTokenForDeveloperIdentity响应。

+0

我会以同样的方式使用congitocredentials对象以及android和ios mobile sdks吗? – MonkeyBonkey

+0

@MonkeyBonkey,不,请参阅我们的[端到端示例](https://mobile.awsblog.com/post/Tx3E3NJURV1LNV1/Integrating-Amazon-Cognito-using-developer-authenticated-identities-An-end )在iOS和Android上使用开发人员身份验证身份的示例。 –

+0

给了我这个错误Uncived AssertionError:expected [TypeError:not a buffer] to not exist at _stream_readable.js:908:16当我打电话给s3上传这个证书 – MonkeyBonkey

相关问题