我一直在尝试将chrome.identity.launchWebAuthFlow与我的Chrome扩展一起使用,以访问Google的OAuth Flow(不,我更喜欢不使用getAuthToken)。我遵循了实现layed out in this question。
这些是我进行设置的步骤:
我已经在我的background.js文件中实现了这段代码
var auth_url = 'https://accounts.google.com/o/oauth2/auth';
var client_id = '<client_id from Cloud Console>';
var redirect_url = chrome.identity.getRedirectURL("oauth2");
var auth_params = {
client_id: client_id,
redirect_uri: redirect_url,
response_type: 'token',
scope: 'profile'
};
var params = Object.keys(auth_params).map(function(k) {
return encodeURIComponent(k) + '=' + encodeURIComponent(auth_params[k])}).join('&')
auth_url += '?' + params;
console.log(redirect_url);
console.log(auth_url);
chrome.identity.launchWebAuthFlow({url: auth_url, interactive: true},
function(responseUrl) { console.log(responseUrl); });
当我运行它时,我收到
Unchecked runtime.lastError while running identity.launchWebAuthFlow: Authorization page could not be loaded.
然后我在浏览器中检查身份验证URL,错误为400 redirect_uri_mismatch
现在,我已经检查了redirect_url无数次。它的格式为https://<app-id>.chromiumapp.org/oauth2
-应用ID与我在Cloud Console凭据中输入的ID完全匹配。当我重新加载扩展时,它也没有改变,因为它与manifest.json中的Key关联。
我想念什么?谁能确认这仍然有效?
作为参考,我的manifest.json文件
{
"name": "My OAuth Extension",
"key": "<My KEY>",
"version": "0.0.1",
"manifest_version": 2,
"description": "Testing OAuth",
"homepage_url": "http://test.com",
"default_locale": "en",
"permissions": [
"https://*/*",
"identity",
"*://*.google.com/*"
],
"background": {
"scripts": ["src/bg/background.js"],
"persistent": true
}
}
我想念什么?谁能确认这仍然有效?