Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
262 views
in Technique[技术] by (71.8m points)

error "Cannot return to provided redirect_uri" in chrome extension using stackapp auth 2.0

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...