0

我正嘗試使用我的Chrome網絡應用程序向github進行身份驗證。Github Oauth使用Chrome網絡應用程序問題

當我點擊按鈕,我得到的回調,我在控制檯中得到這個錯誤。

運行identity.launchWebAuthFlow時未經檢查的runtime.lastError: 用戶未批准訪問。

popup.js

var githubButton = document.getElementById('github'); 
githubButton.addEventListener('click', function() { 
    var CLIENT_ID = "da1d7c12a3ab20decba5"; 
    var CALLBACK_URL = chrome.identity.getRedirectURL("oauth2"); 
    var AUTH_URL = 'https://github.com/login/oauth/authorize/?client_id='+CLIENT_ID+'&redirect_uri='+CALLBACK_URL+'&scope=notifications'; 
    // Opens a window to initiate GitHub OAuth, fires callback 
    // with token in the URL. 
    chrome.identity.launchWebAuthFlow({ 
     url: AUTH_URL, 
     interactive: true, 
    }, function(redirectURL) { 
     var q = redirectURL.substr(redirectURL.indexOf('#')+1); 
     var parts = q.split('&'); 
     for (var i = 0; i < parts.length; i++) { 
      var kv = parts[i].split('='); 
      if (kv[0] == 'access_token') { 
       token = kv[1]; 
       console.log('token is', token); 
      } 
     } 
    }); 
}, false); 

的manifest.json

"permissions": [ 
    "cookies", 
    "activeTab", 
    "identity", 
    "storage", 
    "*://*.github.com/*" 
    ], 

的index.html

<button id="github">Github</button> 

不確定我要去哪裏錯:-(請賜教!

我只想到access_token,以便我可以做一些POST請求。

回答

0

我想this docs可能會幫助你

獲取訪問令牌

chrome.identity.getAuthToken({ 'interactive': true }, function(token) { 
    // Use the token. 
}); 
相關問題