2015-07-20 39 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

相關問題