@adminforth/two-factors-auth 4.2.4 → 4.3.1

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/build.log CHANGED
@@ -17,5 +17,5 @@ custom/tsconfig.json
17
17
  custom/use2faApi.ts
18
18
  custom/utils.js
19
19
 
20
- sent 288,176 bytes received 248 bytes 576,848.00 bytes/sec
21
- total size is 287,203 speedup is 1.00
20
+ sent 288,126 bytes received 248 bytes 576,748.00 bytes/sec
21
+ total size is 287,166 speedup is 1.00
@@ -249,8 +249,7 @@ async function sendCode (value) {
249
249
  method: 'POST',
250
250
  path: '/plugin/twofa/confirmLogin',
251
251
  body: {
252
- code: value,
253
- secret: totp.value.newSecret,
252
+ code: value
254
253
  }
255
254
  })
256
255
  if (resp.allowedLogin) {
@@ -249,8 +249,7 @@ async function sendCode (value) {
249
249
  method: 'POST',
250
250
  path: '/plugin/twofa/confirmLogin',
251
251
  body: {
252
- code: value,
253
- secret: totp.value.newSecret,
252
+ code: value
254
253
  }
255
254
  })
256
255
  if (resp.allowedLogin) {
@@ -7,18 +7,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { parseBody } from "adminforth";
11
+ import { registrationOptionsBodySchema, finishRegistrationBodySchema, deletePasskeyBodySchema, renamePasskeyBodySchema, resolveVerifyAutoBodySchema, } from "./validation.js";
10
12
  export function registerPasskeyEndpoints(server, handlers) {
11
13
  server.endpoint({
12
14
  method: 'POST',
13
15
  path: `/plugin/passkeys/registrationOptions`,
14
16
  noAuth: false,
15
- handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response, cookies, headers }) { return handlers.createRegistrationOptions({ body, adminUser, response, cookies, headers }); }),
17
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response, cookies, headers }) {
18
+ const parsed = parseBody(registrationOptionsBodySchema, body, response);
19
+ if ('error' in parsed)
20
+ return parsed.error;
21
+ return handlers.createRegistrationOptions({ body, adminUser, response, cookies, headers });
22
+ }),
16
23
  });
17
24
  server.endpoint({
18
25
  method: 'POST',
19
26
  path: `/plugin/passkeys/finishRegistration`,
20
27
  noAuth: false,
21
- handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, cookies }) { return handlers.finishRegistration({ body, adminUser, cookies }); }),
28
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, cookies, response }) {
29
+ const parsed = parseBody(finishRegistrationBodySchema, body, response);
30
+ if ('error' in parsed)
31
+ return parsed.error;
32
+ return handlers.finishRegistration({ body, adminUser, cookies });
33
+ }),
22
34
  });
23
35
  server.endpoint({
24
36
  method: 'POST',
@@ -36,13 +48,23 @@ export function registerPasskeyEndpoints(server, handlers) {
36
48
  method: 'DELETE',
37
49
  path: `/plugin/passkeys/deletePasskey`,
38
50
  noAuth: false,
39
- handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser }) { return handlers.deletePasskey({ body, adminUser }); }),
51
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response }) {
52
+ const parsed = parseBody(deletePasskeyBodySchema, body, response);
53
+ if ('error' in parsed)
54
+ return parsed.error;
55
+ return handlers.deletePasskey({ body, adminUser });
56
+ }),
40
57
  });
41
58
  server.endpoint({
42
59
  method: 'POST',
43
60
  path: `/plugin/passkeys/renamePasskey`,
44
61
  noAuth: false,
45
- handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser }) { return handlers.renamePasskey({ body, adminUser }); }),
62
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response }) {
63
+ const parsed = parseBody(renamePasskeyBodySchema, body, response);
64
+ if ('error' in parsed)
65
+ return parsed.error;
66
+ return handlers.renamePasskey({ body, adminUser });
67
+ }),
46
68
  });
47
69
  server.endpoint({
48
70
  method: 'POST',
@@ -54,6 +76,11 @@ export function registerPasskeyEndpoints(server, handlers) {
54
76
  method: 'POST',
55
77
  path: `/plugin/passkeys/resolveVerifyAuto`,
56
78
  noAuth: false,
57
- handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response, cookies, headers }) { return handlers.resolveVerifyAuto({ body, adminUser, response, cookies, headers }); }),
79
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response, cookies, headers }) {
80
+ const parsed = parseBody(resolveVerifyAutoBodySchema, body, response);
81
+ if ('error' in parsed)
82
+ return parsed.error;
83
+ return handlers.resolveVerifyAuto({ body, adminUser, response, cookies, headers });
84
+ }),
58
85
  });
59
86
  }
@@ -7,6 +7,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { parseBody } from "adminforth";
11
+ import { confirmLoginBodySchema, confirmLoginWithPasskeyBodySchema, verifyTotpBodySchema, } from "./validation.js";
10
12
  export function registerTwoFaEndpoints(server, handlers) {
11
13
  server.endpoint({
12
14
  method: 'POST',
@@ -18,13 +20,23 @@ export function registerTwoFaEndpoints(server, handlers) {
18
20
  method: 'POST',
19
21
  path: `/plugin/twofa/confirmLogin`,
20
22
  noAuth: true,
21
- handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response, cookies, headers }) { return handlers.confirmLogin({ body, response, cookies, headers }); }),
23
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response, cookies, headers }) {
24
+ const parsed = parseBody(confirmLoginBodySchema, body, response);
25
+ if ('error' in parsed)
26
+ return parsed.error;
27
+ return handlers.confirmLogin({ body, response, cookies, headers });
28
+ }),
22
29
  });
23
30
  server.endpoint({
24
31
  method: 'POST',
25
32
  path: `/plugin/twofa/confirmLoginWithPasskey`,
26
33
  noAuth: true,
27
- handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response, cookies, headers, requestUrl, query }) { return handlers.confirmLoginWithPasskey({ body, response, cookies, headers, requestUrl, query }); }),
34
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response, cookies, headers, requestUrl, query }) {
35
+ const parsed = parseBody(confirmLoginWithPasskeyBodySchema, body, response);
36
+ if ('error' in parsed)
37
+ return parsed.error;
38
+ return handlers.confirmLoginWithPasskey({ body, response, cookies, headers, requestUrl, query });
39
+ }),
28
40
  });
29
41
  server.endpoint({
30
42
  method: "GET",
@@ -41,6 +53,11 @@ export function registerTwoFaEndpoints(server, handlers) {
41
53
  method: 'POST',
42
54
  path: `/plugin/twofa/verify`,
43
55
  noAuth: false,
44
- handler: (_a) => __awaiter(this, [_a], void 0, function* ({ adminUser, body }) { return handlers.verifyTotp({ adminUser, body }); }),
56
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ adminUser, body, response }) {
57
+ const parsed = parseBody(verifyTotpBodySchema, body, response);
58
+ if ('error' in parsed)
59
+ return parsed.error;
60
+ return handlers.verifyTotp({ adminUser, body });
61
+ }),
45
62
  });
46
63
  }
@@ -0,0 +1,33 @@
1
+ import { z } from "zod";
2
+ export declare const confirmLoginBodySchema: z.ZodObject<{
3
+ code: z.ZodOptional<z.ZodString>;
4
+ skip: z.ZodOptional<z.ZodBoolean>;
5
+ usePasskey: z.ZodOptional<z.ZodBoolean>;
6
+ passkeyOptions: z.ZodOptional<z.ZodAny>;
7
+ }, z.core.$strict>;
8
+ export declare const confirmLoginWithPasskeyBodySchema: z.ZodObject<{
9
+ passkeyResponse: z.ZodRecord<z.ZodString, z.ZodAny>;
10
+ rememberMe: z.ZodOptional<z.ZodBoolean>;
11
+ }, z.core.$strict>;
12
+ export declare const verifyTotpBodySchema: z.ZodObject<{
13
+ code: z.ZodString;
14
+ }, z.core.$strict>;
15
+ export declare const registrationOptionsBodySchema: z.ZodObject<{
16
+ mode: z.ZodOptional<z.ZodNullable<z.ZodString>>;
17
+ confirmationResult: z.ZodRecord<z.ZodString, z.ZodAny>;
18
+ }, z.core.$strict>;
19
+ export declare const finishRegistrationBodySchema: z.ZodObject<{
20
+ credential: z.ZodAny;
21
+ origin: z.ZodString;
22
+ }, z.core.$strict>;
23
+ export declare const deletePasskeyBodySchema: z.ZodObject<{
24
+ passkeyId: z.ZodString;
25
+ }, z.core.$strict>;
26
+ export declare const renamePasskeyBodySchema: z.ZodObject<{
27
+ passkeyId: z.ZodString;
28
+ newName: z.ZodString;
29
+ }, z.core.$strict>;
30
+ export declare const resolveVerifyAutoBodySchema: z.ZodObject<{
31
+ sessionsIds: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
32
+ confirmationResult: z.ZodRecord<z.ZodString, z.ZodAny>;
33
+ }, z.core.$strict>;
@@ -0,0 +1,35 @@
1
+ import { z } from "zod";
2
+ // twofa endpoints
3
+ export const confirmLoginBodySchema = z.object({
4
+ code: z.string().optional(),
5
+ skip: z.boolean().optional(),
6
+ usePasskey: z.boolean().optional(),
7
+ passkeyOptions: z.any().optional(),
8
+ }).strict();
9
+ export const confirmLoginWithPasskeyBodySchema = z.object({
10
+ passkeyResponse: z.record(z.string(), z.any()),
11
+ rememberMe: z.boolean().optional(),
12
+ }).strict();
13
+ export const verifyTotpBodySchema = z.object({
14
+ code: z.string(),
15
+ }).strict();
16
+ // passkey endpoints
17
+ export const registrationOptionsBodySchema = z.object({
18
+ mode: z.string().nullish(),
19
+ confirmationResult: z.record(z.string(), z.any()),
20
+ }).strict();
21
+ export const finishRegistrationBodySchema = z.object({
22
+ credential: z.any(),
23
+ origin: z.string(),
24
+ }).strict();
25
+ export const deletePasskeyBodySchema = z.object({
26
+ passkeyId: z.string(),
27
+ }).strict();
28
+ export const renamePasskeyBodySchema = z.object({
29
+ passkeyId: z.string(),
30
+ newName: z.string(),
31
+ }).strict();
32
+ export const resolveVerifyAutoBodySchema = z.object({
33
+ sessionsIds: z.array(z.string()).nullish(),
34
+ confirmationResult: z.record(z.string(), z.any()),
35
+ }).strict();
@@ -1,19 +1,34 @@
1
1
  import type { IHttpServer } from "adminforth";
2
+ import { parseBody } from "adminforth";
3
+ import {
4
+ registrationOptionsBodySchema,
5
+ finishRegistrationBodySchema,
6
+ deletePasskeyBodySchema,
7
+ renamePasskeyBodySchema,
8
+ resolveVerifyAutoBodySchema,
9
+ } from "./validation.js";
2
10
 
3
11
  export function registerPasskeyEndpoints(server: IHttpServer, handlers: any): void {
4
12
  server.endpoint({
5
13
  method: 'POST',
6
14
  path: `/plugin/passkeys/registrationOptions`,
7
15
  noAuth: false,
8
- handler: async ({ body, adminUser, response, cookies, headers }) =>
9
- handlers.createRegistrationOptions({ body, adminUser, response, cookies, headers }),
16
+ handler: async ({ body, adminUser, response, cookies, headers }) => {
17
+ const parsed = parseBody(registrationOptionsBodySchema, body, response);
18
+ if ('error' in parsed) return parsed.error;
19
+ return handlers.createRegistrationOptions({ body, adminUser, response, cookies, headers });
20
+ },
10
21
  });
11
22
 
12
23
  server.endpoint({
13
24
  method: 'POST',
14
25
  path: `/plugin/passkeys/finishRegistration`,
15
26
  noAuth: false,
16
- handler: async ({ body, adminUser, cookies }) => handlers.finishRegistration({ body, adminUser, cookies }),
27
+ handler: async ({ body, adminUser, cookies, response }) => {
28
+ const parsed = parseBody(finishRegistrationBodySchema, body, response);
29
+ if ('error' in parsed) return parsed.error;
30
+ return handlers.finishRegistration({ body, adminUser, cookies });
31
+ },
17
32
  });
18
33
 
19
34
  server.endpoint({
@@ -34,14 +49,22 @@ export function registerPasskeyEndpoints(server: IHttpServer, handlers: any): vo
34
49
  method: 'DELETE',
35
50
  path: `/plugin/passkeys/deletePasskey`,
36
51
  noAuth: false,
37
- handler: async ({ body, adminUser }) => handlers.deletePasskey({ body, adminUser }),
52
+ handler: async ({ body, adminUser, response }) => {
53
+ const parsed = parseBody(deletePasskeyBodySchema, body, response);
54
+ if ('error' in parsed) return parsed.error;
55
+ return handlers.deletePasskey({ body, adminUser });
56
+ },
38
57
  });
39
58
 
40
59
  server.endpoint({
41
60
  method: 'POST',
42
61
  path: `/plugin/passkeys/renamePasskey`,
43
62
  noAuth: false,
44
- handler: async ({ body, adminUser }) => handlers.renamePasskey({ body, adminUser }),
63
+ handler: async ({ body, adminUser, response }) => {
64
+ const parsed = parseBody(renamePasskeyBodySchema, body, response);
65
+ if ('error' in parsed) return parsed.error;
66
+ return handlers.renamePasskey({ body, adminUser });
67
+ },
45
68
  });
46
69
 
47
70
  server.endpoint({
@@ -55,7 +78,10 @@ export function registerPasskeyEndpoints(server: IHttpServer, handlers: any): vo
55
78
  method: 'POST',
56
79
  path: `/plugin/passkeys/resolveVerifyAuto`,
57
80
  noAuth: false,
58
- handler: async ({ body, adminUser, response, cookies, headers }) =>
59
- handlers.resolveVerifyAuto({ body, adminUser, response, cookies, headers }),
81
+ handler: async ({ body, adminUser, response, cookies, headers }) => {
82
+ const parsed = parseBody(resolveVerifyAutoBodySchema, body, response);
83
+ if ('error' in parsed) return parsed.error;
84
+ return handlers.resolveVerifyAuto({ body, adminUser, response, cookies, headers });
85
+ },
60
86
  });
61
87
  }
@@ -1,4 +1,10 @@
1
1
  import type { IHttpServer } from "adminforth";
2
+ import { parseBody } from "adminforth";
3
+ import {
4
+ confirmLoginBodySchema,
5
+ confirmLoginWithPasskeyBodySchema,
6
+ verifyTotpBodySchema,
7
+ } from "./validation.js";
2
8
 
3
9
  export function registerTwoFaEndpoints(server: IHttpServer, handlers: any): void {
4
10
  server.endpoint({
@@ -12,15 +18,22 @@ export function registerTwoFaEndpoints(server: IHttpServer, handlers: any): void
12
18
  method: 'POST',
13
19
  path: `/plugin/twofa/confirmLogin`,
14
20
  noAuth: true,
15
- handler: async ({ body, response, cookies, headers }) => handlers.confirmLogin({ body, response, cookies, headers }),
21
+ handler: async ({ body, response, cookies, headers }) => {
22
+ const parsed = parseBody(confirmLoginBodySchema, body, response);
23
+ if ('error' in parsed) return parsed.error;
24
+ return handlers.confirmLogin({ body, response, cookies, headers });
25
+ },
16
26
  });
17
27
 
18
28
  server.endpoint({
19
29
  method: 'POST',
20
30
  path: `/plugin/twofa/confirmLoginWithPasskey`,
21
31
  noAuth: true,
22
- handler: async ({ body, response, cookies, headers, requestUrl, query }) =>
23
- handlers.confirmLoginWithPasskey({ body, response, cookies, headers, requestUrl, query }),
32
+ handler: async ({ body, response, cookies, headers, requestUrl, query }) => {
33
+ const parsed = parseBody(confirmLoginWithPasskeyBodySchema, body, response);
34
+ if ('error' in parsed) return parsed.error;
35
+ return handlers.confirmLoginWithPasskey({ body, response, cookies, headers, requestUrl, query });
36
+ },
24
37
  });
25
38
 
26
39
  server.endpoint({
@@ -40,6 +53,10 @@ export function registerTwoFaEndpoints(server: IHttpServer, handlers: any): void
40
53
  method: 'POST',
41
54
  path: `/plugin/twofa/verify`,
42
55
  noAuth: false,
43
- handler: async ({ adminUser, body }) => handlers.verifyTotp({ adminUser, body }),
56
+ handler: async ({ adminUser, body, response }) => {
57
+ const parsed = parseBody(verifyTotpBodySchema, body, response);
58
+ if ('error' in parsed) return parsed.error;
59
+ return handlers.verifyTotp({ adminUser, body });
60
+ },
44
61
  });
45
62
  }
@@ -0,0 +1,43 @@
1
+ import { z } from "zod";
2
+
3
+ // twofa endpoints
4
+ export const confirmLoginBodySchema = z.object({
5
+ code: z.string().optional(),
6
+ skip: z.boolean().optional(),
7
+ usePasskey: z.boolean().optional(),
8
+ passkeyOptions: z.any().optional(),
9
+ }).strict();
10
+
11
+ export const confirmLoginWithPasskeyBodySchema = z.object({
12
+ passkeyResponse: z.record(z.string(), z.any()),
13
+ rememberMe: z.boolean().optional(),
14
+ }).strict();
15
+
16
+ export const verifyTotpBodySchema = z.object({
17
+ code: z.string(),
18
+ }).strict();
19
+
20
+ // passkey endpoints
21
+ export const registrationOptionsBodySchema = z.object({
22
+ mode: z.string().nullish(),
23
+ confirmationResult: z.record(z.string(), z.any()),
24
+ }).strict();
25
+
26
+ export const finishRegistrationBodySchema = z.object({
27
+ credential: z.any(),
28
+ origin: z.string(),
29
+ }).strict();
30
+
31
+ export const deletePasskeyBodySchema = z.object({
32
+ passkeyId: z.string(),
33
+ }).strict();
34
+
35
+ export const renamePasskeyBodySchema = z.object({
36
+ passkeyId: z.string(),
37
+ newName: z.string(),
38
+ }).strict();
39
+
40
+ export const resolveVerifyAutoBodySchema = z.object({
41
+ sessionsIds: z.array(z.string()).nullish(),
42
+ confirmationResult: z.record(z.string(), z.any()),
43
+ }).strict();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/two-factors-auth",
3
- "version": "4.2.4",
3
+ "version": "4.3.1",
4
4
  "description": "AdminForth plugin for two factors authentication",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -25,14 +25,15 @@
25
25
  "license": "MIT",
26
26
  "dependencies": {
27
27
  "@simplewebauthn/server": "^13.2.1",
28
- "node-2fa": "^2.0.3"
28
+ "node-2fa": "^2.0.3",
29
+ "zod": "^4.3.6"
29
30
  },
30
31
  "peerDependencies": {
31
- "adminforth": "^3.6.21"
32
+ "adminforth": "^3.7.1"
32
33
  },
33
34
  "devDependencies": {
34
35
  "@types/node": "^22.10.7",
35
- "adminforth": "^3.6.21",
36
+ "adminforth": "^3.7.1",
36
37
  "semantic-release": "^24.2.1",
37
38
  "semantic-release-slack-bot": "^4.0.2",
38
39
  "typescript": "^5.7.3"