@qelos/plugin-play 3.0.2 → 3.0.3
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 +2 -2
- package/src/authentication.ts +46 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qelos/plugin-play",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "Play a plugin for Qelos!",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@fastify/cookie": "^8.3.0",
|
|
20
20
|
"@fastify/static": "^6.5.0",
|
|
21
21
|
"@qelos/sdk": "^3.0.1",
|
|
22
|
-
"@qelos/web-sdk": "^3.0.
|
|
22
|
+
"@qelos/web-sdk": "^3.0.3",
|
|
23
23
|
"fastify": "^4.3.0",
|
|
24
24
|
"jsonwebtoken": "^8.5.1",
|
|
25
25
|
"undici": "^5.8.0"
|
package/src/authentication.ts
CHANGED
|
@@ -260,19 +260,53 @@ export function getCallbackRoute(): RouteOptions {
|
|
|
260
260
|
}
|
|
261
261
|
|
|
262
262
|
export function getFrontendAuthorizationRoute(): RouteOptions {
|
|
263
|
+
let standaloneAuthorize: (reply) => Promise<any> = async () => {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
263
266
|
if (config.qelosUrl) {
|
|
264
|
-
onFrontendAuthorization(async ({returnUrl, user, tenant}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
267
|
+
onFrontendAuthorization(async ({returnUrl, user, tenant}) => {
|
|
268
|
+
try {
|
|
269
|
+
const draft = await getSdk().drafts.getDraft(returnUrl, `${tenant.sub}.${user.email}`);
|
|
270
|
+
if (draft && draft.contextData) {
|
|
271
|
+
return {
|
|
272
|
+
code: draft.contextData.code,
|
|
273
|
+
token: jwt.sign({code: draft.contextData, user, tenant}, config.accessTokenSecret, {expiresIn: '30min'}),
|
|
274
|
+
}
|
|
270
275
|
}
|
|
276
|
+
} catch {
|
|
277
|
+
//
|
|
271
278
|
}
|
|
272
279
|
return;
|
|
273
280
|
});
|
|
281
|
+
|
|
282
|
+
if (config.dev) {
|
|
283
|
+
standaloneAuthorize = async (reply) => {
|
|
284
|
+
const [fullUser] = await getSdk().users.getList({exact: true, email: config.qelosUsername});
|
|
285
|
+
const user = {
|
|
286
|
+
_id: fullUser._id,
|
|
287
|
+
email: fullUser.email,
|
|
288
|
+
firstName: fullUser.firstName,
|
|
289
|
+
lastName: fullUser.lastName,
|
|
290
|
+
roles: fullUser.roles
|
|
291
|
+
}
|
|
292
|
+
const tenant = {
|
|
293
|
+
sub: user._id,
|
|
294
|
+
identifier: user.email
|
|
295
|
+
};
|
|
296
|
+
reply.setCookie('token_default', jwt.sign({
|
|
297
|
+
code: 'default',
|
|
298
|
+
user,
|
|
299
|
+
tenant
|
|
300
|
+
}, config.accessTokenSecret, {expiresIn: '30min'}));
|
|
301
|
+
return {
|
|
302
|
+
user,
|
|
303
|
+
tenant
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
}
|
|
274
307
|
}
|
|
275
308
|
|
|
309
|
+
|
|
276
310
|
return {
|
|
277
311
|
method: 'POST',
|
|
278
312
|
url: manifest.authorizeUrl,
|
|
@@ -298,8 +332,12 @@ export function getFrontendAuthorizationRoute(): RouteOptions {
|
|
|
298
332
|
}
|
|
299
333
|
}
|
|
300
334
|
}
|
|
301
|
-
|
|
302
|
-
|
|
335
|
+
const response = await standaloneAuthorize(reply);
|
|
336
|
+
if (!response) {
|
|
337
|
+
reply.statusCode = 401;
|
|
338
|
+
return notAuthorized;
|
|
339
|
+
}
|
|
340
|
+
return response;
|
|
303
341
|
}
|
|
304
342
|
}
|
|
305
343
|
}
|