@x-sls/google-auth 1.0.2 → 1.1.2

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/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@x-sls/google-auth",
3
- "version": "1.0.2",
3
+ "version": "1.1.2",
4
4
  "main": "src/index.js",
5
5
  "scripts": {},
6
6
  "dependencies": {
7
- "jsonwebtoken": "^9.0.2"
7
+ "jsonwebtoken": "^9.0.3"
8
8
  }
9
9
  }
package/src/handlers.js CHANGED
@@ -22,8 +22,9 @@ function initiate({ GOOGLE_CLIENT_ID, REDIRECT_URI }) {
22
22
  function callback({
23
23
  GOOGLE_CLIENT_ID,
24
24
  GOOGLE_CLIENT_SECRET,
25
+ JWT_SECRET,
25
26
  REDIRECT_URI,
26
- JWT_SECRET
27
+ isUserAllowed
27
28
  }) {
28
29
  return async event => {
29
30
  const { code, state } = event.queryStringParameters
@@ -47,6 +48,12 @@ function callback({
47
48
  const info = await getUserInfo({ access_token })
48
49
 
49
50
  const { email, name, picture } = info
51
+
52
+ const isAllowed = await isUserAllowed(email)
53
+ if (!isAllowed) {
54
+ throw new Error('Contact admin for access.')
55
+ }
56
+
50
57
  const sessionToken = jwt.sign(
51
58
  {
52
59
  email,
@@ -75,12 +82,17 @@ function callback({
75
82
  }
76
83
  }
77
84
 
78
- function verify({ JWT_SECRET }) {
85
+ function verify({ JWT_SECRET, isUserAllowed }) {
79
86
  return async event => {
80
87
  try {
81
88
  const { token } = JSON.parse(event.body)
82
89
  const decoded = jwt.verify(token, JWT_SECRET)
83
90
 
91
+ const isAllowed = await isUserAllowed(decoded.email)
92
+ if (!isAllowed) {
93
+ throw new Error('Contact admin for access.')
94
+ }
95
+
84
96
  return {
85
97
  statusCode: 200,
86
98
  headers: {
@@ -96,7 +108,7 @@ function verify({ JWT_SECRET }) {
96
108
  'Access-Control-Allow-Origin': '*',
97
109
  'Access-Control-Allow-Credentials': true
98
110
  },
99
- body: JSON.stringify({ error: 'Invalid token' })
111
+ body: JSON.stringify({ error: error.message })
100
112
  }
101
113
  }
102
114
  }
package/src/index.js CHANGED
@@ -1,7 +1,7 @@
1
- const createClient = require('./client')
1
+ const client = require('./client')
2
2
  const handlers = require('./handlers')
3
3
 
4
4
  module.exports = {
5
- createClient,
5
+ client,
6
6
  handlers
7
7
  }