gapi.auth.signOut(); not working I'm lost

前端 未结 3 1519
無奈伤痛
無奈伤痛 2020-12-03 03:56

Below is the code I am using to login with google. I have an element on login.php with id authorize-button. When clicked it logs in just fine.

I have a logout li

相关标签:
3条回答
  • 2020-12-03 04:15

    Weird issue, but solved my problem by rendering the signin button (hidden) even if the user is authenticated.

    See full question/answer here https://stackoverflow.com/a/19356354/353985

    0 讨论(0)
  • 2020-12-03 04:27

    Make sure you have set your cookie-policy to a value other than none in your sign-in button code. For example:

    function handleAuthClick(event) {
      gapi.auth.authorize(
        {
          client_id: clientId, 
          scope: scopes, 
          immediate: false, 
          cookie_policy: 'single_host_origin'
        },
        handleAuthResult);
      return false;
    }
    

    Note that sign out will not work if you are running from localhost.

    0 讨论(0)
  • 2020-12-03 04:29

    I came across the same issue today. I have search for solution the whole. The only reliable solution that worked for me is through revoke as explained here

    I stored access_token in session which is needed during revoke

    Below is my code you may find it useful

          function logout() {
             var access_token = $('#<%=accessTok.ClientID %>').val();
             var provider = $('#<%=provider.ClientID %>').val();
        if (access_token && provider) {
            if (provider == 'GPLUS') {
                var revokeUrl = 'https://accounts.google.com/o/oauth2/revoke?token=' +
                    access_token;
    
                // Perform an asynchronous GET request.
                $.ajax({
                    type: 'GET',
                    url: revokeUrl,
                    async: false,
                    contentType: "application/json",
                    dataType: 'jsonp',
                    success: function (nullResponse) {
                        // Do something now that user is disconnected
                        // The response is always undefined.
                    },
                    error: function (e) {
                        // Handle the error
                        // console.log(e);
                        // You could point users to manually disconnect if unsuccessful
                        // https://plus.google.com/apps
                    }
                });
            }
            else if (provider == 'FB') {
                FB.getLoginStatus(function (response) {
                    if (response.status === 'connected') {
                        FB.logout();
                    }
                });
            }
        } else {
    
        }
    }
    
    0 讨论(0)
提交回复
热议问题