我想在我的站点中实现 Google 登录,就像在 Stack Exchange、Stack Overflow 等。 这意味着当用户选择使用 Google 身份验证登录时,网站会重定向到一个页面,用户可以在该页面上选择要使用的 Google 帐户,而无需打开新窗口/标签并重定向到该网站 你能帮我提供链接/文档吗? 不要打开新标签页/窗口非常重要。
我正在使用这个:https://developers.google.com/identity/sign-in/web/build-button
你可以看到当你点击按钮时会打开一个新窗口,我想阻止这种情况。
提前致谢
最佳答案
您可以尝试切换到 JavaScript 客户端身份验证并将 ux_mode 选项传递给 signIn() 函数选项。
ux_mode: "redirect"
文档在这里: https://developers.google.com/identity/sign-in/web/reference#googleauthsigninoptions
然后你可以像这样获取用户配置文件:
let googleUser = window.gapi.auth2.getAuthInstance().currentUser.get();
if (googleUser) {
let profile = googleUser.getBasicProfile();
if (profile) {
this.state.google.firstname = profile.getGivenName();
this.state.google.lastname = profile.getFamilyName();
this.state.google.email = profile.getEmail();
}
}
这一切都记录在这里和那里: https://developers.google.com/identity/sign-in/web/people
关于javascript - 在不打开新窗口/标签的情况下使用谷歌身份验证登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37838397/