微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决无法使用 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.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?