https://github.com/getstation/electron-google-oauth2
A Google OAuth2 module for your Electron app
https://github.com/getstation/electron-google-oauth2
Last synced: about 1 year ago
JSON representation
A Google OAuth2 module for your Electron app
- Host: GitHub
- URL: https://github.com/getstation/electron-google-oauth2
- Owner: getstation
- License: mit
- Created: 2018-05-14T14:10:54.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-10-05T18:06:29.000Z (over 2 years ago)
- Last Synced: 2025-04-02T05:08:36.111Z (about 1 year ago)
- Language: TypeScript
- Size: 81.1 KB
- Stars: 81
- Watchers: 6
- Forks: 39
- Open Issues: 11
-
Metadata Files:
- Readme: readme.md
- Changelog: CHANGELOG.md
- License: license
Awesome Lists containing this project
README
# @getstation/electron-google-oauth2
> Library that manages Google OAuth2 authentication for your [Electron](http://electron.atom.io) app.
## Install
```
// npm
$ npm install --save @getstation/electron-google-oauth2
// yarn
$ yarn add @getstation/electron-google-oauth2
```
## Usage
### Access Token
```typescript
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
```typescript
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
```js
const myApiOauth = new ElectronGoogleOAuth2(
'CLIENT_ID',
'CLIENT_SECRET',
['https://www.googleapis.com/auth/drive.metadata.readonly']
{ successRedirectURL: 'https://google.com' },
);
```
### Requires with plain JavaScript
```js
const ElectronGoogleOAuth2 = require('@getstation/electron-google-oauth2').default;
new ElectronGoogleOAuth2(CLIENT_ID, CLIENT_SECRET, SCOPES_LIST);
```
## License
MIT