Google+Signin使用GoogleJava脚本客户端库



我正在使用在我的应用程序中进行googlre登录

gapi.auth.authorize({
client_id : clientId,
scope : scopes,
immediate : true
}, handleAuthResult);

我能够授权用户,然后我给出了一个链接,使用这个api 来识别用户

gapi.auth.signOut();

它也会注销用户,但当我刷新页面时,它不会要求再次登录。它是直接加载用户帐户,我想让它要求用户再次登录。有人能告诉我怎么做吗?

如果您在localhost上运行,则注销将不起作用。

你所做的对我来说很好。也许你在handleAuthResult方法中遗漏了一个正在注销的用户的检查。发生这种情况的原因可能是,即使用户未登录,回调方法也会被触发。要检查此情况,在更改用户的登录状态之前,您应该确保在回调中获得访问令牌。一些代码也将帮助初始化Google+JavaScript API客户端:

handleAuthResult: function(authResult) {
gapi.client.load('plus','v1', function(){
$('#authResult').html('Auth Result:<br/>');
for (var field in authResult) {
$('#authResult').append(' ' + field + ': ' +
authResult[field] + '<br/>');
}
if (authResult['access_token']) {
$('#authOps').show('slow');
$('#gConnect').hide();
helper.profile();
helper.people();
} else if (authResult['error']) {
// There was an error, which means the user is not signed in.
// As an example, you can handle by writing to the console:
console.log('There was an error: ' + authResult['error']);
$('#authResult').append('Logged out');
$('#authOps').hide('slow');
$('#gConnect').show();
}
console.log('authResult', authResult);
});
},

你可以在这里看到演示代码。如果您打开浏览器的JavaScript控制台,当用户注销时,您会注意到以下错误消息:

authResult 
...
Object {error: "user_signed_out", 
cookie_policy: "single_host_origin"
error: "user_signed_out"
expires_at: "1388530488"
expires_in: "86400"
g-oauth-window: undefined
g_user_cookie_policy: "single_host_origin"
issued_at: "1388444088"
response_type: "code token id_token gsession"
scope: "https://www.googleapis.com/auth/plus.login 
session_state: "707059cda8acedf0acf31d83c713e9f16f232610..25c4"
status: Object
google_logged_in: true
method: null
signed_in: false
...

如果用户自动/重复注销网站,很可能是由于cookie存储已损坏的已知问题。如果您看到此问题,请在隐姓埋名窗口中打开目标页面或删除当前cookie,例如在开发人员控制台中运行以下javascript:

var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];
var eqPos = cookie.indexOf("=");
var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
}

我尝试了@class answer,它仍然不能与signOut()一起使用,当我们调用gap.auth.authorize时没有错误。但我找到了另一种方法,尝试访问链接https://accounts.google.com/o/oauth2/revoke?token=authResult['access_token'],这会让你喜欢注销,用户需要重新接受身份验证。尽管我现在有点困惑,我们应该用哪种方式来注销();

最新更新