问题
I'm trying to use vk.messages api in chrome app like this:
app.login = function () {
var link = 'https://oauth.vk.com/authorize?' +
'client_id=4837072' +
'&scope=friends,docs,status,messages,notifications,' +
'&redirect_uri=' + 'https://oauth.vk.com/blank.html' +
'&display=popup' +
'&v=API_VERSION' +
'&response_type=token';
var width = 655;
var height = 539;
var left = (screen.width / 2) - (width / 2);
var top = (screen.height / 2) - (height / 2);
chrome.identity.launchWebAuthFlow({
'url': link,
'interactive': true
}, function (redirect_url) {
// redirect_url is undefined
console.log(redirect_url);
});
};
It needs to set auth redirect_uri this way "https://oauth.vk.com/blank.html", but chrome.identity api uses "https://.chromiumapp.org/". So, vk auth window is showed and redirect works, but chrome can't determine auth redirect, and doesn't call back with redirect url. Is there any other way to get redirect url in chrome app?
回答1:
Well, I see where you're going with "it needs to set redirect_uri
this way":
redirect_uri=https://oauth.vk.com/blank.html
It is a mandatory condition for methods which descriptions say that they are available only for Desktop applications.
I'm afraid there is no way to override the URL used by identity
API.
In this case, you can go kind of the same route Silver Bird Twitter client went: inject a Content Script in the target address. From there you can extract the tokens needed.
Edit: I forgot that you are writing a Chrome app. You should then try using <webview>
and its script injection capabilities.
This means you'll have to do OAuth without help from chrome.identity
yourself, but at least it's a solution.
来源:https://stackoverflow.com/questions/29200374/authorize-chrome-app-as-standalone-in-vkontakte-api