javascript - Google 使用自定义登录表单登录 Cognito

标签 javascript node.js reactjs amazon-cognito aws-amplify

目前,我正在尝试使用 Cognito Aws 服务 为我的 Web 应用程序实现社交登录。但我不想将用户重定向到 Cognito Hosted UI 以进行社交登录。

所以我使用react-google-login对于 Google 登录,我也获得了回调访问 token

<GoogleLogin
   clientId="xxxxxxxxxxxxxx.apps.googleusercontent.com"
   buttonText="Login"
   onSuccess={this.responseGoogle}
   onFailure={this.responseGoogleFailure}
   cookiePolicy={'single_host_origin'}
/>


responseGoogle = async (response) => {
  console.log("response..........", response);
  const user = {
    name: response.profileObj.name,
    email: response.profileObj.email
  };

  let expires_at = 3600 * 1000 + new Date().getTime()

  Auth.federatedSignIn('google', { token: response.tokenId, expires_at }, user).then(credentials => {
     console.log(credentials);
  });
}

上述代码提供了 Cognito session 值,但并未在用户池中创建用户。

我搜索了很多,但没有找到任何解决方案。我已经在下面提到了这个链接,它指的是我的问题。基本上我不想为 SocialLogin 使用托管 UI。

提前致谢

https://github.com/aws-amplify/amplify-js/issues/1316

https://github.com/aws-amplify/amplify-js/issues/3875

最佳答案

可以在不显示托管 ui 的情况下直接打开指向 Google 登录页面的链接,但仍然需要通过 Cognito 进行身份验证,您基本上直接链接到在 Cognito 托管中选择 Google 按钮时打开的 url用户界面即

https://<YOUR_DOMAIN>.auth.<REGION>.amazoncognito.com/oauth2/authorize?identity_provider=Google&redirect_uri=<REDIRECT_URI>&response_type=TOKEN&client_id=<CLIENT_ID>&scope=openid

在身份验证之后,您将最终返回到您的重定向 uri,并且用户将被创建/验证。

关于javascript - Google 使用自定义登录表单登录 Cognito,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58778539/

相关文章:

javascript - Jquery 检索具有相同节点的 XML 数据

javascript - 在javascript中删除文件

node.js - 使用 Typescript 在 Node 中将 Sequelize 模型作为属性传递

reactjs - 在 React select 中使用枚举

javascript - 使用 Javascript 中的 HTML 特殊字符从头到脚序列化 iframe 的内容

javascript - 将 CSS 应用于 IFrame 时出现跨浏览器问题

javascript - 在 Console.log 和 api 响应中获取未定义的外键

node.js - 关注智威汤逊安全

javascript - 如何将键盘监听器添加到我的 onClick 处理程序?

javascript - 使用 lodash 的推拉来替代收集复选框值