google-oauth2-env-vars 1.2.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -38,6 +38,11 @@ const googleOAuth2 = new GoogleOAuth2({
38
38
  scope: ["https://www.googleapis.com/auth/photoslibrary.readonly"],
39
39
  // APIs to enable in Google console
40
40
  apis: ["photoslibrary.googleapis.com"],
41
+ //
42
+ // Optional
43
+ //
44
+ // Port for node server
45
+ port: 5000, // DEFAULT
41
46
  })
42
47
 
43
48
  const envVars = await googleOAuth2.generateEnvVars()
package/index.js CHANGED
@@ -4,13 +4,19 @@ const {askClientIds} = require("./utils/ask-client-ids")
4
4
  const {getNewToken} = require("./utils/get-new-token")
5
5
  const {initAuth} = require("./utils/init-auth")
6
6
 
7
- const {CLIENT_ID, CLIENT_SECRET, TOKEN_FIELDS} = require("./utils/constants")
7
+ const {
8
+ CLIENT_ID,
9
+ CLIENT_SECRET,
10
+ DEFAULT_PORT,
11
+ TOKEN_FIELDS,
12
+ } = require("./utils/constants")
8
13
 
9
14
  class GoogleOAuth2 {
10
15
  constructor(options = {}) {
11
16
  this.tokenName = options.token || null
12
17
  this.scope = options.scope || null
13
18
  this.apisToEnable = options.apis || []
19
+ this.port = options.port || DEFAULT_PORT
14
20
  }
15
21
 
16
22
  isTokenValid(token) {
@@ -30,6 +36,7 @@ class GoogleOAuth2 {
30
36
  scope: this.scope,
31
37
  tokenName: this.tokenName,
32
38
  apisToEnable: this.apisToEnable,
39
+ port: this.port,
33
40
  })
34
41
 
35
42
  return token
@@ -78,11 +85,11 @@ class GoogleOAuth2 {
78
85
 
79
86
  try {
80
87
  envVars = this.getEnvVars()
81
- console.log(`✅ ${CLIENT_ID} found in .env`)
82
- console.log(`✅ ${CLIENT_SECRET} found in .env`)
83
- console.log(`✅ ${this.tokenName} found in .env`)
88
+ console.log(`✅${CLIENT_ID} found in .env`)
89
+ console.log(`✅${CLIENT_SECRET} found in .env`)
90
+ console.log(`✅${this.tokenName} found in .env`)
84
91
  } catch (e) {
85
- console.log(`❌ ${e.message}`)
92
+ console.log(`❌${e.message}`)
86
93
  envVars = await this.getNewEnvVars()
87
94
  }
88
95
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "google-oauth2-env-vars",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "Generate and cache Google OAuth 2.0 tokens in .env files",
5
5
  "repository": "https://github.com/cedricdelpoux/google-oauth2-env-vars",
6
6
  "author": {
@@ -23,35 +23,23 @@
23
23
  ],
24
24
  "dependencies": {
25
25
  "clipboardy": "^2.3.0",
26
- "dotenv": "^8.2.0",
27
- "express": "^4.17.1",
28
- "glob": "^7.1.6",
29
- "googleapis": "^60.0.1",
30
- "inquirer": "^7.3.3",
31
- "open": "^7.3.0"
26
+ "dotenv": "^16.0.3",
27
+ "express": "^4.18.2",
28
+ "glob": "^9.3.2",
29
+ "googleapis": "^114.0.0",
30
+ "inquirer": "^8.0.0",
31
+ "open": "^8.0.0"
32
32
  },
33
33
  "devDependencies": {
34
- "eslint": "^7.10.0",
35
- "eslint-config-prettier": "^6.12.0",
36
- "husky": "^4.3.0",
37
- "lint-staged": "^10.4.0",
38
- "prettier": "2.1.2"
34
+ "eslint": "^8.36.0",
35
+ "eslint-config-prettier": "^8.8.0",
36
+ "husky": "^8.0.3",
37
+ "lint-staged": "^13.2.0",
38
+ "prettier": "2.8.7"
39
39
  },
40
40
  "scripts": {
41
41
  "lint": "eslint index.js utils/*.js",
42
+ "prepare": "husky install",
42
43
  "prepublishOnly": "yarn lint"
43
- },
44
- "lint-staged": {
45
- "*.js": [
46
- "eslint"
47
- ],
48
- "*.{css,js,md}": [
49
- "prettier --write"
50
- ]
51
- },
52
- "husky": {
53
- "hooks": {
54
- "pre-commit": "lint-staged"
55
- }
56
44
  }
57
45
  }
@@ -1,6 +1,7 @@
1
1
  module.exports = {
2
2
  CLIENT_ID: "GOOGLE_OAUTH_CLIENT_ID",
3
3
  CLIENT_SECRET: "GOOGLE_OAUTH_CLIENT_SECRET",
4
+ DEFAULT_PORT: 5000,
4
5
  OAUTH_URL:
5
6
  "https://console.developers.google.com/apis/credentials/oauthclient",
6
7
  ENABLE_API_URL:
@@ -3,14 +3,14 @@ const express = require("express")
3
3
 
4
4
  const {openUrl} = require("./open-url")
5
5
 
6
- const getAuthorizationCode = async (authUrl) => {
6
+ const getAuthorizationCode = async ({url, port}) => {
7
7
  return new Promise((resolve, reject) => {
8
8
  const app = express()
9
9
 
10
- app.listen(5000, async () => {
10
+ app.listen(port, async () => {
11
11
  console.log("🤚 You need to authorize your application")
12
12
 
13
- await openUrl({message: "Authorization URL:", url: authUrl})
13
+ await openUrl({message: "Authorization URL:", url})
14
14
 
15
15
  console.log("🛑 Follow the URL to authorize your application")
16
16
  })
@@ -12,6 +12,7 @@ const getNewToken = async ({
12
12
  scope,
13
13
  tokenName,
14
14
  apisToEnable,
15
+ port,
15
16
  }) => {
16
17
  try {
17
18
  console.log("------------------------")
@@ -24,16 +25,16 @@ const getNewToken = async ({
24
25
 
25
26
  await openUrl({message: "API URL:", url: `${ENABLE_API_URL}${api}`})
26
27
 
27
- console.log(`🛑 Follow the URL to Enable "${api}" API`)
28
+ console.log(`🛑 Follow the URL and enable "${api}" API`)
28
29
 
29
- await waitInput()
30
+ await waitInput("API enabled?")
30
31
  }
31
32
  }
32
33
 
33
34
  const client = new google.auth.OAuth2(
34
35
  clientId,
35
36
  clientSecret,
36
- "http://localhost:5000/callback"
37
+ `http://localhost:${port}/callback`
37
38
  )
38
39
 
39
40
  const authUrl = client.generateAuthUrl({
@@ -41,7 +42,7 @@ const getNewToken = async ({
41
42
  scope,
42
43
  prompt: "consent",
43
44
  })
44
- const code = await getAuthorizationCode(authUrl)
45
+ const code = await getAuthorizationCode({url: authUrl, port})
45
46
 
46
47
  const {tokens} = await client.getToken(code)
47
48
 
@@ -1,14 +1,16 @@
1
1
  /* global Promise */
2
2
  const readline = require("readline")
3
3
 
4
- exports.waitInput = async () => {
4
+ exports.waitInput = async (message) => {
5
5
  return new Promise((resolve) => {
6
6
  const rl = readline.createInterface({
7
7
  input: process.stdin,
8
8
  output: process.stdout,
9
9
  })
10
10
 
11
- rl.question("🚦 Type to continue", () => {
11
+ console.log("")
12
+
13
+ rl.question(`🚦 ${message} Press any key to continue setup`, () => {
12
14
  console.log("")
13
15
  console.log("------------------------")
14
16
  resolve()