authorize chrome app as standalone in vkontakte api

坚强是说给别人听的谎言 提交于 2019-12-11 11:44:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!