@adminforth/two-factors-auth 4.3.4 → 4.4.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.
@@ -7,6 +7,7 @@ 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 { convertPeriodToSeconds } from "adminforth";
10
11
  import crypto from 'crypto';
11
12
  const TOTP_TEMP_COOKIE = "2FaTemporaryJWT";
12
13
  const PASSKEY_LOGIN_TEMP_COOKIE = "passkeyLoginTemporaryJWT";
@@ -36,11 +37,11 @@ export class CookieService {
36
37
  });
37
38
  }
38
39
  setTotpTemporary(response, payload) {
39
- var _a;
40
- const value = this.adminforth.auth.issueJWT(payload, 'temp2FA', ((_a = this.options.passkeys) === null || _a === void 0 ? void 0 : _a.challengeValidityPeriod) || '1m');
40
+ const period = this.options.totpSetupValidityPeriod || '1m';
41
+ const value = this.adminforth.auth.issueJWT(payload, 'temp2FA', period);
41
42
  this.adminforth.auth.setCustomCookie({
42
43
  response,
43
- payload: { name: TOTP_TEMP_COOKIE, value, expiry: undefined, expirySeconds: 10 * 60, httpOnly: true },
44
+ payload: { name: TOTP_TEMP_COOKIE, value, expiry: undefined, expirySeconds: convertPeriodToSeconds(period), httpOnly: true },
44
45
  });
45
46
  }
46
47
  removeTotpTemporary(response) {
package/dist/types.d.ts CHANGED
@@ -18,6 +18,12 @@ export interface PluginOptions extends PluginsCommonOptions {
18
18
  * During this period, user will not be challenged with 2FA on sensitive actions.
19
19
  */
20
20
  stepUpMfaGracePeriodSeconds?: number;
21
+ /**
22
+ * Time the user has to complete 2FA setup / enter the OTP code before the temporary
23
+ * login session expires. Increase it if users don't have enough time to scan the QR
24
+ * code and enter the code. Default is '5m'.
25
+ */
26
+ totpSetupValidityPeriod?: PeriodString;
21
27
  customBrandPrefix?: string;
22
28
  /**
23
29
  * Passkeys (WebAuthn) configuration.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/two-factors-auth",
3
- "version": "4.3.4",
3
+ "version": "4.4.0",
4
4
  "description": "AdminForth plugin for two factors authentication",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,4 +1,5 @@
1
1
  import type { IAdminForth, IAdminForthHttpResponse } from "adminforth";
2
+ import { convertPeriodToSeconds } from "adminforth";
2
3
  import type { PluginOptions } from "../types.js";
3
4
  import type { CookieList, HttpHeaders } from "../utils/types.js";
4
5
  import crypto from 'crypto';
@@ -57,10 +58,11 @@ export class CookieService {
57
58
  }
58
59
 
59
60
  public setTotpTemporary(response: IAdminForthHttpResponse, payload: TotpTemporaryPayload): void {
60
- const value = this.adminforth.auth.issueJWT(payload, 'temp2FA', this.options.passkeys?.challengeValidityPeriod || '1m');
61
+ const period = this.options.totpSetupValidityPeriod || '1m';
62
+ const value = this.adminforth.auth.issueJWT(payload, 'temp2FA', period);
61
63
  this.adminforth.auth.setCustomCookie({
62
64
  response,
63
- payload: { name: TOTP_TEMP_COOKIE, value, expiry: undefined, expirySeconds: 10 * 60, httpOnly: true },
65
+ payload: { name: TOTP_TEMP_COOKIE, value, expiry: undefined, expirySeconds: convertPeriodToSeconds(period), httpOnly: true },
64
66
  });
65
67
  }
66
68
 
package/types.ts CHANGED
@@ -23,6 +23,13 @@ export interface PluginOptions extends PluginsCommonOptions {
23
23
  */
24
24
  stepUpMfaGracePeriodSeconds?: number;
25
25
 
26
+ /**
27
+ * Time the user has to complete 2FA setup / enter the OTP code before the temporary
28
+ * login session expires. Increase it if users don't have enough time to scan the QR
29
+ * code and enter the code. Default is '5m'.
30
+ */
31
+ totpSetupValidityPeriod?: PeriodString; // e.g. '5m', '10m', '15m'. Default is '1m'
32
+
26
33
  customBrandPrefix?: string;
27
34
 
28
35
  /**