【问题标题】:How can I get UserPool details by IdentityPool/UserPool id (sub)如何通过身份池/用户池 ID(子)获取用户池详细信息
【发布时间】:2021-12-31 17:18:57
【问题描述】:

如果我拥有使用 AWS SDK 的用户的 IdentityPool 或 UserPool ID(子),是否有办法获取用户详细信息(配置文件属性等)?

用例是我将用户提交的一些信息保存在数据库中,其密钥等于用户 ID(子)。因此,当我从数据库中读取它时,我想从我的池中为我的应用 UI 恢复一些用户信息。

我发现了一个类似的问题 (Getting cognito user pool username from cognito identity pool identityId),但似乎给出的答案集中在无服务器部署上,并且仍然存在一些差距。

提前致谢

【问题讨论】:

    标签: aws-sdk amazon-cognito aws-sdk-js


    【解决方案1】:

    我想我找到了解决办法,实际上是在表面上。

    拥有用户池 ID 1 可以使用 ListUsers 调用和过滤器 sub = \"${userId}\"。要使用的客户端是CognitoIdentityProviderClient,如果使用JS的话。

        const client = new CognitoIdentityProviderClient({
            region: REGION,
            credentials: fromCognitoIdentityPool({
                client: new CognitoIdentityClient({ region: REGION }),
                logins: {
                    [PROVIDER_ID]: token
                },
                identityPoolId: ID_POOL_ID
            })
        });
    
        const filter = `sub = \"${userPoolId}\"`;
    
        const resp = await client.send(new ListUsersCommand({
            UserPoolId: USER_POOL_ID,
            Filter: filter,
            Limit: 1
        }));
    

    当然也可以使用 AdminGetUser,就像上面提到的 Ulas Keles,如果它适用的话

    【讨论】:

      【解决方案2】:

      既然你有用户的sub,你可以使用AdminGetUser。它返回池中的UserAttributes

      【讨论】:

        猜你喜欢
        • 2018-05-18
        • 2020-10-07
        • 2020-04-21
        • 2017-01-22
        • 1970-01-01
        • 2021-05-23
        • 2021-06-08
        • 2016-10-20
        • 2018-07-17
        相关资源
        最近更新 更多