我得到使用來自亞馬遜開放ID令牌兌換從cognito訪問密鑰無效使用錯誤的憑據
這裏憑據Invalid access key
錯誤是我在做什麼
找開發商確認打開ID令牌
cognito.getOpenIdTokenForDeveloperIdentity(參數,可以函數(ERR,數據){
Ø penIdToken = data.credentials });
爲安全證書兌換開放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(); }); });
我更新當前憑據
AWS.config.update({accessKeyId : credentials.AccessKeyId, secretAccessKey:credentials.SecretAccessKey});
我將文件上傳到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);
您能否包括您用於每個步驟的完整代碼?請確保您查看http://docs.aws.amazon.com/cognito/devguide/identity/concepts/authentication-flow/上的「開發者身份驗證身份驗證」。這說明了對Cognito的每次呼叫以及呼叫是來自設備還是來自您的後端服務器。 –
確定更新了步驟2的示例 – MonkeyBonkey
您確定您的政策授予讀/寫權限嗎? – f1lt3r