Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is anyone having issues with the async not receiving a response after authentication? #13

Open
bksteckler opened this issue Aug 10, 2017 · 5 comments
Assignees

Comments

@bksteckler
Copy link

Relatively new to electron so I am not sure if I am missing something in how I structured the code or if there is something amiss.

I have set up a main.js with the included code snippet and I can not seem to get a response from the getAuthorizationCode function to enable the code to continue past the async await call. I am able to get the log in window to appear along with the authentication consent screen. But at that point it redirects to my localhost page but the code is stuck in the async waiting process.

Any suggestions?

const electron = require("electron");
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;

const path = require("path");
const url = require("url");
const electronGoogleOauth = require("electron-google-oauth");

app.on('ready',createWindow);
function createWindow(){
    const browserWindowParams = {
        'use-content-size': true,
        center: true,
        show: true,
        resizable: true,
        'always-on-top': true,
        'standard-window': true,
        'auto-hide-menu-bar': true,
        'node-integration': false
    };

    const googleOauth = electronGoogleOauth(browserWindowParams);

    (async () => {
        console.log("I am in the async");

        // retrieve  authorization code only 
        const authCode = await googleOauth.getAuthorizationCode(
            ['https://www.google.com/m8/feeds'],
            <<Removed Client Id>>,
            <<Removed Secret Id>>,
            'http://localhost'
        );

        console.log("async await has completed");
        console.log(authCode);

        // retrieve access token and refresh token 
        const result = await googleOauth.getAccessToken(
            ['https://www.google.com/m8/feeds'],
           <<Removed Client Id>>,
            <<Removed Secret Id>>,
            'http://localhost'
        );
        console.log(result);
    })();
}
@parro-it parro-it self-assigned this Aug 10, 2017
@andrewrt
Copy link

Seeing the same thing here.

I thought this might be due to the contacts API not being enabled in the google developer console, but that doesn't seem to be the issue.
(Tried enabling/disabling contacts api, tried switching out the feeds argument for 'profile', etc. But that didn't help).

@TimNZ
Copy link

TimNZ commented Nov 4, 2017

Try this.
The BrowserWindow options are out of date, this module was made ages ago.

You only need to call getAccessToken() as it already calls getAuthorizationCode().
You need to hook the app 'window-all-closed' event as the app will by default quit when all windows are closed.
Feel free to revert to async, should work fine.

Run in Electron 1.7.7

const electronGoogleOauth = require('electron-google-oauth');
const {app} = require('electron');
const browserWindowParams = {
  center: true,
  show: true,
  resizable: false,
  webPreferences: {
    nodeIntegration: false
  }
};

const clientId = '<clientid>';
const clientSecret = '<clientsecret>';

app.on('window-all-closed',() => {

})
app.on('ready', () => {
  const googleOauth = electronGoogleOauth(browserWindowParams);
  googleOauth.getAccessToken(
    ['https://www.googleapis.com/auth/plus.me',
      'profile',
      'email'],
    clientId,
    clientSecret
  ).then((result) => {
    console.log('result',result);
  })

});

@ItsWendell
Copy link

@TimNZ thanks for sharing, works here!

@vanseinfo
Copy link

@TimNZ Your code worked!! Thanks for sharing..

@vfranco19
Copy link

Thanks you men

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants