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?
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.
All use of the Drive API is available at no additional cost.
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();
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With