sumba 1.1.8 → 1.1.9
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/lib/check-user-id.js +7 -5
- package/package.json +1 -1
- package/plugin/factory.js +19 -14
package/lib/check-user-id.js
CHANGED
|
@@ -29,7 +29,7 @@ async function mergeSetting (req) {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
async function checkUserId (req, reply, source) {
|
|
32
|
-
const { isEmpty, camelCase, get } = this.lib._
|
|
32
|
+
const { merge, isEmpty, camelCase, get } = this.lib._
|
|
33
33
|
const { routePath } = this.app.waibu
|
|
34
34
|
|
|
35
35
|
const webApp = get(req, 'routeOptions.config.webApp', 'waibu')
|
|
@@ -65,19 +65,21 @@ async function checkUserId (req, reply, source) {
|
|
|
65
65
|
await setUser.call(this, req)
|
|
66
66
|
return
|
|
67
67
|
}
|
|
68
|
+
const silentOnError = this.config.auth[webApp].silentOnError ?? this.config.auth.common.silentOnError
|
|
69
|
+
const payload = silentOnError ? { noContent: true } : undefined
|
|
68
70
|
const authMethods = this.config.auth[webApp].methods ?? []
|
|
69
|
-
if (isEmpty(authMethods)) throw this.error('noAuthMethod', { statusCode: 500 })
|
|
71
|
+
if (isEmpty(authMethods)) throw this.error('noAuthMethod', merge({ statusCode: 500 }, payload))
|
|
70
72
|
let success
|
|
71
73
|
for (const m of authMethods) {
|
|
72
74
|
const handler = this[camelCase(`verify ${m}`)]
|
|
73
|
-
if (!handler) throw this.error('invalidAuthMethod%s', m, { statusCode: 500 })
|
|
74
|
-
const check = await handler(req, reply, source)
|
|
75
|
+
if (!handler) throw this.error('invalidAuthMethod%s', m, merge({ statusCode: 500 }, payload))
|
|
76
|
+
const check = await handler(req, reply, source, payload)
|
|
75
77
|
if (check) {
|
|
76
78
|
success = check
|
|
77
79
|
break
|
|
78
80
|
}
|
|
79
81
|
}
|
|
80
|
-
if (!success) throw this.error('accessDeniedNoAuth', { statusCode: 403 })
|
|
82
|
+
if (!success) throw this.error('accessDeniedNoAuth', merge({ statusCode: 403 }, payload))
|
|
81
83
|
await mergeSetting.call(this, req)
|
|
82
84
|
}
|
|
83
85
|
}
|
package/package.json
CHANGED
package/plugin/factory.js
CHANGED
|
@@ -69,10 +69,12 @@ async function factory (pkgName) {
|
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
71
|
waibuRestApi: {
|
|
72
|
-
methods: ['basic', 'apiKey', 'jwt']
|
|
72
|
+
methods: ['basic', 'apiKey', 'jwt'],
|
|
73
|
+
silentOnError: false
|
|
73
74
|
},
|
|
74
75
|
waibuMpa: {
|
|
75
|
-
methods: ['session']
|
|
76
|
+
methods: ['session'],
|
|
77
|
+
silentOnError: false
|
|
76
78
|
},
|
|
77
79
|
waibuStatic: {
|
|
78
80
|
methods: ['basic', 'apiKey', 'jwt'],
|
|
@@ -80,7 +82,8 @@ async function factory (pkgName) {
|
|
|
80
82
|
useUtf8: true,
|
|
81
83
|
realm: 'Protected Area',
|
|
82
84
|
warningMessage: 'Please authenticate yourself, thank you!'
|
|
83
|
-
}
|
|
85
|
+
},
|
|
86
|
+
silentOnError: false
|
|
84
87
|
}
|
|
85
88
|
},
|
|
86
89
|
redirect: {
|
|
@@ -175,7 +178,7 @@ async function factory (pkgName) {
|
|
|
175
178
|
return output
|
|
176
179
|
}
|
|
177
180
|
|
|
178
|
-
verifySession = async (req, reply, source) => {
|
|
181
|
+
verifySession = async (req, reply, source, payload) => {
|
|
179
182
|
const { getUser } = this
|
|
180
183
|
const { routePath } = this.app.waibu
|
|
181
184
|
|
|
@@ -189,7 +192,8 @@ async function factory (pkgName) {
|
|
|
189
192
|
throw this.error('_redirect', { redirect: redir })
|
|
190
193
|
}
|
|
191
194
|
|
|
192
|
-
verifyApiKey = async (req, reply, source) => {
|
|
195
|
+
verifyApiKey = async (req, reply, source, payload) => {
|
|
196
|
+
const { merge } = this.lib._
|
|
193
197
|
const { isMd5, hash } = this.app.bajoExtra
|
|
194
198
|
const { getUser } = this
|
|
195
199
|
const { recordFind } = this.app.dobo
|
|
@@ -199,16 +203,16 @@ async function factory (pkgName) {
|
|
|
199
203
|
token = await hash(token)
|
|
200
204
|
const query = { token }
|
|
201
205
|
const rows = await recordFind('SumbaUser', { query }, { req, noHook: true })
|
|
202
|
-
if (rows.length === 0) throw this.error('invalidKey', { statusCode: 401 })
|
|
203
|
-
if (rows[0].status !== 'ACTIVE') throw this.error('userInactive', { details: [{ field: 'status', error: 'inactive' }], statusCode: 401 })
|
|
206
|
+
if (rows.length === 0) throw this.error('invalidKey', merge({ statusCode: 401 }, payload))
|
|
207
|
+
if (rows[0].status !== 'ACTIVE') throw this.error('userInactive', merge({ details: [{ field: 'status', error: 'inactive' }], statusCode: 401 }, payload))
|
|
204
208
|
req.user = await getUser(rows[0])
|
|
205
209
|
return true
|
|
206
210
|
}
|
|
207
211
|
|
|
208
|
-
verifyBasic = async (req, reply, source) => {
|
|
212
|
+
verifyBasic = async (req, reply, source, payload) => {
|
|
209
213
|
const { getUserFromUsernamePassword } = this
|
|
210
214
|
const { getUser } = this
|
|
211
|
-
const { isEmpty } = this.lib._
|
|
215
|
+
const { isEmpty, merge } = this.lib._
|
|
212
216
|
|
|
213
217
|
const setHeader = async (setting, reply) => {
|
|
214
218
|
const { isString } = this.lib._
|
|
@@ -242,16 +246,16 @@ async function factory (pkgName) {
|
|
|
242
246
|
await setHeader(setting, reply)
|
|
243
247
|
return err.message
|
|
244
248
|
}
|
|
245
|
-
throw err
|
|
249
|
+
throw merge(err, payload)
|
|
246
250
|
}
|
|
247
251
|
return true
|
|
248
252
|
}
|
|
249
253
|
|
|
250
|
-
verifyJwt = async (req, reply, source) => {
|
|
254
|
+
verifyJwt = async (req, reply, source, payload) => {
|
|
251
255
|
const { importPkg } = this.app.bajo
|
|
252
256
|
const { recordGet } = this.app.dobo
|
|
253
257
|
const { getUser } = this
|
|
254
|
-
const { isEmpty } = this.lib._
|
|
258
|
+
const { isEmpty, merge } = this.lib._
|
|
255
259
|
|
|
256
260
|
const fastJwt = await importPkg('bajoExtra:fast-jwt')
|
|
257
261
|
const { createVerifier } = fastJwt
|
|
@@ -269,10 +273,11 @@ async function factory (pkgName) {
|
|
|
269
273
|
if (!rec) throw this.error('invalidToken', { statusCode: 401 })
|
|
270
274
|
if (rec.status !== 'ACTIVE') throw this.error('userInactive', { details: [{ field: 'status', error: 'inactive' }], statusCode: 401 })
|
|
271
275
|
req.user = await getUser(rec)
|
|
272
|
-
return true
|
|
273
276
|
} catch (err) {
|
|
274
|
-
|
|
277
|
+
merge(err, payload)
|
|
278
|
+
throw err
|
|
275
279
|
}
|
|
280
|
+
return true
|
|
276
281
|
}
|
|
277
282
|
|
|
278
283
|
checkPathsByTeam = ({ paths = [], method = 'GET', teams = [], guards = [] }) => {
|