@adminforth/two-factors-auth 4.4.8 → 4.5.0

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 311,882 bytes received 248 bytes 624,260.00 bytes/sec
20
+ sent 311,869 bytes received 248 bytes 624,234.00 bytes/sec
21
21
  total size is 310,909 speedup is 1.00
@@ -12,6 +12,9 @@ export function registerPasskeyEndpoints(server, handlers) {
12
12
  server.endpoint({
13
13
  method: 'POST',
14
14
  path: `/plugin/passkeys/registrationOptions`,
15
+ agent: {
16
+ hiddenFromAgents: true,
17
+ },
15
18
  noAuth: false,
16
19
  request_schema: registrationOptionsBodySchema,
17
20
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response, cookies, headers }) {
@@ -21,6 +24,9 @@ export function registerPasskeyEndpoints(server, handlers) {
21
24
  server.endpoint({
22
25
  method: 'POST',
23
26
  path: `/plugin/passkeys/finishRegistration`,
27
+ agent: {
28
+ hiddenFromAgents: true,
29
+ },
24
30
  noAuth: false,
25
31
  request_schema: finishRegistrationBodySchema,
26
32
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, cookies, response }) {
@@ -30,18 +36,27 @@ export function registerPasskeyEndpoints(server, handlers) {
30
36
  server.endpoint({
31
37
  method: 'POST',
32
38
  path: `/plugin/passkeys/loginOptions`,
39
+ agent: {
40
+ hiddenFromAgents: true,
41
+ },
33
42
  noAuth: true,
34
43
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ response, headers }) { return handlers.createLoginOptions({ response, headers }); }),
35
44
  });
36
45
  server.endpoint({
37
46
  method: 'GET',
38
47
  path: `/plugin/passkeys/getPasskeys`,
48
+ agent: {
49
+ hiddenFromAgents: true,
50
+ },
39
51
  noAuth: false,
40
52
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ adminUser, response }) { return handlers.getPasskeys({ adminUser, response }); }),
41
53
  });
42
54
  server.endpoint({
43
55
  method: 'DELETE',
44
56
  path: `/plugin/passkeys/deletePasskey`,
57
+ agent: {
58
+ hiddenFromAgents: true,
59
+ },
45
60
  noAuth: false,
46
61
  request_schema: deletePasskeyBodySchema,
47
62
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response }) {
@@ -51,6 +66,9 @@ export function registerPasskeyEndpoints(server, handlers) {
51
66
  server.endpoint({
52
67
  method: 'POST',
53
68
  path: `/plugin/passkeys/renamePasskey`,
69
+ agent: {
70
+ hiddenFromAgents: true,
71
+ },
54
72
  noAuth: false,
55
73
  request_schema: renamePasskeyBodySchema,
56
74
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response }) {
@@ -60,12 +78,18 @@ export function registerPasskeyEndpoints(server, handlers) {
60
78
  server.endpoint({
61
79
  method: 'POST',
62
80
  path: `/plugin/passkeys/checkIfUserHasPasskeys`,
81
+ agent: {
82
+ hiddenFromAgents: true,
83
+ },
63
84
  noAuth: true,
64
85
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ cookies, response }) { return handlers.checkIfUserHasPasskeys({ cookies, response }); }),
65
86
  });
66
87
  server.endpoint({
67
88
  method: 'POST',
68
89
  path: `/plugin/passkeys/resolveVerifyAuto`,
90
+ agent: {
91
+ hiddenFromAgents: true,
92
+ },
69
93
  noAuth: false,
70
94
  request_schema: resolveVerifyAutoBodySchema,
71
95
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response, cookies, headers }) {
@@ -12,21 +12,30 @@ export function registerTwoFaEndpoints(server, handlers) {
12
12
  server.endpoint({
13
13
  method: 'POST',
14
14
  path: `/plugin/twofa/initSetup`,
15
+ agent: {
16
+ hiddenFromAgents: true,
17
+ },
15
18
  noAuth: true,
16
19
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ cookies, response }) { return handlers.initSetup({ cookies, response }); }),
17
20
  });
18
21
  server.endpoint({
19
22
  method: 'POST',
20
23
  path: `/plugin/twofa/confirmLogin`,
24
+ agent: {
25
+ hiddenFromAgents: true,
26
+ },
21
27
  noAuth: true,
22
28
  request_schema: confirmLoginBodySchema,
23
- handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response, cookies, headers }) {
24
- return handlers.confirmLogin({ body, response, cookies, headers });
29
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response, cookies, headers, requestUrl, query }) {
30
+ return handlers.confirmLogin({ body, response, cookies, headers, requestUrl, query });
25
31
  }),
26
32
  });
27
33
  server.endpoint({
28
34
  method: 'POST',
29
35
  path: `/plugin/twofa/confirmLoginWithPasskey`,
36
+ agent: {
37
+ hiddenFromAgents: true,
38
+ },
30
39
  noAuth: true,
31
40
  request_schema: confirmLoginWithPasskeyBodySchema,
32
41
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response, cookies, headers, requestUrl, query }) {
@@ -36,17 +45,26 @@ export function registerTwoFaEndpoints(server, handlers) {
36
45
  server.endpoint({
37
46
  method: "GET",
38
47
  path: "/plugin/twofa/skip-allow",
48
+ agent: {
49
+ hiddenFromAgents: true,
50
+ },
39
51
  noAuth: true,
40
52
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ cookies, response }) { return handlers.skipAllow({ cookies, response }); }),
41
53
  });
42
54
  server.endpoint({
43
55
  method: "GET",
44
56
  path: "/plugin/twofa/skip-allow-modal",
57
+ agent: {
58
+ hiddenFromAgents: true,
59
+ },
45
60
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ adminUser, headers, cookies, response }) { return handlers.skipAllowModal({ adminUser, headers, cookies, response }); }),
46
61
  });
47
62
  server.endpoint({
48
63
  method: 'POST',
49
64
  path: `/plugin/twofa/verify`,
65
+ agent: {
66
+ hiddenFromAgents: true,
67
+ },
50
68
  noAuth: false,
51
69
  request_schema: verifyTotpBodySchema,
52
70
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ adminUser, body, response }) {
@@ -5,11 +5,13 @@ export declare function createTwoFaHandlers(ctx: any): {
5
5
  totpJWT: any;
6
6
  status: string;
7
7
  }>;
8
- confirmLogin: ({ body, response, cookies, headers }: {
8
+ confirmLogin: ({ body, response, cookies, headers, requestUrl, query }: {
9
9
  body: any;
10
10
  response: any;
11
11
  cookies: any;
12
12
  headers: any;
13
+ requestUrl: any;
14
+ query: any;
13
15
  }) => Promise<{
14
16
  error: any;
15
17
  } | {
@@ -18,8 +18,9 @@ export function createTwoFaHandlers(ctx) {
18
18
  }
19
19
  return toReturn;
20
20
  }),
21
- confirmLogin: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response, cookies, headers }) {
21
+ confirmLogin: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response, cookies, headers, requestUrl, query }) {
22
22
  var _b, _c;
23
+ const extra = { body, headers, cookies, query, requestUrl, response };
23
24
  if (!(yield ctx.checkPasskeyLoginRateLimit(headers))) {
24
25
  return respondWithStatus({ error: 'Too many login attempts, please try again later' }, response, HttpStatus.TOO_MANY_REQUESTS);
25
26
  }
@@ -38,7 +39,7 @@ export function createTwoFaHandlers(ctx) {
38
39
  yield ctx.totpService.saveSecret(decoded.pk, decoded.newSecret);
39
40
  }
40
41
  ctx.cookieService.removeTotpTemporary(response);
41
- yield ctx.cookieService.setAuthCookie({ expireInDuration: decoded.sessionDuration, response, username: decoded.userName, pk: decoded.pk });
42
+ yield ctx.cookieService.setAuthCookie({ expireInDuration: decoded.sessionDuration, response, username: decoded.userName, pk: decoded.pk, extra });
42
43
  return { status: 'ok', allowedLogin: true };
43
44
  }
44
45
  else {
@@ -69,7 +70,7 @@ export function createTwoFaHandlers(ctx) {
69
70
  }
70
71
  if (verified) {
71
72
  ctx.cookieService.removeTotpTemporary(response);
72
- yield ctx.cookieService.setAuthCookie({ expireInDuration: decoded.sessionDuration, response, username: decoded.userName, pk: decoded.pk });
73
+ yield ctx.cookieService.setAuthCookie({ expireInDuration: decoded.sessionDuration, response, username: decoded.userName, pk: decoded.pk, extra });
73
74
  return { status: 'ok', allowedLogin: true };
74
75
  }
75
76
  else {
@@ -108,7 +109,7 @@ export function createTwoFaHandlers(ctx) {
108
109
  const expireInDuration = rememberMe
109
110
  ? ((_b = rememberDaysAfterPasskeyLogin !== null && rememberDaysAfterPasskeyLogin !== void 0 ? rememberDaysAfterPasskeyLogin : ctx.adminforth.config.auth.rememberMeDuration) !== null && _b !== void 0 ? _b : '30d')
110
111
  : '1d';
111
- yield ctx.adminforth.restApi.processLoginCallbacks(adminUser, toReturn, response, {
112
+ const extra = {
112
113
  headers,
113
114
  cookies,
114
115
  requestUrl,
@@ -118,13 +119,15 @@ export function createTwoFaHandlers(ctx) {
118
119
  meta: {
119
120
  loginAllowedByPasskeyDirectSignIn: true
120
121
  },
121
- }, expireInDuration);
122
+ };
123
+ yield ctx.adminforth.restApi.processLoginCallbacks(adminUser, toReturn, response, extra, expireInDuration);
122
124
  if (toReturn.allowedLogin === true) {
123
125
  yield ctx.cookieService.setAuthCookie({
124
126
  response,
125
127
  username,
126
128
  pk: userPk,
127
129
  expireInDuration,
130
+ extra,
128
131
  });
129
132
  }
130
133
  return toReturn;
@@ -1,4 +1,4 @@
1
- import type { IAdminForth, IAdminForthHttpResponse } from "adminforth";
1
+ import type { HttpExtra, IAdminForth, IAdminForthHttpResponse } from "adminforth";
2
2
  import type { PluginOptions } from "../types.js";
3
3
  import type { CookieList, HttpHeaders } from "../utils/types.js";
4
4
  export type TotpTemporaryPayload = {
@@ -30,6 +30,7 @@ export declare class CookieService {
30
30
  username: string;
31
31
  pk: string;
32
32
  expireInDuration: string;
33
+ extra: HttpExtra;
33
34
  }): Promise<string>;
34
35
  getTotpTemporary(cookies: CookieList): string | null;
35
36
  verifyTotpTemporary(cookies: CookieList): Promise<TotpTemporaryPayload | null>;
@@ -11,6 +11,9 @@ export function registerPasskeyEndpoints(server: IHttpServer, handlers: any): vo
11
11
  server.endpoint({
12
12
  method: 'POST',
13
13
  path: `/plugin/passkeys/registrationOptions`,
14
+ agent: {
15
+ hiddenFromAgents: true,
16
+ },
14
17
  noAuth: false,
15
18
  request_schema: registrationOptionsBodySchema,
16
19
  handler: async ({ body, adminUser, response, cookies, headers }) => {
@@ -21,6 +24,9 @@ export function registerPasskeyEndpoints(server: IHttpServer, handlers: any): vo
21
24
  server.endpoint({
22
25
  method: 'POST',
23
26
  path: `/plugin/passkeys/finishRegistration`,
27
+ agent: {
28
+ hiddenFromAgents: true,
29
+ },
24
30
  noAuth: false,
25
31
  request_schema: finishRegistrationBodySchema,
26
32
  handler: async ({ body, adminUser, cookies, response }) => {
@@ -31,6 +37,9 @@ export function registerPasskeyEndpoints(server: IHttpServer, handlers: any): vo
31
37
  server.endpoint({
32
38
  method: 'POST',
33
39
  path: `/plugin/passkeys/loginOptions`,
40
+ agent: {
41
+ hiddenFromAgents: true,
42
+ },
34
43
  noAuth: true,
35
44
  handler: async ({ response, headers }) => handlers.createLoginOptions({ response, headers }),
36
45
  });
@@ -38,6 +47,9 @@ export function registerPasskeyEndpoints(server: IHttpServer, handlers: any): vo
38
47
  server.endpoint({
39
48
  method: 'GET',
40
49
  path: `/plugin/passkeys/getPasskeys`,
50
+ agent: {
51
+ hiddenFromAgents: true,
52
+ },
41
53
  noAuth: false,
42
54
  handler: async ({ adminUser, response }) => handlers.getPasskeys({ adminUser, response }),
43
55
  });
@@ -45,6 +57,9 @@ export function registerPasskeyEndpoints(server: IHttpServer, handlers: any): vo
45
57
  server.endpoint({
46
58
  method: 'DELETE',
47
59
  path: `/plugin/passkeys/deletePasskey`,
60
+ agent: {
61
+ hiddenFromAgents: true,
62
+ },
48
63
  noAuth: false,
49
64
  request_schema: deletePasskeyBodySchema,
50
65
  handler: async ({ body, adminUser, response }) => {
@@ -55,6 +70,9 @@ export function registerPasskeyEndpoints(server: IHttpServer, handlers: any): vo
55
70
  server.endpoint({
56
71
  method: 'POST',
57
72
  path: `/plugin/passkeys/renamePasskey`,
73
+ agent: {
74
+ hiddenFromAgents: true,
75
+ },
58
76
  noAuth: false,
59
77
  request_schema: renamePasskeyBodySchema,
60
78
  handler: async ({ body, adminUser, response }) => {
@@ -65,6 +83,9 @@ export function registerPasskeyEndpoints(server: IHttpServer, handlers: any): vo
65
83
  server.endpoint({
66
84
  method: 'POST',
67
85
  path: `/plugin/passkeys/checkIfUserHasPasskeys`,
86
+ agent: {
87
+ hiddenFromAgents: true,
88
+ },
68
89
  noAuth: true,
69
90
  handler: async ({ cookies, response }) => handlers.checkIfUserHasPasskeys({ cookies, response }),
70
91
  });
@@ -72,6 +93,9 @@ export function registerPasskeyEndpoints(server: IHttpServer, handlers: any): vo
72
93
  server.endpoint({
73
94
  method: 'POST',
74
95
  path: `/plugin/passkeys/resolveVerifyAuto`,
96
+ agent: {
97
+ hiddenFromAgents: true,
98
+ },
75
99
  noAuth: false,
76
100
  request_schema: resolveVerifyAutoBodySchema,
77
101
  handler: async ({ body, adminUser, response, cookies, headers }) => {
@@ -9,6 +9,9 @@ export function registerTwoFaEndpoints(server: IHttpServer, handlers: any): void
9
9
  server.endpoint({
10
10
  method: 'POST',
11
11
  path: `/plugin/twofa/initSetup`,
12
+ agent: {
13
+ hiddenFromAgents: true,
14
+ },
12
15
  noAuth: true,
13
16
  handler: async ({ cookies, response }) => handlers.initSetup({ cookies, response }),
14
17
  });
@@ -16,16 +19,22 @@ export function registerTwoFaEndpoints(server: IHttpServer, handlers: any): void
16
19
  server.endpoint({
17
20
  method: 'POST',
18
21
  path: `/plugin/twofa/confirmLogin`,
22
+ agent: {
23
+ hiddenFromAgents: true,
24
+ },
19
25
  noAuth: true,
20
26
  request_schema: confirmLoginBodySchema,
21
- handler: async ({ body, response, cookies, headers }) => {
22
- return handlers.confirmLogin({ body, response, cookies, headers });
27
+ handler: async ({ body, response, cookies, headers, requestUrl, query }) => {
28
+ return handlers.confirmLogin({ body, response, cookies, headers, requestUrl, query });
23
29
  },
24
30
  });
25
31
 
26
32
  server.endpoint({
27
33
  method: 'POST',
28
34
  path: `/plugin/twofa/confirmLoginWithPasskey`,
35
+ agent: {
36
+ hiddenFromAgents: true,
37
+ },
29
38
  noAuth: true,
30
39
  request_schema: confirmLoginWithPasskeyBodySchema,
31
40
  handler: async ({ body, response, cookies, headers, requestUrl, query }) => {
@@ -36,6 +45,9 @@ export function registerTwoFaEndpoints(server: IHttpServer, handlers: any): void
36
45
  server.endpoint({
37
46
  method: "GET",
38
47
  path: "/plugin/twofa/skip-allow",
48
+ agent: {
49
+ hiddenFromAgents: true,
50
+ },
39
51
  noAuth: true,
40
52
  handler: async ({ cookies, response }) => handlers.skipAllow({ cookies, response }),
41
53
  });
@@ -43,12 +55,18 @@ export function registerTwoFaEndpoints(server: IHttpServer, handlers: any): void
43
55
  server.endpoint({
44
56
  method: "GET",
45
57
  path: "/plugin/twofa/skip-allow-modal",
58
+ agent: {
59
+ hiddenFromAgents: true,
60
+ },
46
61
  handler: async ({ adminUser, headers, cookies, response }) => handlers.skipAllowModal({ adminUser, headers, cookies, response }),
47
62
  });
48
63
 
49
64
  server.endpoint({
50
65
  method: 'POST',
51
66
  path: `/plugin/twofa/verify`,
67
+ agent: {
68
+ hiddenFromAgents: true,
69
+ },
52
70
  noAuth: false,
53
71
  request_schema: verifyTotpBodySchema,
54
72
  handler: async ({ adminUser, body, response }) => {
@@ -11,7 +11,8 @@ export function createTwoFaHandlers(ctx: any) {
11
11
  return toReturn
12
12
  },
13
13
 
14
- confirmLogin: async ({ body, response, cookies, headers }) => {
14
+ confirmLogin: async ({ body, response, cookies, headers, requestUrl, query }) => {
15
+ const extra = { body, headers, cookies, query, requestUrl, response };
15
16
  if (!(await ctx.checkPasskeyLoginRateLimit(headers))) {
16
17
  return respondWithStatus({ error: 'Too many login attempts, please try again later' }, response, HttpStatus.TOO_MANY_REQUESTS);
17
18
  }
@@ -32,7 +33,7 @@ export function createTwoFaHandlers(ctx: any) {
32
33
  await ctx.totpService.saveSecret(decoded.pk, decoded.newSecret);
33
34
  }
34
35
  ctx.cookieService.removeTotpTemporary(response)
35
- await ctx.cookieService.setAuthCookie({expireInDuration: decoded.sessionDuration, response, username:decoded.userName, pk:decoded.pk})
36
+ await ctx.cookieService.setAuthCookie({expireInDuration: decoded.sessionDuration, response, username:decoded.userName, pk:decoded.pk, extra})
36
37
  return { status: 'ok', allowedLogin: true }
37
38
  } else {
38
39
  return respondWithStatus({ error: 'Wrong or expired OTP code' }, response, HttpStatus.FORBIDDEN)
@@ -61,7 +62,7 @@ export function createTwoFaHandlers(ctx: any) {
61
62
  }
62
63
  if (verified) {
63
64
  ctx.cookieService.removeTotpTemporary(response)
64
- await ctx.cookieService.setAuthCookie({expireInDuration: decoded.sessionDuration, response, username:decoded.userName, pk:decoded.pk})
65
+ await ctx.cookieService.setAuthCookie({expireInDuration: decoded.sessionDuration, response, username:decoded.userName, pk:decoded.pk, extra})
65
66
  return { status: 'ok', allowedLogin: true }
66
67
  } else {
67
68
  return respondWithStatus({ error: verificationError }, response, HttpStatus.FORBIDDEN)
@@ -105,21 +106,23 @@ export function createTwoFaHandlers(ctx: any) {
105
106
  ? (rememberDaysAfterPasskeyLogin ?? ctx.adminforth.config.auth.rememberMeDuration ?? '30d')
106
107
  : '1d';
107
108
 
109
+ const extra = {
110
+ headers,
111
+ cookies,
112
+ requestUrl,
113
+ query,
114
+ body: {},
115
+ response,
116
+ meta: {
117
+ loginAllowedByPasskeyDirectSignIn: true
118
+ },
119
+ };
120
+
108
121
  await ctx.adminforth.restApi.processLoginCallbacks(
109
122
  adminUser,
110
123
  toReturn,
111
124
  response,
112
- {
113
- headers,
114
- cookies,
115
- requestUrl,
116
- query,
117
- body: {},
118
- response,
119
- meta: {
120
- loginAllowedByPasskeyDirectSignIn: true
121
- },
122
- },
125
+ extra,
123
126
  expireInDuration,
124
127
  );
125
128
 
@@ -129,6 +132,7 @@ export function createTwoFaHandlers(ctx: any) {
129
132
  username,
130
133
  pk: userPk,
131
134
  expireInDuration,
135
+ extra,
132
136
  });
133
137
  }
134
138
  return toReturn;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/two-factors-auth",
3
- "version": "4.4.8",
3
+ "version": "4.5.0",
4
4
  "description": "AdminForth plugin for two factors authentication",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -29,11 +29,11 @@
29
29
  "zod": "^4.3.6"
30
30
  },
31
31
  "peerDependencies": {
32
- "adminforth": "^3.31.5"
32
+ "adminforth": "^3.32.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/node": "^22.10.7",
36
- "adminforth": "^3.31.5",
36
+ "adminforth": "^3.32.0",
37
37
  "semantic-release": "^24.2.1",
38
38
  "semantic-release-slack-bot": "^4.0.2",
39
39
  "typescript": "^5.7.3"
@@ -1,4 +1,4 @@
1
- import type { IAdminForth, IAdminForthHttpResponse } from "adminforth";
1
+ import type { HttpExtra, IAdminForth, IAdminForthHttpResponse } from "adminforth";
2
2
  import { convertPeriodToSeconds } from "adminforth";
3
3
  import type { PluginOptions } from "../types.js";
4
4
  import type { CookieList, HttpHeaders } from "../utils/types.js";
@@ -43,7 +43,7 @@ export class CookieService {
43
43
  return this.adminforth.auth.getCustomCookie({ cookies, name: AUTH_COOKIE });
44
44
  }
45
45
 
46
- public setAuthCookie(opts: { response: IAdminForthHttpResponse; username: string; pk: string; expireInDuration: string }): Promise<string> {
46
+ public setAuthCookie(opts: { response: IAdminForthHttpResponse; username: string; pk: string; expireInDuration: string; extra: HttpExtra }): Promise<string> {
47
47
  return this.adminforth.auth.setAuthCookie(opts);
48
48
  }
49
49