我想允许我的用户使用 AWS Cognito 通过身份提供商登录。
import { Auth } from 'aws-amplify';
...
Auth.federatedSignIn({ provider: "Google" })};
这实际上工作正常。用户登录后,该用户还会在 AWS 控制台的用户池中列出具有所需属性的用户 - 因此属性映射似乎也有效。
但是,当用户通过联合登录时在我的前端调用 Auth.currentAuthenticatedUser()
时,返回的对象不包含用户属性 -此属性不知何故丢失。
import { Auth } from 'aws-amplify';
...
const user = await Auth.currentAuthenticatedUser();
const { attributes } = user;
console.log('current attributes:', attributes);
返回 => 当前属性:undefined
相同的方法会返回未使用联合服务的用户的属性。
current attributes:
{
email: ...
given_name ...
}
我怎样才能让 Cognito 也为通过身份提供者登录的用户返回属性,以便我,例如可以显示用户的全名吗?
最佳答案
我试图通过使用 flutter amplify 包在 flutter 项目中获取用户属性,这是访问所有属性的方法:
var res = await Amplify.Auth.fetchUserAttributes();
for (int i = 0; i < res.length; i++) {
print("${res[i].userAttributeKey} :: ${res[i].value}");
}
🍻!
关于amazon-web-services - 如何接收通过 AWS Amplify 中的身份提供商登录的用户的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64140762/