我正在使用 openid 来登录用户。(仅限谷歌帐户)。现在我的页面中有一个注销链接,单击该链接后,我希望用户退出谷歌帐户并将页面重定向到我的主页。这可以做到吗?

编辑-
更改接受的答案,因为现在 Google 允许重定向[继续]到您想要的任何域。

有帮助吗?

解决方案

我已经解决了当用户单击注销链接时调用此函数的问题:

var logout = function(){
document.location.href = "https://www.google.com/accounts/Logout?continue=https://appengine.google.com/_ah/logout?continue=http://www.example.com";
}

当用户点击链接时,浏览器会将用户重定向到注销页面,并且只有当注销完成后,用户才会被重定向到该网站”http://www.example.com".

我希望这能有所帮助。

其他提示

<强>挑战

https://www.google.com/accounts/Logout 将记录用户退出。有一个continueUrl参数,谷歌有时会添加到该地址,但它才会成功,如果目标是一些谷歌的网站,而不是你自己的用户重定向。这使得该方法不可用。

此外OpenID规范不包括全球注销在这一时刻。

还有另一种方法:

<强>建议

在您的网页上的iframe中,使用的onClick JavaScript事件处理程序注销链接上加载的https: //www.google.com/accounts/Logout 到iframe中。在那之后(你可能要检查的IFrame是否成功加载),将用户重定向到一个注销程序自己的网站。退出后让该网页重定向到您的主页。

链接看起来有点像这样:

<a href="https://www.google.com/accounts/Logout"
    onclick="myIFrame.location='https://www.google.com/accounts/Logout';StartPollingForCompletion();return false;">
   log out</a>
<iframe id="myIFrame"></iframe>

您需要实现StartPollingForCompletion()功能定期检查注销页面是否已加载。使用setTimeout()时间投票,并为您的IFrame的一些属性(我不肯定知道哪些会工作,因为你的工作跨站点这里)。

还看到这些问题:

的OpenID。你怎么注销

如何注销功能添加到支持OpenID的网站?

我也一直在努力做同样的事情。仅适用于谷歌应用程序 -
要注销,请尝试以下两个选项:
1) 使用 i 框架 -

<iframe src="https://mail.google.com/a/YOURDOMAIN.IN/?logout&hl=en" width="100%" height="300">
  <p>Your browser does not support iframes.</p>
</iframe>

2) 使用 JavaScript -

<script type="text/javascript">
     window.open('https://mail.google.com/a/YOURDOMAIN.IN/?logout&hl=en','logout_from_google','width=600,height=300,menubar=no,status=no,location=no,toolbar=no,scrollbars=no,top=20,left=20');
</script>

由于我已经花了巨大的时间在这谷歌登录/注销问题我的应用程序(这是一个节点/ MongoDB的服务器,使用大量谷歌文档和谷歌API的脚本),我量曾在这里分享我的成果..

唯一的好办法完全注销用户是使用这样的:

 var newWindow = window.open('https://mail.google.com/mail/?logout&hl=fr','Disconnect from Google','width=100,height=50,menubar=no,status=no,location=no,toolbar=no,scrollbars=no,top=200,left=200');
setTimeout(function(){
    if (newWindow) newWindow.close();
    window.location="auth/google";
},3000);

如果使用以上的溶液,得到由IRA,它是这样做似乎为浏览器的当前标签中的局部注销。这意味着如果用户关闭的选项卡,然后重新打开应用程序,他将仍然记录到以前的帐户。

我,因为我无法从谷歌电子邮件帐户注销后正确地重定向到我的应用程序使用一个外部的窗口。此解决方案的时间最多,如果用户的带宽是不是太慢了,让3秒注销关闭弹出窗口前正在做。然后用户被要求登录在我的主窗口的应用程序的另一个帐户。

此确认floccinaucinihilipilification的溶液,也许上面给出的iframe解决方案应该比我的好。

我刚刚做同样的,注销用户。不知何故接受的答案不为我工作,我从谷歌得到了一个错误

The page you requested is invalid.

所以我最终把这个在我的网页:

<img src="https://www.google.com/accounts/Logout" />

成功地注销用户。

下面是我做什么,不记得,如果我做起来还是发现它的地方......它就像一个魅力......比其他的事实,它注销你出所有谷歌网站的(我可以”不敢相信他们没有提供一个适当的方式做到这一点,但你去那里。)

<script>
function makeFrame(domId,url) { 
    ifrm = document.createElement("IFRAME"); 
    ifrm.setAttribute("src", url);
    ifrm.setAttribute("id", domId);
    ifrm.setAttribute("style", "display:none;");         
    ifrm.style.width = 1+"px"; 
    ifrm.style.height = 1+"px"; 
    document.body.appendChild(ifrm); 
} 

function logOutGoogle(){
    makeFrame('googleLogoutIFrame','https://www.google.com/accounts/Logout');
}
$(window).ready(function() {
    logOutGoogle();
});
</script>

我不知道,如果我做的事情是正确的。但我设法使用这样的代码:

<a class="btn btn-default navbar-btn text-white" id="signOut" href="../home.html" onclick="signOut('https://www.google.com/accounts/Logout');">Sign out</a>
    <script>
      function signOut() {
        var auth2 = gapi.auth2.getAuthInstance();
        auth2.signOut().then(function () {
          console.log('User signed out.');
        });
      }
      firebase.auth().signOut().then(function() {
        // Sign-out successful.
        alert('You have Signed Out. Please Sign In');
      }).catch(function(error) {
        // An error happened.
        alert('An error happened');
      });
    </script>

我使用此代码从谷歌帐户注销。它会抛出一个错误,但不要担心,它会立即错误发生的直接到你的应用程序的服务器端signout路线后重定向。

<a href="https://www.google.com/accounts/Logout" target="myiframe">logout</a>
<iframe name="myiframe" style="display:none" onload="redirect()"></iframe>

<script>
  function redirect() {
    window.location = 'http://your.site.com/signout';
  };
</script>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top