google-oauth2-env-vars
v1.4.0
Published
Generate and cache Google OAuth 2.0 tokens in .env files
Downloads
403
Maintainers
Readme
Helper class to generate and cache Google OAuth 2.0
tokens in .env
files:
GOOGLE_OAUTH_CLIENT_ID=23...8o1jm.apps.googleusercontent.com
GOOGLE_OAUTH_CLIENT_SECRET=QL...naxL
GOOGLE_PHOTOS_TOKEN={"access_token":"ya..54c","refresh_token":"1..qq0","scope":"https://www.googleapis.com/auth/photoslibrary.readonly","token_type":"Bearer","expiry_date":1598277881619}
Usage
Download package from the NPM registry:
yarn add google-oauth2-env-vars
Generate .env vars
const GoogleOAuth2 = require("google-oauth2-env-vars")
const googleOAuth2 = new GoogleOAuth2({
// .env token var name
token: "GOOGLE_PHOTOS_TOKEN",
// Authorization scope
scope: ["https://www.googleapis.com/auth/photoslibrary.readonly"],
// APIs to enable in Google console
apis: ["photoslibrary.googleapis.com"],
//
// Optional
//
// Port for node server
port: 5000, // DEFAULT
})
const envVars = await googleOAuth2.generateEnvVars()
Get Auth
const GoogleOAuth2 = require("google-oauth2-env-vars")
const googleOAuth2 = new GoogleOAuth2({
// .env token var name
token: "GOOGLE_PHOTOS_TOKEN",
})
const auth = await googleOAuth2.getAuth()
const {token} = await auth.getAccessToken()
const googlePhotos = new GooglePhotos(token)
Contributing
- ⇄ Pull/Merge requests and ★ Stars are always welcome.
- For bugs and feature requests, please create an issue.