Jul*_*anJ 5 google-chrome-extension google-oauth
我一直在尝试让 chrome.identity.launchWebAuthFlow 与我的 Chrome 扩展程序一起使用以访问 Google 的 OAuth Flow(不,我不想使用 getAuthToken)。我遵循了这个问题中列出的实现。
这些是我进行设置的步骤:
我已经在我的 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); });
Run Code Online (Sandbox Code Playgroud)当我运行这个时,我收到
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
- App ID 与我放入 Cloud Console Credentials 的内容完全匹配。当我重新加载扩展时,它也不会改变,因为它与 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
}
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么?任何人都可以确认这仍然有效吗?
小智 3
我的应用程序中有一个相同的项目并解决如下:
https://<appId>.chromiumapp.org/
。url
我在函数的参数中使用了新的 ClientID chrome.identity.launchWebAuthFlow
。redirect_url
了函数回调。 归档时间: |
|
查看次数: |
387 次 |
最近记录: |