【问题标题】:AWS Cognito can't set credentials on CognitoIdentityCredentialsAWS Cognito 无法在 CognitoIdentityCredentials 上设置凭证
【发布时间】:2017-08-27 19:18:23
【问题描述】:

我在为 AWS Cognito 设置凭证时遇到问题。

我在用例 4 上有来自 AWS amazon-cognito-identity-js 的以下代码。

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()
            }
        });

我检查了我在 CognitoIdentityCredentials 方法上发送的 IdentityPoolIdLogins 是否正确,但我在 accessKeyId 和 sessionToken 上得到未定义作为返回。

以下是我得到的。 CognitoIdentityCredentials {expired: true, expireTime: null, accessKeyId: undefined, sessionToken: undefined, params: Object…}

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

【问题讨论】:

  • 您解决了这个问题吗?我也有同样的问题。

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


【解决方案1】:

在此之后,您是否调用“AWS.config.credentials.get()”以确保凭据提供程序请求凭据?

【讨论】:

    【解决方案2】:

    确保您已设置 AWS.config.region

    例如

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

    【讨论】:

      【解决方案3】:

      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
      

      【讨论】:

      猜你喜欢
      • 2018-03-28
      • 2016-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-06
      • 2021-01-20
      • 2021-09-05
      • 2021-09-13
      相关资源
      最近更新 更多