目前,我正在尝试使用 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。
提前致谢
最佳答案
可以在不显示托管 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/