javascript - 如何在 Chrome 扩展中为 OAuth2 提供重定向 URL?

标签 javascript google-chrome-extension oauth oauth-2.0 google-api

我使用 oauth2-extension 能够从 chrome-extension 中访问 google-data http://smus.com/oauth2-chrome-extensions/

我修改了manifest.json,在JS中输入了数据并尝试进行身份验证,但得到了错误响应:

redirect_uri_mismatch [...] redirect_uri=http://www.google.com/robots.txt

我很想将该网址添加到允许的重定向网址中,但在使用“ native 应用程序”或“chrome 应用程序”时没有这样的选项,我只是无法在 Google 的开发控制台上添加重定向 URI。

有什么办法可以解决这个问题吗?

我的manifest.Json的一部分:

"permissions": [
        "http://ajax.googleapis.com/",
        "storage",
        "https://accounts.google.com/o/oauth2/token"
    ],
    "content_scripts":
            [{
                    "matches": ["https://plus.google.com/*"],
                    "js": [
                        "setup/js/jquery-1.10.2.min.js",                        
                        "date.js"]
                },
                {
                    "matches": ["http://www.google.com/robots.txt*"],
                    "js": ["oauth2/oauth2_inject.js"],
                    "run_at": "document_start"
                }],

我的 JS 代码:

var googleAuth = new OAuth2('google', {
  client_id: 'WHATEVER.apps.googleusercontent.com',
  client_secret: 'HIDDEN',
  api_scope: 'https://www.googleapis.com/auth/tasks'
});


function GetAuth()
{
    googleAuth.authorize(function() {
        alert('yippee ki yay!');
    });
}

(当然“HIDDEN”和“WHATEVER”包含有效值)

最佳答案

谷歌扩展示例中有一个 oauth 示例,工作正常,我使用过它。但您确实应该迁移到 chrome 身份,它可以为您完成这一切。

关于javascript - 如何在 Chrome 扩展中为 OAuth2 提供重定向 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21658659/

相关文章:

javascript - 如何在 Javascript 中获取 html 页面的标题

google-chrome-extension - 如何删除对 Google Chrome 扩展程序的评论

javascript - img src 中的 meteor 模板不起作用

json - 添加键盘快捷键以执行 Chrome 扩展

javascript - 建立内容脚本和后台页面之间的通信链接

oauth - Soundcloud 作为 Oauth 提供者 : How to make it connect only one time

facebook - 使用 facebook graph api 从页面获取事件

c# - Microsoft ADD - 应用程序注册 - 请求中指定的回复网址与配置的回复网址不匹配

javascript - Three.js 捏合缩放

javascript - 动态创建多个 DIVS