sherlock
sherlock

Reputation: 2807

How to purge chrome.identity cache?

I am developing a Chrome plugin that uses chrome.identity API. There are two distinct flows, one for authenticated users and another for non-authenticated ones. During testing, the problem I'm facing is, if I authenticate the user calling getAuthToken() and then disconnect the connected app from Google account, the plugin still takes the authenticated flow, because I believe chrome.identity framework caches the authentication token. I need to actually wait for some time for getAuthToken() to "realize" that the authentication has been revoked and then the authentication dialog pops up. Is there any way to forcefully purge the chrome.identity cache?

Upvotes: 0

Views: 1598

Answers (1)

Iván Nokonoko
Iván Nokonoko

Reputation: 5118

You could use chrome.identity.removeCachedAuthToken. According to documentation:

Removes an OAuth2 access token from the Identity API's token cache.

You have to pass the token you want removed in the first argument, so if you acquired a token with:

var myToken;
chrome.identity.getAuthToken({interactive:true}, function(token){
    if (token) myToken = token;
});

You then use:

chrome.identity.removeCachedAuthToken({token:myToken},function(){
    //token was removed from cache
});

Upvotes: 2

Related Questions