我正在跟进谷歌的指南 https://developers.google.com/identity/sign-in/web/sign-in#sign_out_a_user注销用户。
考虑到gapi.auth2
刷新页面后将是未定义的,我正在做:
if (gapi.auth2) {
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut();
} else {
gapi.load('auth2', function () {
gapi.auth2.init({
client_id: 'myAppID',
cookiepolicy: 'single_host_origin'
}).signOut();
});
}
但我得到uncaught exception: This method can only be invoked after the token manager is started
在 else 块中。
我还尝试将身份验证实例存储在本地存储中,但这样做会导致在对其进行字符串化时出现一些循环对象值错误。
一个可能的解决方案是做一个
document.location.href = "https://www.google.com/accounts/Logout?continue=https://appengine.google.com/_ah/logout?continue=myUrl";
但是,这不仅会影响用户登录的所有 Google 服务,而且还会进行不需要的重定向,而不是仅将用户从我的应用程序中注销。
有不同的方法吗?
有一个更简单的方法,你只需在调用gapi.auth2.init后调用.then
gapi.load('auth2', function () {
var auth2 = gapi.auth2.init({
client_id: 'myAppID',
cookiepolicy: 'single_host_origin'
});
auth2.then(function(){
// this get called right after token manager is started
auth2.signOut();
});
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)