@x-sls/google-auth 1.0.2 → 1.1.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/package.json +1 -1
- package/src/handlers.js +15 -3
- package/src/index.js +2 -2
package/package.json
CHANGED
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
|
-
|
|
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:
|
|
111
|
+
body: JSON.stringify({ error: error.message })
|
|
100
112
|
}
|
|
101
113
|
}
|
|
102
114
|
}
|