我剛剛構建了一個插件,我需要在其中集成Google登錄。我搜索並找到了如何在Chrome擴展中使用谷歌創建登錄
chrome.identity
使用Google帳戶對用戶進行身份驗證但該功能無法正常工作。
所以我跨越溶液來通過以下
變種清單此代碼= chrome.runtime.getManifest();
var clientId = encodeURIComponent(manifest.oauth2.client_id);
var scopes = encodeURIComponent(manifest.oauth2.scopes.join(' '));
var redirectUri = encodeURIComponent('urn:ietf:wg:oauth:2.0:oob:auto');
var url = 'https://accounts.google.com/o/oauth2/v2/auth' +
'?client_id=' + clientId +
'&response_type=code' +
'&redirect_uri=' + redirectUri +
'&scope=' + scopes;
var RESULT_PREFIX = ['Success', 'Denied', 'Error'];
chrome.tabs.create({'url': 'about:blank'}, function(authenticationTab) {
chrome.tabs.onUpdated.addListener(function googleAuthorizationHook(tabId, changeInfo, tab) {
if (tabId === authenticationTab.id) {
var titleParts = tab.title.split(' ', 2);
var result = titleParts[0];
if (titleParts.length == 2 && RESULT_PREFIX.indexOf(result) >= 0) {
chrome.tabs.onUpdated.removeListener(googleAuthorizationHook);
chrome.tabs.remove(tabId);
var response = titleParts[1];
switch (result) {
case 'Success':
// Example: id_token=<YOUR_BELOVED_ID_TOKEN>&authuser=0&hd=<SOME.DOMAIN.PL>&session_state=<SESSION_SATE>&prompt=<PROMPT>
console.log("suc:"+response);
break;
case 'Denied':
// Example: error_subtype=access_denied&error=immediate_failed
console.log("denied:"+response);
break;
case 'Error':
// Example: 400 (OAuth2 Error)!!1
console.log("error:"+response);
break;
}
}
}
});
chrome.tabs.update(authenticationTab.id, {'url': url});
});
,其中,如果我從url變量刪除v2
那麼它總是給誤差與id_token
轉,但如果我添加v2
那麼它的成功並返回代碼。
所以現在我讀谷歌文檔,其中說,現在使用client_id and client_secret
創建一個POST請求,但我的Chrome應用創建谷歌控制檯上的證書不具有client_secret
現在我該怎麼辦?有什麼我錯過了或在這裏做錯了,我也遇到了鉻擴展Screencastify
使用谷歌登錄之一。
任何人都可以解釋他們是如何做到的嗎?