14.0.0 • Published 11 months ago

@getstation/electron-google-oauth2 v14.0.0

Weekly downloads
79
License
MIT
Repository
github
Last release
11 months ago

@getstation/electron-google-oauth2

Library that manages Google OAuth2 authentication for your Electron app.

Install

// npm
$ npm install --save @getstation/electron-google-oauth2
// yarn
$ yarn add @getstation/electron-google-oauth2

Usage

Access Token

import ElectronGoogleOAuth2 from '@getstation/electron-google-oauth2';

app.on('ready', () => {
  const myApiOauth = new ElectronGoogleOAuth2(
    'CLIENT_ID',
    'CLIENT_SECRET',
    ['https://www.googleapis.com/auth/drive.metadata.readonly']
  );

  myApiOauth.openAuthWindowAndGetTokens()
    .then(token => {
      // use your token.access_token
    });
});

Refresh Token

import ElectronGoogleOAuth2 from '@getstation/electron-google-oauth2';

app.on('ready', () => {
  const myApiOauth = new ElectronGoogleOAuth2(
    'CLIENT_ID',
    'CLIENT_SECRET',
    ['https://www.googleapis.com/auth/drive.metadata.readonly']
  );
  
  const refreshToken = \\ Read the saved refresh token
  
  if(refreshToken) {
    myApiOauth.setTokens({ refresh_token: refreshToken });
  } else {
    myApiOauth.openAuthWindowAndGetTokens()
      .then(token => {
        // save the token.refresh_token secured to use it the next time the app loading
        // use your token.access_token
      });
  }
});

Use custom successRedirectURL

const myApiOauth = new ElectronGoogleOAuth2(
  'CLIENT_ID',
  'CLIENT_SECRET',
  ['https://www.googleapis.com/auth/drive.metadata.readonly']
  { successRedirectURL: 'https://google.com' },
);

Requires with plain JavaScript

const ElectronGoogleOAuth2 = require('@getstation/electron-google-oauth2').default;
new ElectronGoogleOAuth2(CLIENT_ID, CLIENT_SECRET, SCOPES_LIST);

License

MIT

14.0.0

11 months ago

2.1.0

4 years ago

2.0.0

5 years ago

2.0.0-rc.2

5 years ago

2.0.0-rc

5 years ago

2.0.0-rc.1

5 years ago

1.1.2

5 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago