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

标签 javascript google-signin google-authentication google-oauth

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

相关文章:

javascript - 在 Firefox 中, Protractor 在移动到下一个 block 之前不会等待页面加载

azure - 如何强制使用 Azure 帐户选择器

javascript - 定义对象时方括号有什么用?

javascript - new File() 给了我 JavaScript NodeJS 中未定义的文件

javascript - SDK 2 : Example of a settings dialog

spring-boot - Spring Boot 社交登录和 Google Calendar API

mobile - 不确定我是否应该遵循谷歌登录文档

firebase - Flutter Google 登录数据保存到 Firebase Cloud Firestore

google-api - Google Console 重定向 URI 中的子域

java - 代码 :12500, 消息:12500 未以任何方式解决