amazon-web-services - 如何接收通过 AWS Amplify 中的身份提供商登录的用户的属性?

标签 amazon-web-services oauth-2.0 amazon-cognito aws-amplify

我想允许我的用户使用 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/

相关文章:

Azure 机器人与经过身份验证的消息传递端点交互

c# - Google Oauth 2.0 redirect_uri_mismatch - 端口在回调时更改

python - 谷歌云端点: Picturesque App

python - 在 Python 中的 API 网关请求中使用 AWS Cognito 访问 token

ios - 如何支持使用 aws cognito 登录苹果?

amazon-web-services - AWS Cloudwatch 指标显示与 redis-cli 不同的当前连接数

image - 为什么要使用 Imgur 或 Amazon S3 之类的服务进行图像托管?

amazon-web-services - 使用 secret 管理器的 AWS lambda 函数

amazon-web-services - AWS-CLI : Create RDS Aurora DB instance into existing cluster created from snapshot

amazon-web-services - AWS Cognito - 使用 Cloud Formation 创建池 - 预期支持的属性返回为不受支持