google-oauth2-env-vars

1.4.0 • Public • Published

google-oauth2-env-vars

Npm version Npm downloads MIT license PRs welcome


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.

Package Sidebar

Install

npm i google-oauth2-env-vars

Weekly Downloads

36

Version

1.4.0

License

MIT

Unpacked Size

12.3 kB

Total Files

11

Last publish

Collaborators

  • cedricdelpoux