AWS Cognito无法在CognitoIdentityCredentials上设置凭据

时间:2017-04-03 03:00:01

标签: amazon-web-services aws-sdk aws-cognito

我遇到了为AWS Cognito设置凭据的问题。

我在使用案例4中使用AWS amazon-cognito-identity-js下面的代码。

do.call(rbind, l)

我已经检查过我在AWS.config.credentials = new AWS.CognitoIdentityCredentials({ IdentityPoolId : '...', // your identity pool id here Logins : { // Change the key below according to the specific region your user pool is in. 'cognito-idp.<region>.amazonaws.com/<YOUR_USER_POOL_ID>' : result.getIdToken().getJwtToken() } }); 方法上发送了正确的IdentityPoolIdLogins但我在accessKeyId和sessionToken上未定义为返回。

以下是我得到的。 CognitoIdentityCredentials

知道如何解决这个问题吗?

3 个答案:

答案 0 :(得分:1)

之后你打电话给#AWS; AWS.config.credentials.get()&#39;为了确保凭据提供程序请求凭据?

答案 1 :(得分:1)

确保已设置 AWS.config.region

例如

AWS.config.region = 'us-east-1';

答案 2 :(得分:1)

new CognitoIdentityCredentitals()的结果分配给AWS.config.credentials实际上并没有获得凭证。它只是设置凭据提供程序。这就是为什么当您检查凭据时accessKeyId未定义并且expired设置为true的原因。

如果您随后致电AWS.config.credentials.get(),提供商将要求提供有效的凭据。

但是,还有一点要指出的是,您不必为了使用服务而调用AWS.config.credentials.get(),因为在建立服务时每个服务都会在后台调用AWS.config.credentials.get()

AWS.config.credentials = new AWS.CognitoIdentityCredentials({ ... });
console.log(AWS.config.credentials.expired); // false

/**
 *  The dynamoDB service will call AWS.config.credentials.get()
 *  under the hood when it is being set up,
 *  so you can immediately start using services like this.
*/
const dynamoDB = new AWS.DynamoDB();
console.log(AWS.config.credentials.expired); // true
相关问题