Google使用api javascript / jquery注销 [英] Google logout using api javascript/jquery

查看:150
本文介绍了Google使用api javascript / jquery注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Web应用程序中,我允许用户使用API​​客户端库中的auth命令登录,但我找不到Google API JavaScript客户端库的注销选项。

In my web application, I allow users to login using the auth command in the API Client Library but I cannot find a Logout option for the Google API JavaScript Client Library.

任何人都可以建议我怎样才能注销我的应用程序以及谷歌账户?

Can any one suggest how can i Logout of my application as well as google account??

我的登录代码是:

var OAUTHURL = 'https://accounts.google.com/o/oauth2/auth?';
var VALIDURL = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=';
var SCOPE = 'https://www.googleapis.com/auth/userinfo.profile';
var CLIENTID = googleAPI;
var REDIRECT = redirectUrl;
var TYPE = 'token';
var _url = OAUTHURL + 'scope=' + SCOPE + '&client_id=' + CLIENTID + '&redirect_uri=' + REDIRECT + '&response_type=' + TYPE;
var acToken;
var tokenType;
var expiresIn;
var user;
$('#googleLogin').click(function(){
        var win = window.open(_url, "windowname1", 'width=800, height=600');

        var pollTimer = window.setInterval(function () {
            if (win.document.URL.indexOf(REDIRECT) != -1) {
                window.clearInterval(pollTimer);
                var url = win.document.URL;
                acToken = gup(url, 'access_token');
                tokenType = gup(url, 'token_type');
                expiresIn = gup(url, 'expires_in');
                win.close();

                validateToken(acToken);
            }
        }, 100);
});
function validateToken(token) {
        $.ajax({
            url: VALIDURL + token,
            data: null,
            success: function (responseText) {
                getUserInfo();
            },
            dataType: "jsonp"
        });
}


推荐答案

他们的Google帐户退出您的应用程序时。这种行为对于用户来说是意想不到的,令人讨厌。

Do not log your users out of their Google Account when they sign out of your application. This behavior is unexpected and annoying to users.

您最多应该试图弄清楚如何注销应用程序的用户。 (我把它放在引号中,因为取决于你的实现,应用程序可能会伪装它)。

You should, at most, be trying to figure out how to "log out" users of your application. (I put it in quotes, because depending on your implementation, the app might be faking it).

如果你只关心在UI中隐藏元素,你可以设置一个变量,例如 signedIn ,并在用户点击登录/注销按钮时设置或取消设置。如果您关心在会话中保持此状态,请使用存储相同值的cookie。

If you care only about hiding elements in the UI, you can set a variable, e.g. signedIn, and set or unset it when the user hits a login/logout button. If you care about persisting this state across sessions, use a cookie that stores the same value.

如果您想确保键盘另一侧的人是确实是登录用户,您可以在授权调用中使用 max_auth_age 参数。如果您将它设置为 0 ,用户需要在您的应用获取有效令牌之前使用Google重新进行身份验证。如果将它与自动会话到期(如您在银行或健康网站上看到的)相配,您可以对当前用户的身份相对自信。

If you want to make sure the person on the other side of the keyboard is really the signed in user, you can use the max_auth_age parameter on the authorize call. If you set it to 0, users will need to re-authenticate with Google before your app gets a valid token. If you pair this with an automatic session expiration (like you'd see on a bank or health website), you can be relatively confident of the identity of the current user.

这篇关于Google使用api javascript / jquery注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆