@adminforth/two-factors-auth 2.7.3 → 2.8.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
@@ -15,5 +15,5 @@ custom/package.json
15
15
  custom/tsconfig.json
16
16
  custom/utils.js
17
17
 
18
- sent 271,998 bytes received 210 bytes 544,416.00 bytes/sec
19
- total size is 271,171 speedup is 1.00
18
+ sent 272,607 bytes received 210 bytes 545,634.00 bytes/sec
19
+ total size is 271,780 speedup is 1.00
@@ -128,6 +128,11 @@
128
128
  get2FaConfirmationResult: (verifyingCallback?: (confirmationResult: string) => Promise<boolean>, title?: string) =>
129
129
  new Promise(async (resolve, reject) => {
130
130
  if (modelShow.value) throw new Error('Modal is already open');
131
+ const skipAllowModal = await checkIfSkipAllowModal();
132
+ if (skipAllowModal) {
133
+ resolve({ code: "123456" }); // dummy code
134
+ return;
135
+ }
131
136
  await checkIfUserHasPasskeys();
132
137
  if (title) {
133
138
  customDialogTitle.value = title;
@@ -338,6 +343,24 @@
338
343
  });
339
344
  }
340
345
 
346
+
347
+ async function checkIfSkipAllowModal(){
348
+ try {
349
+ const response = await callAdminForthApi({
350
+ method: "GET",
351
+ path: "/plugin/twofa/skip-allow-modal",
352
+ });
353
+ if ( response.skipAllowed === true ) {
354
+ return true;
355
+ } else {
356
+ return false;
357
+ }
358
+ } catch (error) {
359
+ console.error('Error checking skip allow modal:', error);
360
+ return false;
361
+ }
362
+ }
363
+
341
364
  </script>
342
365
 
343
366
  <style scoped>
@@ -285,7 +285,7 @@ const handleSkip = async () => {
285
285
  });
286
286
  if (resp.allowedLogin){
287
287
  if ( route.meta.isPasskeysEnabled ) {
288
- handlePasskeyAlert();
288
+ handlePasskeyAlert(route.meta.suggestionPeriod, router);
289
289
  }
290
290
  await user.finishLogin();
291
291
  } else if (resp.error) {
@@ -128,6 +128,11 @@
128
128
  get2FaConfirmationResult: (verifyingCallback?: (confirmationResult: string) => Promise<boolean>, title?: string) =>
129
129
  new Promise(async (resolve, reject) => {
130
130
  if (modelShow.value) throw new Error('Modal is already open');
131
+ const skipAllowModal = await checkIfSkipAllowModal();
132
+ if (skipAllowModal) {
133
+ resolve({ code: "123456" }); // dummy code
134
+ return;
135
+ }
131
136
  await checkIfUserHasPasskeys();
132
137
  if (title) {
133
138
  customDialogTitle.value = title;
@@ -338,6 +343,24 @@
338
343
  });
339
344
  }
340
345
 
346
+
347
+ async function checkIfSkipAllowModal(){
348
+ try {
349
+ const response = await callAdminForthApi({
350
+ method: "GET",
351
+ path: "/plugin/twofa/skip-allow-modal",
352
+ });
353
+ if ( response.skipAllowed === true ) {
354
+ return true;
355
+ } else {
356
+ return false;
357
+ }
358
+ } catch (error) {
359
+ console.error('Error checking skip allow modal:', error);
360
+ return false;
361
+ }
362
+ }
363
+
341
364
  </script>
342
365
 
343
366
  <style scoped>
@@ -285,7 +285,7 @@ const handleSkip = async () => {
285
285
  });
286
286
  if (resp.allowedLogin){
287
287
  if ( route.meta.isPasskeysEnabled ) {
288
- handlePasskeyAlert();
288
+ handlePasskeyAlert(route.meta.suggestionPeriod, router);
289
289
  }
290
290
  await user.finishLogin();
291
291
  } else if (resp.error) {
package/dist/index.js CHANGED
@@ -25,6 +25,12 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
25
25
  var _a, _b, _c, _d;
26
26
  if (!confirmationResult)
27
27
  return { error: "Confirmation result is required" };
28
+ if (this.options.usersFilterToApply) {
29
+ const res = this.options.usersFilterToApply(opts.adminUser);
30
+ if (res === false) {
31
+ return { ok: true };
32
+ }
33
+ }
28
34
  if (confirmationResult.mode === "totp") {
29
35
  const code = confirmationResult.result;
30
36
  const authRes = this.adminforth.config.resources
@@ -487,6 +493,19 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
487
493
  }
488
494
  }),
489
495
  });
496
+ server.endpoint({
497
+ method: "GET",
498
+ path: "/plugin/twofa/skip-allow-modal",
499
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ adminUser }) {
500
+ if (this.options.usersFilterToApply) {
501
+ const res = this.options.usersFilterToApply(adminUser);
502
+ if (res === false) {
503
+ return { skipAllowed: true };
504
+ }
505
+ }
506
+ return { skipAllowed: false };
507
+ }),
508
+ });
490
509
  server.endpoint({
491
510
  method: 'POST',
492
511
  path: `/plugin/twofa/verify`,
package/index.ts CHANGED
@@ -32,7 +32,12 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
32
32
  opts?: { adminUser?: AdminUser; userPk?: string; cookies?: any }
33
33
  ): Promise<{ ok: true } | { error: string }> {
34
34
  if (!confirmationResult) return { error: "Confirmation result is required" };
35
-
35
+ if (this.options.usersFilterToApply) {
36
+ const res = this.options.usersFilterToApply(opts.adminUser);
37
+ if ( res === false ) {
38
+ return { ok: true };
39
+ }
40
+ }
36
41
  if (confirmationResult.mode === "totp") {
37
42
  const code = confirmationResult.result;
38
43
  const authRes = this.adminforth.config.resources
@@ -538,6 +543,19 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
538
543
  }
539
544
  },
540
545
  });
546
+ server.endpoint({
547
+ method: "GET",
548
+ path: "/plugin/twofa/skip-allow-modal",
549
+ handler: async ({ adminUser }) => {
550
+ if ( this.options.usersFilterToApply ) {
551
+ const res = this.options.usersFilterToApply(adminUser);
552
+ if ( res === false ) {
553
+ return { skipAllowed: true };
554
+ }
555
+ }
556
+ return { skipAllowed: false };
557
+ },
558
+ });
541
559
  server.endpoint({
542
560
  method: 'POST',
543
561
  path: `/plugin/twofa/verify`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/two-factors-auth",
3
- "version": "2.7.3",
3
+ "version": "2.8.0",
4
4
  "description": "AdminForth plugin for two factors authentication",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",