Library that manages Google OAuth2 authentication for your Electron app.
// npm
$ npm install --save @popsql/electron-google-oauth2
// yarn
$ yarn add @popsql/electron-google-oauth2
import ElectronGoogleOAuth2 from '@popsql/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
});
});
import ElectronGoogleOAuth2 from '@popsql/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
});
}
});
const myApiOauth = new ElectronGoogleOAuth2(
'CLIENT_ID',
'CLIENT_SECRET',
['https://www.googleapis.com/auth/drive.metadata.readonly']
{ successRedirectURL: 'https://google.com' },
);
const ElectronGoogleOAuth2 = require('@popsql/electron-google-oauth2').default;
new ElectronGoogleOAuth2(CLIENT_ID, CLIENT_SECRET, SCOPES_LIST);
MIT