gpt4 book ai didi

javascript - 在不打开新窗口/标签的情况下使用谷歌身份验证登录

转载 作者:数据小太阳 更新时间:2023-10-29 05:35:20 25 4
gpt4 key购买 nike

我想在我的站点中实现 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com