2017-12-03 11 views
0

content.jsを示していないChrome.identity.getAuthTokenこれはChromeの拡張機能のためのコンテンツページでGoogleユーザーリストに

document.getElementById("signIn").addEventListener("click", function(){ 
chrome.runtime.sendMessage({task:"switchUser", user: current_user},function(response){      
    }); 
}); 

background.jsこれはChromeの拡張機能のための背景ページで

chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse){ 
    if(request.task == "switchUser"){ 
    function getToken(){ 
     chrome.identity.getAuthToken({ interactive: true }, function(token) { 
     sendResponse(token); 
     }); 
    } 
     chrome.identity.removeCachedAuthToken({ token: 
     currentSessionAccessToken }, getToken); 
    } 
    return true; 
}); 

Previous OAuthトークンは正常に削除されましたが、getAuthTokenを使用して新しいトークンを生成すると、ユーザー選択リストは表示されません。しかし、私はインタラクティブに設定しました。私は何が欠けていますか?

答えて

0

トークンを最初に取り消してからキャッシュから削除する必要があります。 background.jsページの下にあるコードを見つけてください。

chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse){ 
if(request.task == "switchUser"){ 
function getToken(){ 
    chrome.identity.getAuthToken({ interactive: true }, function(token) { 
     sendResponse(token); 
     }); 
    } 
     var xmlHttp = new XMLHttpRequest(); 
     xmlHttp.open('GET', 'https://accounts.google.com/o/oauth2/revoke?token=' + currentSessionAccessToken); //revoke the token calling this url. 
     xmlHttp.onload = function() { 
     chrome.identity.removeCachedAuthToken({ token: currentSessionAccessToken }, getToken); //after token is revoked, remove it from cache as well. 
    } 
     xmlHttp.onerror = function(){    
     }; 
     xmlHttp.send(); 
    } 
    return true; 
}); 
関連する問題