【问题标题】:How to provide redirect URL for OAuth2 in Chrome extension?如何在 Chrome 扩展程序中为 OAuth2 提供重定向 URL?
【发布时间】:2014-03-06 16:32:49
【问题描述】:

我使用 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

我很想将该 url 添加到允许的重定向 url,但是在使用“本机应用程序”或“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”包含有效值)

【问题讨论】:

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


    【解决方案1】:

    google 扩展示例中有一个 oauth 示例运行良好,我使用过。但是你真的应该迁移到 chrome 身份,它为你做这一切。

    【讨论】:

    • 我无法相信它与 chrome 身份一起工作是多么容易...... :) 谢谢朋友。
    • 请注意,用户需要登录 chrome 而旧方法不需要。
    • “不起作用”不是这样的。可以帮助。具体情况?
    • chrome 身份要求您使用 Google 帐户登录 chrome,这在很多时候并不适合
    【解决方案2】:

    我遇到了同样的问题,oauth2-extensions!我尝试编辑适配器文件 adapters/google.js ,如下

     redirectURL: function(config) {
        return 'your-redirect-url'; // here default redirect URL is http://www.google.com/robots.txt
      }
    

    这对我有用,但是我不确定此 API 修改是否有任何问题,因为在 oauth2-extensions 的 documentation 中没有提及此类。

    另外,chrome.identity 是完成此任务的最简单选择!

    【讨论】:

      猜你喜欢
      • 2012-08-17
      • 2014-11-15
      • 2012-03-17
      • 2018-08-21
      • 1970-01-01
      • 1970-01-01
      • 2016-03-28
      • 1970-01-01
      • 2017-01-25
      相关资源
      最近更新 更多