Google OAuth断开连接,但是GoogleOuth.isSignedIn.get()= true?

问题描述 投票:0回答:2

这是我的代码:

function googleLogOut(){

debugAlert("googleLogOut:Begin");

GoogleAuth.disconnect();
GoogleAuth.signOut().then(function () {
    debugAlert("googleLogOut:Logout Completed, current login status = " + GoogleAuth.isSignedIn.get());
    userNotLoggedIn();
    debugAlert("googleLogOut:Exit");
});

}

根据我的理解,断开连接撤销当前登录用户授予我的应用程序的授权,signOut应该将用户从他的Google帐户中注销,基本上支持用户最初经过的OAuth签名,以便获得访问我的应用程序。

但是,在GoogleAuth.signOut()之后,GoogleAuth.isSignedIn.get()的评估结果为true - 请参阅警告对话框图片:

Alert Dialog

javascript google-oauth2 google-authentication
2个回答
0
投票

实际上,事实证明,用户仍然登录到他的Google帐户,因此技术上isSignIn.get()返回正确的值。我通过打开一个新的浏览器选项卡并转到gmail来确认这一点 - 显然我仍然登录。但更重要的是,此代码所做的是撤销用户授予我的应用程序的所有权限 - 这是本质这个注销功能。为了测试这个 -

GoogleAuth.currentUser.get()。hasGrantedScopes(SCOPE)== false

因此,Google帐户是否已登录到我的应用程序的复合测试是:

GoogleAuth.isSignedIn.get()== true && GoogleAuth.currentUser.get()。hasGrantedScopes(SCOPE)== true

这是修改后的注销功能。 (功能相同,只是修改了调试语句以显示范围权限的撤销。)

function googleLogOut(){

debugAlert("googleLogOut:Begin");

GoogleAuth.disconnect();
GoogleAuth.signOut().then(function () {
    debugAlert("googleLogOut:Logout Completed, current login status = " + GoogleAuth.isSignedIn.get());
    if (GoogleAuth.isSignedIn.get()) {
        debugAlert("googleLogOut:Logout Completed, current SCOPE status = " + GoogleAuth.currentUser.get().hasGrantedScopes(SCOPE));
    }
    userNotLoggedIn();
    debugAlert("googleLogOut:Exit");
});

}


0
投票

这是一种完全不同的方法。我发现这更可靠。

logoutWindow = window.open(“https://accounts.google.com/SignOutOptions”,“_ blank”,“toolbar = no,width = 600,height = 400”);

我只需打开Goog​​le帐户管理页面的窗口。当用户退出时,他们也会从我的应用程序中退出。

作为锦上添花,当我在我的应用程序中捕获用户注销事件时,我关闭窗口 - 如果用户通过我的应用程序调用的窗口注销:

try {
    logoutWindow.close();
}
catch (err) {
    // nothing...
}

0
投票

使用GoogleAuth.isSignedIn.listen(listener) - 当您的监听器被调用时,GoogleAuth对象的状态已经更新。

© www.soinside.com 2019 - 2024. All rights reserved.