【问题标题】:How to get identity pool Id for a user in nodejs如何在nodejs中获取用户的身份池ID
【发布时间】:2017-01-22 15:53:59
【问题描述】:

我正在尝试在 cognito 中获取用户的身份池 ID。

我拥有所需的所有凭据(用户名、密码)以及我的客户端 ID、池 ID 和身份池 ID。

我可以使用以下代码在浏览器中执行此操作:

AWS.config.credentials.get(function(err, resp) {
                    if (err) {
                        console.log('get creds error', err);
                        alert('get creds error' + err);
                    } else {
                        console.log('get creds success', AWS.config.credentials);

                        // Credentials will be available when this function is called.
                        accessKeyId = AWS.config.credentials.accessKeyId;
                        secretAccessKey = AWS.config.credentials.secretAccessKey;
                        sessionToken = AWS.config.credentials.sessionToken;

                        console.log("in creds.get - accessKeyId: " + accessKeyId);
                        console.log("in creds.get - secretyKey: " + secretAccessKey);
                        console.log("in creds.get - sessionToken: " + sessionToken);
                        // get this Id and push to array
                        console.log('UserID: ', AWS.config.credentials.params.IdentityId);
                        users_identity[username] = AWS.config.credentials.params.IdentityId;
                        cognitoUser.signOut();
                    }
                });

,但是当我尝试为多个用户获取它时,我只能为一个用户获取它。当我打电话时,对方的身份池 ID 显示不正确

  console.log('UserID: ', AWS.config.credentials.params.IdentityId);

是否可以在 nodejs 中做到这一点?

【问题讨论】:

    标签: node.js amazon-web-services amazon-dynamodb amazon-cognito


    【解决方案1】:

    您打印的是身份ID,而不是身份池ID。身份 ID 是 Cognito 为每个用户提供的唯一标识符。我不知道 javascript SDK 中的身份池 id 有任何 getter,但是这是您在凭据初始化时配置的输入值。您应该可以保持该值可访问并在需要时使用它。

    【讨论】:

      猜你喜欢
      • 2021-12-31
      • 2016-10-08
      • 2020-07-01
      • 2018-05-18
      • 2020-04-21
      • 2020-02-16
      • 1970-01-01
      • 2022-01-18
      • 1970-01-01
      相关资源
      最近更新 更多