我也为此苦苦挣扎,但最终我发现这个解决方案隐藏在 Chrome App Samples 中。https://github.com/GoogleChrome/chrome-app-samples/blob/master/gapi-chrome-apps-lib/gapi-chrome-apps.js
removeCachedAuthToken 在本地删除它,但要从 Google 服务器撤销令牌,您需要发送请求,因此第二部分:xhr.open('GET', ' https://accounts.google.com/o/oauth2/revoke?令牌= '+当前令牌);
尝试这个:
function revokeToken() {
chrome.identity.getAuthToken({ 'interactive': false },
function(current_token) {
if (!chrome.runtime.lastError) {
// @corecode_begin removeAndRevokeAuthToken
// @corecode_begin removeCachedAuthToken
// Remove the local cached token
chrome.identity.removeCachedAuthToken({ token: current_token },
function() {});
// @corecode_end removeCachedAuthToken
// Make a request to revoke token in the server
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://accounts.google.com/o/oauth2/revoke?token=' +
current_token);
xhr.send();
// @corecode_end removeAndRevokeAuthToken
// Update the user interface accordingly
$('#revoke').get(0).disabled = true;
console.log('Token revoked and removed from cache. '+
'Check chrome://identity-internals to confirm.');
}
});
}