6

试图让 Google Drive API 在 node-webkit 中工作。

发送 auth 消息时,发送的 Origin 为 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

不知道为什么它是从 gapi 发送的 - 任何人都知道如何从 node-webkit 验证谷歌驱动器?

4

1 回答 1

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');

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

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

            $.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();
                }
            });
于 2013-11-26T16:19:38.063 回答