javascript出错后如何重置Google OAuth2?

问题描述

我已在组织内设置登录我的应用程序,该应用程序运行良好,因为从其他帐户登录时会提示错误错误 403:org_internal”。但问题是它登录到了 chrome,从下一次我尝试登录它时,它只是提示相同的错误而不要求提供凭据。

我曾尝试调用 signOut() 方法,但它似乎不起作用。

如何重置 OAuth2 实例,以便在出现任何错误时要求提供凭据?

解析谷歌身份验证的初始化函数

googleAuth = gapi.auth2.init({
                client_id: ****,scope: 'https://www.googleapis.com/auth/classroom.rosters.readonly https://www.googleapis.com/auth/classroom.profile.emails https://www.googleapis.com/auth/classroom.profile.photos https://www.googleapis.com/auth/classroom.rosters'
            });

登录谷歌:

initClient().then(function (googleAuth) {
            $scope.googleAuth = googleAuth
            return googleAuth.signIn();
}

错误

enter image description here

解决方法

您的错误信息

客户仅限于其组织内的用户。

表示在 Google 开发者控制台中创建客户端时,此应用已设置为内部。

enter image description here

内部应用只能由 Google WorkSpace 域中的用户访问,使用其他用户登录或将您的项目设置为外部。

如何注销用户

至于注销用户以下内容应该会有所帮助

<a href="#" onclick="signOut();">Sign out</a>
<script>
  function signOut() {
    var auth2 = gapi.auth2.getAuthInstance();
    auth2.signOut().then(function () {
      console.log('User signed out.');
    });
  }
</script>

无耻地从sign_out_a_user中撕下代码