您可以使用 AWS Cognito 的增强身份验证 (Enhanced Authentication) 功能来解决当前验证用户不显示名称属性的问题。以下是一个示例代码,演示如何使用 AWS SDK for JavaScript 来实现这一点:
// 导入 AWS SDK for JavaScript
const AWS = require('aws-sdk');
// 配置 AWS SDK
AWS.config.update({ region: 'your_region' });
// 创建 CognitoIdentityServiceProvider 对象
const cognitoIdentityServiceProvider = new AWS.CognitoIdentityServiceProvider();
// 定义要查询的用户池和用户的信息
const userPoolId = 'your_user_pool_id';
const username = 'your_username';
// 定义要获取的用户属性
const attributesToGet = [];
// 获取用户的属性
cognitoIdentityServiceProvider.adminGetUser({
UserPoolId: userPoolId,
Username: username,
UserAttributes: attributesToGet
}, (err, data) => {
if (err) {
console.error(err);
} else {
// 用户属性将包含在 data.UserAttributes 数组中
console.log('User attributes:', data.UserAttributes);
}
});
在上述代码中,您需要将 'your_region' 替换为您实际使用的 AWS 区域,'your_user_pool_id' 替换为您的用户池 ID,以及 'your_username' 替换为您要查询的用户的用户名。
注意,您需要使用具有足够权限的 AWS 身份验证凭据来运行此代码,以便可以访问 Cognito 用户池的相关操作。
希望这可以帮助到您!