错误“无法返回提供的redirect_uri”在使用stackapp auth 2.0进行扩展 [英] error "Cannot return to provided redirect_uri" in chrome extension using stackapp auth 2.0
问题描述
我遵循 https://developer.chrome.com/apps/app_identity 的教程。并在这里使用api https://developer.chrome.com/apps/identity 但没有运气。任何人都可以指出这段代码有什么问题吗?
googleLibraryLoaded(){
var redirect_uri = chrome.identity .getRedirectURL( http://qqibrow.github.io);
var full_url =https://stackexchange.com/oauth/dialog?client_id=4716&redirect_uri=+ redirect_uri;
console.log(redirect_uri);
console.log(full_url);
chrome.identity.launchWebAuthFlow({
'url':full_url,
'interactive':true
},authorizationCallback);
}
var authorizationCallback = function(data){
//如果成功,应该用auth_token打印出redirect_uri。
console.log(data);
};
// manifest.json
// ...
权限:[
activeTab,
identity,
https://ajax.googleapis.com/,
https://stackexchange.com/*,
https://stackexchange.com/oauth/*,
http://qqibrow.github.io/*
,
web_accessible_resources:[
http://qqibrow.github.io/*,
https://stackexchange.com/*,
],
// ...
如果我尝试 https:// stackexchange .com / oauth / dialog?client_id = 4716& redirect_uri = http://qqibrow.github.io 它确实有效。但是,通过上面的代码,我总是从stackexchange中得到一个错误页面,并说:
$ p $ Application $ Login $ $ $ Application Application Failure error error:Can not return提供redirect_uri。
这是 chrome.identity.getRedirectURL()
。
它不允许您重定向到任意域;您可以提供一个路径,但是 chrome.identity
的域将为 https://< app-id> .chromiumapp.org
。
因此,您的调用返回 https://< app-id> .chromiumapp.org / http:/ /qqibrow.github.io
这不是一个有效的URL,并且您的认证失败。
我建议重新阅读 launchWebAuthFlow
文档。
I follow the tutorial here https://developer.chrome.com/apps/app_identity and use the api here https://developer.chrome.com/apps/identity but with no luck. Could anyone point out is anything wrong in this code?
function onGoogleLibraryLoaded() {
var redirect_uri = chrome.identity.getRedirectURL("http://qqibrow.github.io");
var full_url = "https://stackexchange.com/oauth/dialog?client_id=4716&redirect_uri=" + redirect_uri;
console.log(redirect_uri);
console.log(full_url);
chrome.identity.launchWebAuthFlow({
'url': full_url,
'interactive': true
}, authorizationCallback);
}
var authorizationCallback = function (data) {
// should print out redirect_uri with auth_token if succeed.
console.log(data);
};
// manifest.json
// ...
"permissions": [
"activeTab",
"identity",
"https://ajax.googleapis.com/",
"https://stackexchange.com/*",
"https://stackexchange.com/oauth/*",
"http://qqibrow.github.io/*"
],
"web_accessible_resources": [
"http://qqibrow.github.io/*",
"https://stackexchange.com/*",
],
// ...
If i try https://stackexchange.com/oauth/dialog?client_id=4716&redirect_uri=http://qqibrow.github.io it does work. But with above code, I always got a error page from stackexchange, saying that:
Application Login Failure error description: Cannot return to provided redirect_uri.
This is a creative usage of chrome.identity.getRedirectURL()
.
It does not allow you to redirect to an arbitrary domain; you can provide a path, but the domain for chrome.identity
will be https://<app-id>.chromiumapp.org
.
So, your call returns https://<app-id>.chromiumapp.org/http://qqibrow.github.io
which is not a valid URL, and your auth fails.
I recommend re-reading the launchWebAuthFlow
documentation.
这篇关于错误“无法返回提供的redirect_uri”在使用stackapp auth 2.0进行扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!