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

当前,我正在尝试使用 Cognito Aws服务为我的Web应用程序实现社交登录。但是我不想将用户重定向到用于社交登录的Cognito 托管用户界面

因此,我将react-google-login用作Google登录名,并且也获得了回调访问令牌

<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会话值,但是并没有在用户池中创建用户。

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

预先感谢

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

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

xuan2901 回答:使用自定义登录表单登录Google Cognito

可以直接打开指向Google登录页面的链接,而无需显示托管的用户界面,但仍通过Cognito进行身份验证,基本上可以直接链接到在托管的Cognito中选择Google按钮时打开的网址。 ui ie

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,并已创建/验证了用户。

本文链接:https://www.f2er.com/3133196.html

大家都在问