无法使用 gapi.auth2.getAuthInstance().signOut() 注销

问题描述

我正在尝试按照此处给出的说明为我的 Web 应用程序实现 google 登录https://developers.google.com/identity/sign-in/web/sign-in

我的Html页面如下:

<html lang="en">
  <head>
    <Meta name="google-signin-scope" content="profile email">
    <Meta name="google-signin-client_id" content="xdydycdskeldlsldlkkekdd.apps.googleusercontent.com">
<script src="https://apis.google.com/js/platform.js" async defer></script></head>
  <body>
    <div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark"></div>
    <a href="#" onclick="signOut();">Sign out</a>
<script>
    

  function signOut() {
    var auth2 = gapi.auth2.getAuthInstance();
    alert(auth2);
    
    auth2.signOut().then(function () {
      console.log('User signed out.');
      alert('User signed out.');
    });
  }
</script>

    <script>
      function onSignIn(googleUser) {
        // Useful data for your client-side scripts:

        var profile = googleUser.getBasicProfile();
        alert(profile);
        console.log("ID: " + profile.getId()); // Don't send this directly to your server!
        console.log('Full Name: ' + profile.getName());
        console.log('Given Name: ' + profile.getGivenname());
        console.log('Family Name: ' + profile.getFamilyName());
        console.log("Image URL: " + profile.getimageUrl());
        console.log("Email: " + profile.getEmail());

        // The ID token you need to pass to your backend:
        var id_token = googleUser.getAuthResponse().id_token;
        
   }
    </script>
  </body>
</html>

登录有效,我收到一个 gmail 弹出窗口,我输入凭据并登录。但是当我点击退出时,它根据警报将消息显示'用户退出',但是如果我再次点击登录按钮,它会在没有任何提示的情况下签名我设置的密码或 2 因素身份验证。谁能解释为什么会发生这种情况?另外,如果我连续点击退出,它每次都会给出'用户退出'的消息,有人可以帮我吗?谢谢

enter image description here

在其他浏览器(不包括 chrome)中,如 firefox,我在登录按钮点击时没有从 javascript 功能收到任何警报?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...