javascript - Can't signOut of Google OAuth2 -


i not able use google signout() sign me out of oauth session signed into.

as example, have pasted below code taken directly google quick start site... https://developers.google.com/google-apps/calendar/quickstart/js

i have saved 1.htm file on website , attempting drive google api.

when use oauth 2.0 client id (not shown in attached code) api console, able login , see calendar events. however, when sign out button clicked, don't logged out.

enter image description here

right after clicking sign out, following code running sure...

enter image description here

but then, doesn't sign me out. running console, see still thinks logged in... enter image description here

i listening changes status on signin our signout... enter image description here

but callback never hit signout()... enter image description here

finally, if try entire thing developer console...

  1. shows gapi.auth2 says logged in
  2. manual sign out command
  3. shows gapi.auth2 says still logged in enter image description here

how can code modified make signout() work?

<!doctype html> <html> <head>     <title>google calendar api quickstart</title>     <meta charset='utf-8' /> </head> <body>  <p>google calendar api quickstart</p>  <!--add buttons initiate auth sequence , sign out--> <button id="authorize-button" style="display: none;">authorize</button> <button id="signout-button" style="display: none;">sign out</button>  <pre id="content"></pre>  <script type="text/javascript">     // client id , api key developer console     var client_id = 'my oauth client id';      // array of api discovery doc urls apis used quickstart     var discovery_docs = ["https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest"];      // authorization scopes required api; multiple scopes can     // included, separated spaces.     var scopes = "https://www.googleapis.com/auth/calendar";      var authorizebutton = document.getelementbyid('authorize-button');     var signoutbutton = document.getelementbyid('signout-button');      /**      *  on load, called load auth2 library , api client library.      */     function handleclientload() {         gapi.load('client:auth2', initclient);     }      /**      *  initializes api client library , sets sign-in state      *  listeners.      */     function initclient() {         gapi.client.init({             discoverydocs: discovery_docs,             clientid: client_id,             scope: scopes         }).then(function () {             // listen sign-in state changes.             gapi.auth2.getauthinstance().issignedin.listen(updatesigninstatus);              // handle initial sign-in state.             updatesigninstatus(gapi.auth2.getauthinstance().issignedin.get());             authorizebutton.onclick = handleauthclick;             signoutbutton.onclick = handlesignoutclick;         });     }      /**      *  called when signed in status changes, update ui      *  appropriately. after sign-in, api called.      */     function updatesigninstatus(issignedin) {         if (issignedin) {             authorizebutton.style.display = 'none';             signoutbutton.style.display = 'block';             listupcomingevents();         } else {             authorizebutton.style.display = 'block';             signoutbutton.style.display = 'none';         }     }      /**      *  sign in user upon button click.      */     function handleauthclick(event) {         gapi.auth2.getauthinstance().signin();     }      /**      *  sign out user upon button click.      */     function handlesignoutclick(event) {         gapi.auth2.getauthinstance().signout();     }      /**      * append pre element body containing given message      * text node. used display results of api call.      *      * @param {string} message text placed in pre element.      */     function appendpre(message) {         var pre = document.getelementbyid('content');         var textcontent = document.createtextnode(message + '\n');         pre.appendchild(textcontent);     }      /**      * print summary , start datetime/date of next ten events in      * authorized user's calendar. if no events found      * appropriate message printed.      */     function listupcomingevents() {         gapi.client.calendar.events.list({             'calendarid': 'primary',             'timemin': (new date()).toisostring(),             'showdeleted': false,             'singleevents': true,             'maxresults': 10,             'orderby': 'starttime'         }).then(function (response) {             var events = response.result.items;             appendpre('upcoming events:');              if (events.length > 0) {                 (i = 0; < events.length; i++) {                     var event = events[i];                     var when = event.start.datetime;                     if (!when) {                         when = event.start.date;                     }                     appendpre(event.summary + ' (' + when + ')')                 }             } else {                 appendpre('no upcoming events found.');             }         });     }  </script>  <script async defer src="https://apis.google.com/js/api.js"         onload="this.onload=function(){};handleclientload()"         onreadystatechange="if (this.readystate === 'complete') this.onload()"> </script> 

try using revoking token http/rest method:

to programmatically revoke token, application makes request https://accounts.google.com/o/oauth2/revoke , includes token parameter:

curl -h "content-type:application/x-www-form-urlencoded" \         https://accounts.google.com/o/oauth2/revoke?token={token} 

the token can access token or refresh token. if token access token , has corresponding refresh token, refresh token revoked.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -