@volcanicminds/backend 0.2.39 → 0.2.41

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.
@@ -1 +1 @@
1
- {"version":3,"file":"onRequest.js","sourceRoot":"","sources":["../../../lib/hooks/onRequest.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,2CAAmD;AAGnD,MAAM,CAAC,OAAO,GAAG,CAAO,GAAG,EAAE,KAAK,EAAE,EAAE;;IAEpC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,CAAA;IACrC,GAAG,CAAC,IAAI,GAAG,GAAG,EAAE,CAAC,IAAA,gBAAO,EAAC,GAAG,CAAC,CAAA;IAC7B,GAAG,CAAC,UAAU,GAAG,GAAG,EAAE,CAAC,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAA;IACrC,GAAG,CAAC,KAAK,GAAG,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;IAC9D,GAAG,CAAC,OAAO,GAAG,CAAC,CAAO,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,MAAK,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,IAAI,CAAA,CAAC,CAAA;IAGxG,MAAM,IAAI,GAAG,CAAA,MAAA,GAAG,CAAC,OAAO,0CAAE,aAAa,KAAI,EAAE,CAAA;IAC7C,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC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@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../lib/schemas/auth.ts"],"names":[],"mappings":""}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.blockBodySchema = exports.getQueryParamsSchema = void 0;
4
+ exports.getQueryParamsSchema = {
5
+ $id: 'getQueryParamsSchema',
6
+ type: 'object',
7
+ nullable: true,
8
+ properties: {
9
+ page: {
10
+ type: 'number',
11
+ description: 'Page **number** (default 1)'
12
+ },
13
+ pageSize: {
14
+ type: 'number',
15
+ description: 'Page **size** (default 25)'
16
+ },
17
+ sort: {
18
+ type: 'array',
19
+ description: 'Sorting **order** (default ascending).<br/>\
20
+ Otherwise, use the postfix `:desc` or `:asc` (like `&sort=myfield:desc`)',
21
+ items: { type: 'string' }
22
+ }
23
+ }
24
+ };
25
+ exports.blockBodySchema = {
26
+ $id: 'blockBodySchema',
27
+ type: 'object',
28
+ nullable: true,
29
+ properties: {
30
+ reason: { type: 'string' }
31
+ }
32
+ };
33
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../lib/schemas/common.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG;IAClC,GAAG,EAAE,sBAAsB;IAC3B,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,IAAI;IACd,UAAU,EAAE;QACV,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,6BAA6B;SAC3C;QACD,QAAQ,EAAE;YACR,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,4BAA4B;SAC1C;QACD,IAAI,EAAE;YACJ,IAAI,EAAE,OAAO;YACb,WAAW,EACT;iFACyE;YAC3E,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SAC1B;KACF;CACF,CAAA;AAEY,QAAA,eAAe,GAAG;IAC7B,GAAG,EAAE,iBAAiB;IACtB,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,IAAI;IACd,UAAU,EAAE;QACV,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAC3B;CACF,CAAA"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tokenSchema = exports.tokenBodySchema = exports.tokenParamsSchema = void 0;
4
+ exports.tokenParamsSchema = {
5
+ $id: 'tokenParamsSchema',
6
+ type: 'object',
7
+ nullable: true,
8
+ properties: {
9
+ id: {
10
+ type: 'string',
11
+ description: 'Token id'
12
+ }
13
+ }
14
+ };
15
+ exports.tokenBodySchema = {
16
+ $id: 'tokenBodySchema',
17
+ type: 'object',
18
+ nullable: true,
19
+ properties: {
20
+ name: { type: 'string' },
21
+ description: { type: 'string' },
22
+ requiredRoles: { type: 'array', items: { type: 'string' } }
23
+ }
24
+ };
25
+ exports.tokenSchema = {
26
+ $id: 'tokenSchema',
27
+ type: 'object',
28
+ nullable: true,
29
+ properties: {
30
+ id: { type: 'string' },
31
+ _id: { type: 'string' },
32
+ externalId: { type: 'string' },
33
+ name: { type: 'string' },
34
+ description: { type: 'string' },
35
+ token: { type: 'string' },
36
+ roles: { type: 'array', items: { type: 'string' } }
37
+ }
38
+ };
39
+ //# sourceMappingURL=token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token.js","sourceRoot":"","sources":["../../../lib/schemas/token.ts"],"names":[],"mappings":";;;AAAa,QAAA,iBAAiB,GAAG;IAC/B,GAAG,EAAE,mBAAmB;IACxB,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,IAAI;IACd,UAAU,EAAE;QACV,EAAE,EAAE;YACF,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,UAAU;SACxB;KACF;CACF,CAAA;AAEY,QAAA,eAAe,GAAG;IAC7B,GAAG,EAAE,iBAAiB;IACtB,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,IAAI;IACd,UAAU,EAAE;QACV,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACxB,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC/B,aAAa,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;KAC5D;CACF,CAAA;AAEY,QAAA,WAAW,GAAG;IACzB,GAAG,EAAE,aAAa;IAClB,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,IAAI;IACd,UAAU,EAAE;QACV,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACtB,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACvB,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC9B,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACxB,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC/B,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACzB,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;KACpD;CACF,CAAA"}
package/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export {
3
3
  FastifyReply,
4
4
  FastifyRequest,
5
5
  AuthenticatedUser,
6
+ AuthenticatedToken,
6
7
  Role,
7
8
  Data,
8
9
  Roles,
package/index.ts CHANGED
@@ -27,7 +27,7 @@ import fastifyApollo, { fastifyApolloDrainPlugin } from '@as-integrations/fastif
27
27
  import { myContextFunction, MyContext } from './lib/apollo/context'
28
28
  import resolvers from './lib/apollo/resolvers'
29
29
  import typeDefs from './lib/apollo/type-defs'
30
- import { UserManagement } from './types/global'
30
+ import { UserManagement, TokenManagement } from './types/global'
31
31
 
32
32
  global.log = logger
33
33
 
@@ -168,6 +168,9 @@ const start = async (decorators) => {
168
168
  // defaults
169
169
  decorators = {
170
170
  userManager: {
171
+ isValidUser(data: any) {
172
+ throw Error('Not implemented')
173
+ },
171
174
  createUser(data: any) {
172
175
  throw Error('Not implemented')
173
176
  },
@@ -210,16 +213,54 @@ const start = async (decorators) => {
210
213
  resetPassword(user: any, password: string) {
211
214
  throw Error('Not implemented')
212
215
  },
213
- enableUserById(id: string) {
216
+ blockUserById(id: string, reason: string) {
214
217
  throw Error('Not implemented')
215
218
  },
216
- disableUserById(id: string) {
219
+ unblockUserById(data: any) {
217
220
  throw Error('Not implemented')
218
221
  },
219
- isValidUser(data: any) {
222
+ countQuery(data: any) {
223
+ throw Error('Not implemented')
224
+ },
225
+ findQuery(data: any) {
220
226
  throw Error('Not implemented')
221
227
  }
222
228
  } as UserManagement,
229
+ tokenManager: {
230
+ isValidToken(data: any) {
231
+ throw Error('Not implemented')
232
+ },
233
+ createToken(data: any) {
234
+ throw Error('Not implemented')
235
+ },
236
+ resetExternalId(id: string) {
237
+ throw Error('Not implemented')
238
+ },
239
+ updateTokenById(id: string, token: any) {
240
+ throw Error('Not implemented')
241
+ },
242
+ retrieveTokenById(id: string) {
243
+ throw Error('Not implemented')
244
+ },
245
+ retrieveTokenByExternalId(id: string) {
246
+ throw Error('Not implemented')
247
+ },
248
+ blockTokenById(id: string, reason: string) {
249
+ throw Error('Not implemented')
250
+ },
251
+ unblockTokenById(id: string) {
252
+ throw Error('Not implemented')
253
+ },
254
+ countQuery(data: any) {
255
+ throw Error('Not implemented')
256
+ },
257
+ findQuery(data: any) {
258
+ throw Error('Not implemented')
259
+ },
260
+ removeTokenById(id: string) {
261
+ throw Error('Not implemented')
262
+ }
263
+ } as TokenManagement,
223
264
  ...decorators
224
265
  }
225
266
 
@@ -252,13 +293,15 @@ export {
252
293
  FastifyReply,
253
294
  FastifyRequest,
254
295
  AuthenticatedUser,
296
+ AuthenticatedToken,
255
297
  Role,
256
298
  Data,
257
299
  Roles,
258
300
  Route,
259
301
  RouteConfig,
260
302
  ConfiguredRoute,
261
- UserManagement
303
+ UserManagement,
304
+ TokenManagement
262
305
  } from './types/global'
263
306
 
264
307
  /**
@@ -56,6 +56,21 @@ export async function unregister(req: FastifyRequest, reply: FastifyReply) {
56
56
  return { ok: true }
57
57
  }
58
58
 
59
+ export async function validatePassword(req: FastifyRequest, reply: FastifyReply) {
60
+ const { password } = req.data()
61
+
62
+ if (!password) {
63
+ return reply.status(400).send(Error('Password cannot be null'))
64
+ }
65
+
66
+ const match = regExp.password.test(password)
67
+ if (!match) {
68
+ return reply.status(400).send(Error('Password is not valid'))
69
+ }
70
+
71
+ return { ok: match }
72
+ }
73
+
59
74
  export async function changePassword(req: FastifyRequest, reply: FastifyReply) {
60
75
  const { email, oldPassword, newPassword1, newPassword2 } = req.data()
61
76
 
@@ -72,6 +72,32 @@ module.exports = {
72
72
  }
73
73
  }
74
74
  },
75
+ {
76
+ method: 'POST',
77
+ path: '/validate-password',
78
+ roles: [],
79
+ handler: 'auth.validatePassword',
80
+ middlewares: [],
81
+ config: {
82
+ title: 'Validate password',
83
+ description: 'Validate password if valid and usable',
84
+ body: {
85
+ type: 'object',
86
+ properties: {
87
+ password: { type: 'string' }
88
+ }
89
+ },
90
+ response: {
91
+ 200: {
92
+ description: 'Default response',
93
+ type: 'object',
94
+ properties: {
95
+ ok: { type: 'boolean' }
96
+ }
97
+ }
98
+ }
99
+ }
100
+ },
75
101
  {
76
102
  method: 'POST',
77
103
  path: '/change-password',
@@ -253,6 +279,7 @@ module.exports = {
253
279
  }
254
280
  }
255
281
  },
282
+ body: { $ref: 'blockBodySchema' },
256
283
  response: {
257
284
  200: {
258
285
  description: 'Default response',
@@ -0,0 +1,104 @@
1
+ import { FastifyReply, FastifyRequest } from 'fastify'
2
+
3
+ export async function count(req: FastifyRequest, reply: FastifyReply) {
4
+ return await req.server['tokenManager'].countQuery(req.data())
5
+ }
6
+
7
+ export async function find(req: FastifyRequest, reply: FastifyReply) {
8
+ const { headers, records } = await req.server['tokenManager'].findQuery(req.data())
9
+ return reply.type('application/json').headers(headers).send(records)
10
+ }
11
+
12
+ export async function findOne(req: FastifyRequest, reply: FastifyReply) {
13
+ const { id } = req.parameters()
14
+
15
+ const token = await req.server['tokenManager'].retrieveTokenById(id)
16
+ return token || reply.status(404).send()
17
+ }
18
+
19
+ export async function create(req: FastifyRequest, reply: FastifyReply) {
20
+ const data = req.data()
21
+
22
+ if (!data.name) {
23
+ return reply.status(404).send(Error('Token name not valid'))
24
+ }
25
+
26
+ // public is the default
27
+ const publicRole = global.roles?.public?.code || 'public'
28
+ data.roles = (data.requiredRoles || []).map((r) => global.roles[r]?.code).filter((r) => !!r)
29
+ if (!data.roles.includes(publicRole)) {
30
+ data.roles.push(publicRole)
31
+ }
32
+
33
+ let token = await req.server['tokenManager'].createToken(data)
34
+ if (!token || !token.getId() || !token.externalId) {
35
+ return reply.status(400).send(Error('Token not registered'))
36
+ }
37
+
38
+ const bearerToken = await reply.jwtSign(
39
+ { sub: token.externalId },
40
+ {
41
+ sign: { expiresIn: undefined }
42
+ }
43
+ )
44
+ if (!bearerToken) {
45
+ return reply.status(400).send(Error('Token not signed'))
46
+ }
47
+
48
+ token = await req.server['tokenManager'].updateTokenById(token.getId(), { token: bearerToken })
49
+ return token
50
+ }
51
+
52
+ export async function remove(req: FastifyRequest, reply: FastifyReply) {
53
+ const { id } = req.parameters()
54
+ if (!id) {
55
+ return reply.status(404).send()
56
+ }
57
+
58
+ let token = await req.server['tokenManager'].retrieveTokenById(id)
59
+ if (!token) {
60
+ return reply.status(403).send(Error('Token not found'))
61
+ }
62
+
63
+ token = await req.server['tokenManager'].removeTokenById(id)
64
+ return { ok: true }
65
+ }
66
+
67
+ export async function update(req: FastifyRequest, reply: FastifyReply) {
68
+ const { id } = req.parameters()
69
+ if (!id) {
70
+ return reply.status(404).send()
71
+ }
72
+
73
+ const token = await req.server['tokenManager'].retrieveTokenById(id)
74
+ if (!token || !token.getId()) {
75
+ return reply.status(404).send()
76
+ }
77
+
78
+ const data = req.data() || {}
79
+ return req.server['tokenManager'].updateTokenById(token.getId(), data)
80
+ }
81
+
82
+ export async function block(req: FastifyRequest, reply: FastifyReply) {
83
+ if (!req.hasRole(roles.admin) && !req.hasRole(roles.backoffice)) {
84
+ return reply.status(403).send({ statusCode: 403, code: 'ROLE_NOT_ALLOWED', message: 'Not allowed to block a user' })
85
+ }
86
+
87
+ const { id: userId } = req.parameters()
88
+ const { reason } = req.data()
89
+
90
+ const user = await req.server['tokenManager'].blockTokenById(userId, reason)
91
+ return { ok: !!user.getId() }
92
+ }
93
+
94
+ export async function unblock(req: FastifyRequest, reply: FastifyReply) {
95
+ if (!req.hasRole(roles.admin) && !req.hasRole(roles.backoffice)) {
96
+ return reply
97
+ .status(403)
98
+ .send({ statusCode: 403, code: 'ROLE_NOT_ALLOWED', message: 'Not allowed to unblock a user' })
99
+ }
100
+
101
+ const { id: userId } = req.parameters()
102
+ const user = await req.server['tokenManager'].unblockTokenById(userId)
103
+ return { ok: !!user.getId() }
104
+ }
@@ -0,0 +1,168 @@
1
+ module.exports = {
2
+ config: {
3
+ title: 'Integration token functions',
4
+ description: 'Integration token functions',
5
+ controller: 'controller',
6
+ tags: ['token'],
7
+ deprecated: false,
8
+ version: false,
9
+ enable: true
10
+ },
11
+ routes: [
12
+ {
13
+ method: 'GET',
14
+ path: '/',
15
+ roles: [roles.admin, roles.backoffice],
16
+ handler: 'token.find',
17
+ middlewares: [],
18
+ config: {
19
+ title: 'Find tokens',
20
+ description: 'Get tokens list',
21
+ query: { $ref: 'getQueryParamsSchema' },
22
+ response: {
23
+ 200: {
24
+ description: 'Default response',
25
+ type: 'array',
26
+ items: { $ref: 'tokenSchema#' }
27
+ }
28
+ }
29
+ }
30
+ },
31
+ {
32
+ method: 'GET',
33
+ path: '/count',
34
+ roles: [roles.admin, roles.backoffice],
35
+ handler: 'token.count',
36
+ middlewares: [],
37
+ config: {
38
+ title: 'Count tokens',
39
+ description: 'Count tokens',
40
+ response: {
41
+ 200: {
42
+ description: 'Default response',
43
+ type: 'number'
44
+ }
45
+ }
46
+ }
47
+ },
48
+ {
49
+ method: 'GET',
50
+ path: '/:id',
51
+ roles: [roles.admin, roles.backoffice],
52
+ handler: 'token.findOne',
53
+ middlewares: [],
54
+ config: {
55
+ title: 'Find token',
56
+ description: 'Get token by id',
57
+ params: { $ref: 'tokenParamsSchema#' },
58
+ response: {
59
+ 200: {
60
+ description: 'Default response',
61
+ $ref: 'tokenSchema#'
62
+ }
63
+ }
64
+ }
65
+ },
66
+ {
67
+ method: 'POST',
68
+ path: '/',
69
+ roles: [roles.admin, roles.backoffice],
70
+ handler: 'token.create',
71
+ middlewares: ['global.isAuthenticated'],
72
+ config: {
73
+ title: 'Create new token',
74
+ description: 'Create a new token',
75
+ body: { $ref: 'tokenBodySchema' },
76
+ response: {
77
+ 200: {
78
+ description: 'Default response',
79
+ $ref: 'tokenSchema#'
80
+ }
81
+ }
82
+ }
83
+ },
84
+ {
85
+ method: 'PUT',
86
+ path: '/:id',
87
+ roles: [roles.admin, roles.backoffice],
88
+ handler: 'token.update',
89
+ middlewares: ['global.isAuthenticated'],
90
+ config: {
91
+ title: 'Update existing token',
92
+ description: 'Update an existing token',
93
+ params: { $ref: 'tokenParamsSchema#' },
94
+ body: { $ref: 'tokenBodySchema' },
95
+ response: {
96
+ 200: {
97
+ description: 'Default response',
98
+ $ref: 'tokenSchema#'
99
+ }
100
+ }
101
+ }
102
+ },
103
+ {
104
+ method: 'DELETE',
105
+ path: '/:id',
106
+ roles: [roles.admin, roles.backoffice],
107
+ handler: 'token.remove',
108
+ middlewares: ['global.isAuthenticated'],
109
+ config: {
110
+ title: 'Unregister existing token (actually disables it)',
111
+ description: 'Unregister an existing token (actually disables it)',
112
+ params: { $ref: 'tokenParamsSchema#' },
113
+ response: {
114
+ 200: {
115
+ description: 'Default response',
116
+ type: 'object',
117
+ properties: {
118
+ ok: { type: 'boolean' }
119
+ }
120
+ }
121
+ }
122
+ }
123
+ },
124
+ {
125
+ method: 'POST',
126
+ path: '/block/:id',
127
+ roles: [roles.admin, roles.backoffice],
128
+ handler: 'token.block',
129
+ middlewares: ['global.isAuthenticated'],
130
+ config: {
131
+ title: 'Block a token by id',
132
+ description: 'Block a token by id',
133
+ params: { $ref: 'tokenParamsSchema#' },
134
+ body: { $ref: 'blockBodySchema' },
135
+ response: {
136
+ 200: {
137
+ description: 'Default response',
138
+ type: 'object',
139
+ properties: {
140
+ ok: { type: 'boolean' }
141
+ }
142
+ }
143
+ }
144
+ }
145
+ },
146
+ {
147
+ method: 'POST',
148
+ path: '/unblock/:id',
149
+ roles: [roles.admin, roles.backoffice],
150
+ handler: 'token.unblock',
151
+ middlewares: ['global.isAuthenticated'],
152
+ config: {
153
+ title: 'Unblock a token by id',
154
+ description: 'Unblock a token by id',
155
+ params: { $ref: 'tokenParamsSchema#' },
156
+ response: {
157
+ 200: {
158
+ description: 'Default response',
159
+ type: 'object',
160
+ properties: {
161
+ ok: { type: 'boolean' }
162
+ }
163
+ }
164
+ }
165
+ }
166
+ }
167
+ ]
168
+ }
@@ -1,5 +1,5 @@
1
1
  import { getParams, getData } from '../util/common'
2
- import { AuthenticatedUser, Role } from '../../types/global'
2
+ import { AuthenticatedUser, AuthenticatedToken, Role } from '../../types/global'
3
3
 
4
4
  module.exports = async (req, reply) => {
5
5
  // request enrichment
@@ -11,24 +11,38 @@ module.exports = async (req, reply) => {
11
11
 
12
12
  // authorization check
13
13
  const auth = req.headers?.authorization || ''
14
- const [prefix, token] = auth.split(' ')
14
+ const [prefix, bearerToken] = auth.split(' ')
15
15
  const isRoutePublic = (req.routeConfig.requiredRoles || []).some((role: Role) => role.code === roles.public.code)
16
16
 
17
- if (prefix === 'Bearer' && token != null) {
18
- let user: AuthenticatedUser = {} as AuthenticatedUser
17
+ if (prefix === 'Bearer' && bearerToken != null) {
18
+ let user: null | AuthenticatedUser = null
19
+ let token: null | AuthenticatedToken = null
20
+
19
21
  try {
20
- const tokenData = reply.server.jwt.verify(token)
22
+ const tokenData = reply.server.jwt.verify(bearerToken)
21
23
  user = await req.server['userManager'].retrieveUserByExternalId(tokenData?.sub)
22
24
  if (!user) {
25
+ token = await req.server['tokenManager'].retrieveTokenByExternalId(tokenData?.sub)
26
+ }
27
+ if (!user && !token) {
23
28
  return reply.status(404).send({ statusCode: 404, code: 'USER_NOT_FOUND', message: 'User not found' })
24
29
  }
25
- const isValid = await req.server['userManager'].isValidUser(user)
26
- if (!isValid) {
27
- return reply.status(404).send({ statusCode: 404, code: 'USER_NOT_VALID', message: 'User not valid' })
30
+ if (user) {
31
+ const isValid = await req.server['userManager'].isValidUser(user)
32
+ if (!isValid) {
33
+ return reply.status(404).send({ statusCode: 404, code: 'USER_NOT_VALID', message: 'User not valid' })
34
+ }
35
+ // ok, we have the full user here
36
+ req.user = user
37
+ }
38
+ if (token) {
39
+ const isValid = await req.server['tokenManager'].isValidToken(token)
40
+ if (!isValid) {
41
+ return reply.status(404).send({ statusCode: 404, code: 'TOKEN_NOT_VALID', message: 'Token not valid' })
42
+ }
43
+ // ok, we have the full user here
44
+ req.token = token
28
45
  }
29
-
30
- // ok, we have the full user here
31
- req.user = user
32
46
  } catch (error) {
33
47
  if (!isRoutePublic) {
34
48
  throw error
@@ -38,8 +52,10 @@ module.exports = async (req, reply) => {
38
52
 
39
53
  if (req.routeConfig.requiredRoles?.length > 0) {
40
54
  const { method = '', url = '', requiredRoles } = req.routeConfig
41
- const userRoles: string[] = req.user?.roles?.map((code) => code) || [roles.public?.code || 'public']
42
- const resolvedRoles = userRoles.length > 0 ? requiredRoles.filter((r) => userRoles.includes(r.code)) : []
55
+ const authRoles: string[] = ((req.user?.roles || req.token?.roles)?.map((code) => code) as string[]) || [
56
+ roles.public?.code || 'public'
57
+ ]
58
+ const resolvedRoles = authRoles.length > 0 ? requiredRoles.filter((r) => authRoles.includes(r.code)) : []
43
59
 
44
60
  if (!resolvedRoles.length) {
45
61
  log.w && log.warn(`Not allowed to call ${method.toUpperCase()} ${url}`)
File without changes
@@ -0,0 +1,31 @@
1
+ export const getQueryParamsSchema = {
2
+ $id: 'getQueryParamsSchema',
3
+ type: 'object',
4
+ nullable: true,
5
+ properties: {
6
+ page: {
7
+ type: 'number',
8
+ description: 'Page **number** (default 1)'
9
+ },
10
+ pageSize: {
11
+ type: 'number',
12
+ description: 'Page **size** (default 25)'
13
+ },
14
+ sort: {
15
+ type: 'array',
16
+ description:
17
+ 'Sorting **order** (default ascending).<br/>\
18
+ Otherwise, use the postfix `:desc` or `:asc` (like `&sort=myfield:desc`)',
19
+ items: { type: 'string' }
20
+ }
21
+ }
22
+ }
23
+
24
+ export const blockBodySchema = {
25
+ $id: 'blockBodySchema',
26
+ type: 'object',
27
+ nullable: true,
28
+ properties: {
29
+ reason: { type: 'string' }
30
+ }
31
+ }