Giter Club home page Giter Club logo

electron-google-oauth's Introduction

electron-google-oauth

Get Google api access token using an electron window to let the user authorize the app.

Travis Build Status

Installation

npm install --save electron-google-oauth

Usage

  import electronGoogleOauth from 'electron-google-oauth';

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

  const googleOauth = electronGoogleOauth(browserWindowParams);

  ( async () => {

    // retrieve  authorization code only
    const authCode = await googleOauth.getAuthorizationCode(
      ['https://www.google.com/m8/feeds'],
      'your-client-id',
      'your-client-secret',
      'your-redirect-uri'
    );
    console.dir(authCode);

    // retrieve access token and refresh token
    const result = await googleOauth.getAccessToken(
      ['https://www.google.com/m8/feeds'],
      'your-client-id',
      'your-client-secret',
      'your-redirect-uri'
    );
    console.dir(result);

  })();

Testing

To test the library, clone this git repo, then define CLIENTSECRET and CLIENTID environment variables holding your Google API details, then run:

npm install
npm start

License

The MIT License (MIT)

Copyright (c) 2015 Andrea Parodi

electron-google-oauth's People

Contributors

luigiplr avatar parro-it avatar thomas101 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

electron-google-oauth's Issues

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

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);
    })();
}

Why OAuth?

Why would one use OAuth for a desktop app? You have nowhere to hide the client secret so in the end everyone can access your users.

Do I get something wrong here?

npm install error

Hey,

1.3.0 seems to have stopped working when you do an install from npm. If you npm init a fresh project and install you get the following...

MacBook-Pro:t Tom$ npm install --save electron-google-oauth
npm WARN package.json [email protected] No description
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No README data
npm ERR! Darwin 15.0.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "--save" "electron-google-oauth"
npm ERR! node v4.2.4
npm ERR! npm  v2.14.12
npm ERR! path /Users/Tom/Desktop/t/node_modules/electron-google-oauth/dist/bin.js
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall chmod

npm ERR! enoent ENOENT: no such file or directory, chmod '/Users/Tom/Desktop/t/node_modules/electron-google-oauth/dist/bin.js'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/Tom/Desktop/t/npm-debug.log

browser-window dependency not found

You're attempting to use a browser-window dependency not specified in package.json so this library cannot be used because of this dependency not being found.
Nice work though! I like how you abstracted signin for electron apps.

authorizeApp promise hung

Greetings, during debug managed to determine that in function authorizeApp promise, win.on('page-title-updated') promise return anything only if title start with "Denied" or "Success", while in my case I got "Sign in - Google accounts". While it may be that I still not put this package in correct way, Promise must return some result in all possible cases, to not spend time on debugging library itself.

Thanks.

Docs example update

Hey just been trying out your library and you've saved me a ton of time, thanks!

Found a bug though. If you use the example provided in the docs, the browser window params never make it down to the browser...

const googleOauth = electronGoogleOauth(browserWindowParams);

...ends up in the __unused_BrowserWindow variable field on line 71. If you pass the following arguments...

const googleOauth = electronGoogleOauth(undefined, browserWindowParams);

the right things end up in the right place. The example does have show set to false as well which means at first glance nothing seems to happen.

Thanks!

cannot specify redirect_uri

I thought this library would be great as a work around the problem with postmessage and the google javascript auth. But I found that this completely changes my flow of my API backend because it assumes an application credential and cannot be shared with my web browser app credentials.

Can this be achieved with redirect_uri postmessage?

BrowserWindow is not a constructor

With the following code:

const result = googleOauth.getAccessToken(
      ['https://www.google.com/m8/feeds'],
      ArbitratorConfig.google_client_id,
      ArbitratorConfig.google_client_secret
    ).then(token => {
                console.log(JSON.stringify(token, null, 2));
                // app.removeListener('will-quit', preventQuit);
                // app.quit();

I am getting the following exception:

index.js:27 Uncaught (in promise) TypeError: BrowserWindow is not a constructor(…)

My current version of electron-google-oauth is 2.0.0.

Error: invalid_client: The OAuth client was not found.

I'm trying to run this example. I've created my CLIENTID and CLIENTSECRET environment variables and verified that they are correct, and do not have any leading or trailing whitespace. I've also run npm install. However when I run the app, I get a 401 error with the description from above. What does this mean?

I've looked all over the place, and it seems like the normal issue that causes this is either whitespace in the environment variables, or a lack of a product name and email in the Google cloud console. I have checked and double checked all of those things. Thanks!

Are you insane?!

Why have you defined show: false, in the window params in the README? I spent an hour trying to understand why the window didn't show up!!! Are you evil??

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.