@opengis/fastify-table 2.0.84 → 2.0.86
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/dist/server/plugins/auth/funcs/authorizeUser.d.ts.map +1 -1
- package/dist/server/plugins/auth/funcs/authorizeUser.js +2 -2
- package/dist/server/plugins/auth/index.js +1 -1
- package/dist/server/routes/auth/controllers/2factor/verify.d.ts.map +1 -1
- package/dist/server/routes/auth/controllers/2factor/verify.js +15 -6
- package/dist/server/templates/pt/recovery-codes-email-template.hbs +13 -0
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorizeUser.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/auth/funcs/authorizeUser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AA4BtD,wBAA8B,aAAa,CACzC,IAAI,EAAE,YAAY,EAClB,GAAG,EAAE,GAAG,EACR,QAAQ,SAAe,EACvB,MAAM,CAAC,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"authorizeUser.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/auth/funcs/authorizeUser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AA4BtD,wBAA8B,aAAa,CACzC,IAAI,EAAE,YAAY,EAClB,GAAG,EAAE,GAAG,EACR,QAAQ,SAAe,EACvB,MAAM,CAAC,EAAE,MAAM,gBA8HhB"}
|
|
@@ -57,7 +57,7 @@ export default async function authorizeUser(user, req, authType = "creds-user",
|
|
|
57
57
|
{};
|
|
58
58
|
await req.session?.save?.();
|
|
59
59
|
const redirectUrl = req.headers?.referer?.match?.(/[?&]redirect=([^&]+)/)?.[1] || "/";
|
|
60
|
-
const twofaEnabled =
|
|
60
|
+
const twofaEnabled = user?.twofa && user.uid && pg;
|
|
61
61
|
const registered = false; // ? check by created/updated date?
|
|
62
62
|
if (req.method === "POST" &&
|
|
63
63
|
(!twofaEnabled || req.session?.secondFactorPassed)) {
|
|
@@ -91,7 +91,7 @@ export default async function authorizeUser(user, req, authType = "creds-user",
|
|
|
91
91
|
}
|
|
92
92
|
// by default, disable 2factor for id.gov.ua auth
|
|
93
93
|
const check = authType === "govid" ? config.auth?.["2factor"]?.govid : true;
|
|
94
|
-
if (
|
|
94
|
+
if (user?.twofa && check) {
|
|
95
95
|
return ("/2factor?redirect=" +
|
|
96
96
|
(href ||
|
|
97
97
|
config.auth?.redirectAfter ||
|
|
@@ -56,7 +56,7 @@ export async function onRequest(req, reply) {
|
|
|
56
56
|
!config.auth?.disableRedirect &&
|
|
57
57
|
!req.url.startsWith(prefix) &&
|
|
58
58
|
!req.url.startsWith("/api") &&
|
|
59
|
-
!req.url.
|
|
59
|
+
!req.url.includes(loginPageUrl) &&
|
|
60
60
|
!req.url.includes(".") &&
|
|
61
61
|
!req.url.includes("@")) {
|
|
62
62
|
return reply.redirect(`${loginPageUrl}` + `?redirect=${req.url}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../../../../server/routes/auth/controllers/2factor/verify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../../../../server/routes/auth/controllers/2factor/verify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AA0BvC;;;;;;;;;;;;;;;;GAgBG;AAEH,wBAA8B,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,YAAY,kBAmEzE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { fileURLToPath } from "url";
|
|
3
|
-
import {
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
4
|
import config from "../../../../../config.js";
|
|
5
5
|
import getTemplate from "../../../../plugins/table/funcs/getTemplate.js";
|
|
6
6
|
import pgClients from "../../../../plugins/pg/pgClients.js";
|
|
@@ -9,6 +9,9 @@ import { verify, enableSecret } from "./providers/totp.js";
|
|
|
9
9
|
import sendNotification from "../../../../plugins/auth/funcs/sendNotification.js";
|
|
10
10
|
const template = "recovery-codes-email-template";
|
|
11
11
|
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
const defaultPt = existsSync(path.join(dirname, `../../../../templates/pt/${template}.hbs`))
|
|
13
|
+
? readFileSync(path.join(dirname, `../../../../templates/pt/${template}.hbs`), "utf8")
|
|
14
|
+
: "Recovery codes: {{{code}}}";
|
|
12
15
|
/**
|
|
13
16
|
* Перевірка двохфакторної авторизації для користувача
|
|
14
17
|
*
|
|
@@ -28,10 +31,10 @@ const dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
28
31
|
*/
|
|
29
32
|
export default async function verifyFunction(req, reply) {
|
|
30
33
|
const { pg = pgClients.client, session = {}, body = {} } = req;
|
|
31
|
-
const { uid, email } = session?.passport?.user || {};
|
|
34
|
+
const { uid, twofa, email } = session?.passport?.user || {};
|
|
32
35
|
// const { nocache = config.local } = query;
|
|
33
36
|
const { code } = body;
|
|
34
|
-
if (!
|
|
37
|
+
if (!twofa) {
|
|
35
38
|
return reply.status(400).send("2fa not enabled");
|
|
36
39
|
}
|
|
37
40
|
if (!config.pg) {
|
|
@@ -54,10 +57,10 @@ export default async function verifyFunction(req, reply) {
|
|
|
54
57
|
from admin.users_social_auth where uid=$1 and social_auth_type='TOTP'`, [uid])
|
|
55
58
|
?.then((el) => el.rows?.[0] || {});
|
|
56
59
|
const customPt = await getTemplate("pt", template);
|
|
57
|
-
const pt = customPt ||
|
|
58
|
-
(await readFile(path.join(dirname, `../../../../../templates/pt/${template}.html`), "utf8"));
|
|
60
|
+
const pt = customPt || defaultPt;
|
|
59
61
|
const html = await handlebars.compile(pt)({
|
|
60
62
|
recoveryCodes,
|
|
63
|
+
code: recoveryCodes,
|
|
61
64
|
domain: `${req.protocol || "https"}://${req.hostname}`,
|
|
62
65
|
});
|
|
63
66
|
await sendNotification({
|
|
@@ -69,9 +72,15 @@ export default async function verifyFunction(req, reply) {
|
|
|
69
72
|
});
|
|
70
73
|
}
|
|
71
74
|
const redirectUrl = req.headers?.referer?.match?.(/[?&]redirect=([^&]+)/)?.[1] || "/";
|
|
72
|
-
return reply.redirect(redirectUrl.startsWith("/") ? redirectUrl : "/");
|
|
75
|
+
// return reply.redirect(redirectUrl.startsWith("/") ? redirectUrl : "/");
|
|
76
|
+
return reply
|
|
77
|
+
.status(200)
|
|
78
|
+
.send({ redirectUrl: redirectUrl.startsWith("/") ? redirectUrl : "/" });
|
|
73
79
|
}
|
|
74
80
|
catch (err) {
|
|
81
|
+
if (err.message === "Невірний код") {
|
|
82
|
+
return reply.status(401).send({ error: err.message, code: 401 });
|
|
83
|
+
}
|
|
75
84
|
return reply.status(500).send(err.toString());
|
|
76
85
|
}
|
|
77
86
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<div style="background:#eee;padding:30px;">
|
|
2
|
+
<div
|
|
3
|
+
style="background:#fff;padding: 15px 20px;width: 550px;border: 1px solid #e3e3e5;border-radius:3px;margin: 0 auto;font: normal 13px/19px Verdana;box-shadow: 0 3px 7px rgba(0,0,0,.1);">
|
|
4
|
+
<h2 style="font:normal 21px/48px Arial;color: #222;text-align:center">
|
|
5
|
+
Коди відновлення на випадок втрати доступу до застосунку для двофакторної аутентифікації порталу {{domain}}
|
|
6
|
+
</h2>
|
|
7
|
+
{{#each recoveryCodes}}
|
|
8
|
+
<p style="width: 400px;margin:0 auto;display: block;background: #4CAF50;color: #fff;font-weight:bold; line-height: 44px;text-align: center;text-decoration: none;border-radius: 3px;text-shadow: 0 1px 3px rgba(0,0,0,.35);border: 1px solid #388E3C;box-shadow: inset 0 1px rgba(255,255,255,.4);">
|
|
9
|
+
{{this}}<hr>
|
|
10
|
+
</p>
|
|
11
|
+
{{/each}}
|
|
12
|
+
</div>
|
|
13
|
+
</div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengis/fastify-table",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.86",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "core-plugins",
|
|
6
6
|
"keywords": [
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"scripts": {
|
|
24
24
|
"prepublishOnly": "npm run build",
|
|
25
25
|
"clean": "tsc -b --clean",
|
|
26
|
-
"build": "tsc -b --clean && tsc && copyfiles server/plugins/grpc/utils/*.proto dist && copyfiles server/migrations/*.sql dist && copyfiles server/templates/**/*.html dist",
|
|
26
|
+
"build": "tsc -b --clean && tsc && copyfiles server/plugins/grpc/utils/*.proto dist && copyfiles server/migrations/*.sql dist && copyfiles server/templates/**/*.html dist && copyfiles server/templates/**/*.hbs dist",
|
|
27
27
|
"prod": "NODE_ENV=production bun dist/server",
|
|
28
28
|
"patch": "npm version patch && git push && npm publish",
|
|
29
29
|
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
|