2015-06-14 40 views
2

当成功获得cognito身份后,我们再设法弄一本openIdToken()AWS Cognito:以身份访问被禁止调用getOpenIdToken()

AWS.config.credentials.get(function(err) { 
    if (!err) { 
     var cognitoIdentity = new AWS.CognitoIdentity(); 
     cognitoIdentity.getOpenIdToken({IdentityId: AWS.config.credentials.identityId}, function(err, data) { 
     if (err) console.log(err, err.stack); // an error occurred 
     else  console.log(data);   // successful response 
     }); 

    } else { 
     console.log('cognito error: ' + err); 
    } 
    }); 

但是这个失败:

"NotAuthorizedException: Access to Identity 'us-east-1:xxxxx' is forbidden. 

完整的错误跟踪:

POST https://cognito-identity.us-east-1.amazonaws.com/ 400 (Bad Request) 
    aws-sdk.min.js:5 [AWS cognitoidentity 400 0.192s 0 retries] getOpenIdToken({IdentityId: 'us-east-1:xxxxx' }) 
routing.html:64 Error: Access to Identity 'us-east-1:xxxxx' is forbidden. 
    at a (https://www.example.com/bower_components/aws-sdk-js/dist/aws-sdk.min.js:6:3548) 
    at r.SequentialExecutor.r.util.inherit.callListeners (https://www.example.com/bower_components/aws-sdk-js/dist/aws-sdk.min.js:6:28594) 
    at r.SequentialExecutor.r.util.inherit.emit (https://www.example.com/bower_components/aws-sdk-js/dist/aws-sdk.min.js:6:28390) 
    at a.Request.n.emitEvent (https://www.example.com/bower_components/aws-sdk-js/dist/aws-sdk.min.js:6:16483) 
    at u.setupStates.e (https://www.example.com/bower_components/aws-sdk-js/dist/aws-sdk.min.js:6:12946) 
    at r.runTo (https://www.example.com/bower_components/aws-sdk-js/dist/aws-sdk.min.js:7:25031) 
    at https://www.example.com/bower_components/aws-sdk-js/dist/aws-sdk.min.js:7:25238 
    at null.<anonymous> (https://www.example.com/bower_components/aws-sdk-js/dist/aws-sdk.min.js:6:12982) 
    at null.<anonymous> (https://www.example.com/bower_components/aws-sdk-js/dist/aws-sdk.min.js:6:16538) 
    at r.SequentialExecutor.r.util.inherit.callListeners (https://www.example.com/bower_components/aws-sdk-js/dist/aws-sdk.min.js:6:28607) "NotAuthorizedException: Access to Identity 'us-east-1:xxxxx' is forbidden. 
+0

能否请您提供一些详细信息,如您使用初始化AWS.config.credentials和你打电话之前credentials.get执行任何其他AWS或Cognito代码的代码? –

回答

1

此错误的两种最常见的原因是:

  • 您尚未在身份池配置中正确设置角色。
  • 您正试图获取身份验证身份的标记而不提供身份提供程序的标记。

请检查您的代码,以上两种情况,如果错误仍然存​​在,请PM我您身份ID/identityPoolId,我会很乐意深入挖掘。

感谢,
Rachit

+0

你有可能解释什么样的正确角色应该是什么样子?当我打电话给“刷新”时,我只会收到这个消息。 – CamHart

+0

您是否使用身份验证身份?如果是的话,你在登录地图中传递了什么? –

+0

是的,我。我传入:'logins.put(“accounts.google.com”,token);'从'GoogleSignInAccount account = result.getSignInAccount()中检索令牌。 String token = account.getIdToken();' – CamHart