无法返回提供的redirect_uri

时间:2016-09-14 14:19:36

标签: javascript google-chrome-extension

尝试使用oauth2和chrome.identify构建chrome扩展时出错。

它不起作用,我遇到以下错误:

Application Login Failure
An error occurred while login into an application.

Error Details

error description: Cannot return to provided redirect_uri

使用以下代码:

const id = '1234'
const key = 'key'
const scope = 'read_inbox,no_expiry'
const request_uri = 'https://stackexchange.com/oauth/dialog'
const redirect_uri = chrome.identity.getRedirectURL('oauth2')
const requestUrl = `${request_uri}?client_id=${id}&scope=${scope}&redirect_uri=${redirect_uri}`
chrome.identity.launchWebAuthFlow({
  url: requestUrl,
  interactive: true
}, url => {
  console.log('redire' + url)
})

应用程序似乎尝试重定向以下内容:

https://hipaoikehndjdcpknmnofjbhfjmonnem.chromiumapp.org/oauth2

但它不起作用......

有什么想法吗?

我的清单:

{
  "name": "__MSG_appName__",
  "version": "0.0.1",
  "manifest_version": 2,
  "description": "__MSG_appDescription__",
  "icons": {
    "16": "images/icon-16.png",
    "128": "images/icon-128.png"
  },
  "default_locale": "en",
  "background": {
    "scripts": [
      "scripts/chromereload.js",
      "scripts/background.js"
    ]
  },
  "permissions": [
    "tabs",
    "identity",
    "https://stackexchange.com/*/*"
  ],
  "options_ui": {
    "page": "options.html",
    "chrome_style": true
  },
  "browser_action": {
    "default_icon": {
      "19": "images/icon-19.png",
      "38": "images/icon-38.png"
    },
    "default_title": "someapp",
    "default_popup": "popup.html"
  }
}

编辑:当我尝试记录错误的网址时,我有以下内容:

https://stackexchange.com/oauth/dialog?client_id=<client_id>&scope=read_inbox,no_expiry&redirect_uri=https://<app-id>.chromiumapp.org/oauth2#

但总是出现同样的错误

1 个答案:

答案 0 :(得分:0)

我遇到了和你今天一样的问题,并且长期以来一直在努力解决这个问题。

我相信您在代码中所写的内容并没有错,但是您在stackexchange.com上注册应用时填写的选项。

简而言之,当您在https://stackapps.com/apps/oauth/register填写此表单时,请务必记住编写 OAuth域指令的正确格式,该格式应为:

<app-id>.chromiumapp.org

没有协议。

我用这种方式解决了这个问题。希望它会有所帮助。