0
我正在使用GitHub API,並且希望將返回的access_token
存儲到node-webkit中的localStorage
中。在node-webkit中處理OAuth回調
所以,問題是,如何從遠程(HTTP)回調URL(如http://localhost:2222/github-callback?code=somecodehere
)獲取令牌?
我正在使用GitHub API,並且希望將返回的access_token
存儲到node-webkit中的localStorage
中。在node-webkit中處理OAuth回調
所以,問題是,如何從遠程(HTTP)回調URL(如http://localhost:2222/github-callback?code=somecodehere
)獲取令牌?
打開授權頁面在新窗口中
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)'不起作用。 – 0x142857 2014-10-30 15:18:09
這可行,但您需要使用窗口而不是文檔:'authWindow.window.location.href' – Kus 2015-05-11 01:54:05
@Kus其實兩者都是按照規範(參見[MDN](https://developer.mozilla.org/zh-CN/) docs/Web/API/Location)),但在這個場景中,你的方式更加語義化,所以是的,我已經解決了答案。 – 2015-05-12 10:40:58