Node-webkit和google drive api

ed4*_*cky 6 google-drive-api google-oauth node-webkit

尝试让Google Drive API在node-webkit中运行.

发送auth消息时,将发送一个Origin of File://被拒绝.

https://accounts.google.com/o/oauth2/auth
?client_id=<some value>
&scope=https://www.googleapis.com/auth/drive.appdata
https://www.googleapis.com/auth/drive.file
https://www.googleapis.com/auth/drive
&immediate=true
&proxy=oauth2relay1232990068
&redirect_uri=postmessage
&origin=file://
&response_type=token
&state=1938150804|0.1319366391
&authuser=0
Run Code Online (Sandbox Code Playgroud)

不确定为什么它会从gapi那里发送 - 任何人都知道如何从node-webkit授权google驱动器?

ed4*_*cky 4

我选择绕过 oAuth API 并自行完成。

用户必须复制授权代码并将其粘贴到我的应用程序中 - 不是首选,但他们只需执行一次,并且比(缺乏)替代方案更好。

分享一下代码给有兴趣的人:

当用户选择Google Drive时:

            window.open('https://accounts.google.com/o/oauth2/auth?'
                    + 'client_id=<some value>'
                    + '&scope=<space delimited list of permissions>'
                    + '&redirect_uri=urn:ietf:wg:oauth:2.0:oob'
                    + '&response_type=code');
Run Code Online (Sandbox Code Playgroud)

这会产生一个弹出窗口,让他们允许并向他们提供身份验证代码。

当身份验证代码粘贴到我的应用程序中时,我将其保存到数据库并继续获取访问代码,然后将其保存到数据库:

            $.ajax({
                url: "https://accounts.google.com/o/oauth2/token",
                type: 'post',
                data: {
                    code: <authCode>,
                    client_id: CLIENT_ID,
                    client_secret: CLIENT_SECRET,
                    redirect_uri: 'urn:ietf:wg:oauth:2.0:oob',
                    grant_type: 'authorization_code'
                }
            }).error(function(data) {
                myObj.isAuth = false;
                if (cbFail) {
                    cbFail(data);
                }
            }).success(function(data) {
                myObj.isAuth = true;
                <persist entire response>
                if (cbSuccess) {
                    cbSuccess();
                }
            });
Run Code Online (Sandbox Code Playgroud)