Node -webkit and google drive api

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

When an auth message is sent, it is sent with the name 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 was sent this way from gapi - does anyone know how to start a google drive with node-webkit?

+6
source share
1 answer

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

The user must copy the authentication code and paste it into my application - this is not the first choice, but they need to do this only once, and this is preferable to the alternative (absence).

Code sharing for those interested:

When a user selects 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 creates a popup that allows them to resolve and presents them with auth code.

When an authentication code is inserted into my application, I save it in the database and continue to receive the access code, which I then save in the database:

  $.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(); } }); 
+4
source

Source: https://habr.com/ru/post/958730/


All Articles