【问题标题】:Handle OAuth callback in node-webkit在 node-webkit 中处理 OAuth 回调
【发布时间】:2014-10-27 19:02:17
【问题描述】:

我正在研究 GitHub API,并希望将返回的 access_token 存储到 node-webkit 中的 localStorage 中。

那么,问题是,如何从远程(HTTP)回调 URL 中获取令牌,例如 http://localhost:2222/github-callback?code=somecodehere

【问题讨论】:

    标签: node.js github oauth github-api node-webkit


    【解决方案1】:

    在新窗口中打开授权页面

    var authWindow = gui.Window.open("https://github.com/login/oauth/authorize");
    

    在其loaded 事件上有一个监听器

    authWindow.on('loaded', function() {
      if(authWindow.location.href.substr(0, 34) === "http://your.domain/github-callback") {
        // do what you want
      }
      // maybe some cleanup
    }
    

    【讨论】:

    • 你测试过了吗? authWindow.document.location.href.substr(0, 34) 不起作用。
    • 这可行,但您需要使用窗口而不是文档:authWindow.window.location.href
    • @Kus 实际上两者都符合规范(参见MDN),但在这个场景中,你的方式更具语义,所以是的,我已经确定了答案。
    • @ZorcetaMoshak 是的,我知道它在规范中,但是当我尝试它时它实际上并不能在 node webkit 中工作,就像 window 一样。
    • @Kus 已经有一段时间没有编写 node-webkit 代码了。感谢您指出 ;)
    猜你喜欢
    • 2014-10-12
    • 2013-04-24
    • 2017-02-28
    • 1970-01-01
    • 2013-08-05
    • 1970-01-01
    • 1970-01-01
    • 2011-02-09
    • 1970-01-01
    相关资源
    最近更新 更多