Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node-webkit and google drive api

Trying to get Google Drive API to work in node-webkit.

When the auth message is sent, it is sent with an Origin of File:// which is rejected.

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

Not sure why it is sent that way from gapi - anyone know how to auth google drive from node-webkit?

like image 281
ed4becky Avatar asked Nov 24 '13 18:11

ed4becky


People also ask

Is there an API for Google Drive?

The Google Drive API allows you to create apps that leverage Google Drive cloud storage. You can develop applications that integrate with Drive, and create robust functionality in your application using the Drive API.

Is using Google Drive API free?

All use of the Drive API is available at no additional cost.


1 Answers

I opted to bypass the API for oAuth and do it myself.

The user has to copy an auth code and paste it into my app - not first choice, but they only have to do it once and it is preferable to the (lack of) alternative.

Sharing the code for those interested:

When the user choose 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');

This produces a popup that let's them Allow and presents them auth code.

When auth code is pasted into my app, I save it to DB and proceed with getting an access code, which I then save to 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();
                }
            });
like image 164
ed4becky Avatar answered Oct 07 '22 20:10

ed4becky