node.js - 使用 AWS Amplify 对 Google 登录进行身份验证 - federatedSignin 返回 null?

标签 node.js amazon-web-services authentication amazon-cognito

我正在尝试使用 AWS Amplify 来支持电子邮件/密码和 Google 身份验证。现在,我想将来自 Google 的详细信息存储到我在 AWS 中的用户池中。我不明白这里的流程 - 我读了很多博客文章,但其中大部分都令人困惑。

这是我尝试做的:

// gapi and Amplify included
googleSigninCallback(googleUser => {
 const googleResponse = googleUser.getAuthResponse();
 const profile = googleUser.getBasicProfile();
 const name = profile.getName();
 const email = profile.getEmail();

 Amplify.Auth.federatedSignin('google', googleResponse, {email, name})
  .then(response => { console.log(response); }) // is always null
  .catch(err => console.log(err));
});

在 DevTools 中,网络选项卡中的请求出现以下错误:

{"__type":"NotAuthorizedException","message":"Unauthenticated access is not supported for this identity pool."}

为什么我应该启用对该池的未经身份验证的访问?我不想。

我这样做对吗?将 Google 用户详细信息存储到 AWS 用户池中甚至可能还是一种好的做法?如果这不是一个好的做法,那什么才是?

此外,如果我想向用户询问 Google 未在应用中提供的更多详细信息并存储它们,如果我们无法将用户存储在用户池中怎么办?

最佳答案

首先确保您的身份池和用户池设置为谷歌身份验证。

那么 federatedSignIn 的最后一个 I 是大写的。

最后只需更改对 federatedSignIn 的调用中的第二个参数,如下所示:

Amplify.Auth.federatedSignIn('google', {
  token: googleResponse.id_token,
  expires_at: googleResponse.expires_at
}, {email, name})...

关于node.js - 使用 AWS Amplify 对 Google 登录进行身份验证 - federatedSignin 返回 null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49473106/

相关文章:

javascript - Sequelize findOne 最新条目

javascript - 未定义的 var module.exports

amazon-web-services - AWS 为 ECS Auto Scaling 组中启动的实例创建标签

c++ - 如何验证进程?

javascript - 如何使用ajax和php登录用户?

node.js - 使用request和passport npm登录账号

node.js - 在 Heroku 上部署 Node.js 应用程序

node.js - Nodejs如何发布多个数组

amazon-web-services - 通过 CloudFront 的 S3 总是给我 AccessDenied 消息

python - 如何为我在 EC2 实例上的 Python 脚本正确/安全地从 AWS SSM 参数存储访问参数?