Search code examples
google-chromegoogle-chrome-extensionoauthgoogle-oauthgmail-api

How to explicitly request dialog to show up when getting auth token in chrome extension?


I'm making an Chrome Extension for gmail, and when I run this snippet of code for first time,everything is fine, dialog shows up and asks user which account to use and token gets stored and I can use the gmail API from my extension:

var access_token = "";
chrome.identity.getAuthToken({ 'interactive': true },
        function(token) {
            if (!!token) {
                access_token = token;
                gapi.auth.setToken({ access_token: token });                 
            }
        }
    );

but when I remove the token with this snippet of code:

chrome.identity.removeCachedAuthToken({ token: access_token }, function() {
            console.log('token removed');                
        });

and I want to get token again using the first snippet, it updates the token itself, without showing dialog to user to choose which account to use. How can I force it to show dialog?


Solution

  • As confirmed in the comments, you need to revoke the token to completely remove the stored credentials.

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