@adminforth/two-factors-auth 2.6.2 → 2.7.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/dist/index.js CHANGED
@@ -255,7 +255,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
255
255
  const beforeLoginConfirmation = this.adminforth.config.auth.beforeLoginConfirmation;
256
256
  const beforeLoginConfirmationArray = Array.isArray(beforeLoginConfirmation) ? beforeLoginConfirmation : [beforeLoginConfirmation];
257
257
  beforeLoginConfirmationArray.push((_a) => __awaiter(this, [_a], void 0, function* ({ adminUser, response, extra }) {
258
- var _b, _c;
258
+ var _b, _c, _d, _e;
259
259
  if (((_b = extra === null || extra === void 0 ? void 0 : extra.body) === null || _b === void 0 ? void 0 : _b.loginAllowedByPasskeyDirectSignIn) === true) {
260
260
  return { body: { loginAllowed: true }, ok: true };
261
261
  }
@@ -280,7 +280,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
280
280
  if (!secret) {
281
281
  const tempSecret = twofactor.generateSecret({ name: issuerName, account: userName });
282
282
  newSecret = tempSecret.secret;
283
- const totpTemporaryJWT = this.adminforth.auth.issueJWT({ userName, newSecret, issuer: issuerName, pk: userPk, userCanSkipSetup, rememberMeDays }, 'temp2FA', '10m');
283
+ const totpTemporaryJWT = this.adminforth.auth.issueJWT({ userName, newSecret, issuer: issuerName, pk: userPk, userCanSkipSetup, rememberMeDays }, 'temp2FA', ((_d = this.options.passkeys) === null || _d === void 0 ? void 0 : _d.challengeValidityPeriod) || '1m');
284
284
  this.adminforth.auth.setCustomCookie({ response, payload: { name: "2FaTemporaryJWT", value: totpTemporaryJWT, expiry: undefined, expirySeconds: 10 * 60, httpOnly: true } });
285
285
  return {
286
286
  body: {
@@ -291,7 +291,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
291
291
  };
292
292
  }
293
293
  else {
294
- const value = this.adminforth.auth.issueJWT({ userName, issuer: issuerName, pk: userPk, userCanSkipSetup, rememberMeDays }, 'temp2FA', '10m');
294
+ const value = this.adminforth.auth.issueJWT({ userName, issuer: issuerName, pk: userPk, userCanSkipSetup, rememberMeDays }, 'temp2FA', ((_e = this.options.passkeys) === null || _e === void 0 ? void 0 : _e.challengeValidityPeriod) || '1m');
295
295
  this.adminforth.auth.setCustomCookie({ response, payload: { name: "2FaTemporaryJWT", value: value, expiry: undefined, expirySeconds: 10 * 60, httpOnly: true } });
296
296
  return {
297
297
  body: {
@@ -511,7 +511,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
511
511
  path: `/plugin/passkeys/registerPasskeyRequest`,
512
512
  noAuth: false,
513
513
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response, cookies }) {
514
- var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
514
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
515
515
  const mode = body === null || body === void 0 ? void 0 : body.mode;
516
516
  const confirmationResult = body === null || body === void 0 ? void 0 : body.confirmationResult;
517
517
  const verificationResult = yield this.verify(confirmationResult, {
@@ -562,7 +562,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
562
562
  userVerification: ((_m = this.options.passkeys) === null || _m === void 0 ? void 0 : _m.settings.authenticatorSelection.userVerification) || "required"
563
563
  },
564
564
  });
565
- const value = this.adminforth.auth.issueJWT({ "challenge": options.challenge, "user_id": adminUser.pk }, 'registerTempPasskeyChallenge', '10m');
565
+ const value = this.adminforth.auth.issueJWT({ "challenge": options.challenge, "user_id": adminUser.pk }, 'registerTempPasskeyChallenge', ((_o = this.options.passkeys) === null || _o === void 0 ? void 0 : _o.challengeValidityPeriod) || '1m');
566
566
  this.adminforth.auth.setCustomCookie({ response, payload: { name: "registerPasskeyTemporaryJWT", value: value, expiry: undefined, expirySeconds: 10 * 60, httpOnly: true } });
567
567
  return { ok: true, data: options };
568
568
  })
@@ -644,13 +644,13 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
644
644
  path: `/plugin/passkeys/signInRequest`,
645
645
  noAuth: true,
646
646
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ response }) {
647
- var _b, _c;
647
+ var _b, _c, _d;
648
648
  try {
649
649
  const options = yield generateAuthenticationOptions({
650
650
  rpID: (_b = this.options.passkeys) === null || _b === void 0 ? void 0 : _b.settings.rp.id,
651
651
  userVerification: ((_c = this.options.passkeys) === null || _c === void 0 ? void 0 : _c.settings.authenticatorSelection.userVerification) || "required"
652
652
  });
653
- const value = this.adminforth.auth.issueJWT({ "challenge": options.challenge }, 'tempLoginPasskeyChallenge', '10m');
653
+ const value = this.adminforth.auth.issueJWT({ "challenge": options.challenge }, 'tempLoginPasskeyChallenge', ((_d = this.options.passkeys) === null || _d === void 0 ? void 0 : _d.challengeValidityPeriod) || '1m');
654
654
  this.adminforth.auth.setCustomCookie({ response, payload: { name: `passkeyLoginTemporaryJWT`, value: value, expiry: undefined, expirySeconds: 10 * 60, httpOnly: true } });
655
655
  return { ok: true, data: options };
656
656
  }
package/index.ts CHANGED
@@ -316,7 +316,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
316
316
  const tempSecret = twofactor.generateSecret({name: issuerName,account: userName})
317
317
  newSecret = tempSecret.secret;
318
318
 
319
- const totpTemporaryJWT = this.adminforth.auth.issueJWT({userName, newSecret, issuer:issuerName, pk:userPk, userCanSkipSetup, rememberMeDays }, 'temp2FA', '10m');
319
+ const totpTemporaryJWT = this.adminforth.auth.issueJWT({userName, newSecret, issuer:issuerName, pk:userPk, userCanSkipSetup, rememberMeDays }, 'temp2FA', this.options.passkeys?.challengeValidityPeriod || '1m');
320
320
  this.adminforth.auth.setCustomCookie({response, payload: {name: "2FaTemporaryJWT", value: totpTemporaryJWT, expiry: undefined, expirySeconds: 10 * 60, httpOnly: true}});
321
321
 
322
322
  return {
@@ -328,7 +328,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
328
328
  }
329
329
 
330
330
  } else {
331
- const value = this.adminforth.auth.issueJWT({userName, issuer:issuerName, pk:userPk, userCanSkipSetup, rememberMeDays }, 'temp2FA', '10m');
331
+ const value = this.adminforth.auth.issueJWT({userName, issuer:issuerName, pk:userPk, userCanSkipSetup, rememberMeDays }, 'temp2FA', this.options.passkeys?.challengeValidityPeriod || '1m');
332
332
  this.adminforth.auth.setCustomCookie({response, payload: {name: "2FaTemporaryJWT", value: value, expiry: undefined, expirySeconds: 10 * 60, httpOnly: true}});
333
333
 
334
334
  return {
@@ -615,7 +615,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
615
615
  userVerification: this.options.passkeys?.settings.authenticatorSelection.userVerification || "required"
616
616
  },
617
617
  });
618
- const value = this.adminforth.auth.issueJWT({ "challenge": options.challenge, "user_id": adminUser.pk }, 'registerTempPasskeyChallenge', '10m');
618
+ const value = this.adminforth.auth.issueJWT({ "challenge": options.challenge, "user_id": adminUser.pk }, 'registerTempPasskeyChallenge', this.options.passkeys?.challengeValidityPeriod || '1m');
619
619
  this.adminforth.auth.setCustomCookie({response, payload: {name: "registerPasskeyTemporaryJWT", value: value, expiry: undefined, expirySeconds: 10 * 60, httpOnly: true}});
620
620
  return { ok: true, data: options };
621
621
  }
@@ -707,7 +707,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
707
707
  rpID: this.options.passkeys?.settings.rp.id,
708
708
  userVerification: this.options.passkeys?.settings.authenticatorSelection.userVerification || "required"
709
709
  });
710
- const value = this.adminforth.auth.issueJWT({ "challenge": options.challenge }, 'tempLoginPasskeyChallenge', '10m');
710
+ const value = this.adminforth.auth.issueJWT({ "challenge": options.challenge }, 'tempLoginPasskeyChallenge', this.options.passkeys?.challengeValidityPeriod || '1m');
711
711
  this.adminforth.auth.setCustomCookie({response, payload: {name: `passkeyLoginTemporaryJWT`, value: value, expiry: undefined, expirySeconds: 10 * 60, httpOnly: true}});
712
712
  return { ok: true, data: options };
713
713
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/two-factors-auth",
3
- "version": "2.6.2",
3
+ "version": "2.7.0",
4
4
  "description": "AdminForth plugin for two factors authentication",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/types.ts CHANGED
@@ -45,6 +45,10 @@ export type PluginOptions = {
45
45
  * Period between showing alert suggesting to set up Passkeys if not set up yet.
46
46
  */
47
47
  suggestionPeriod?: string; // e.g. '30d', '12h', '15m'. Default is '5d'
48
+ /**
49
+ * Challenge period for Passkeys authentication.
50
+ */
51
+ challengeValidityPeriod?: string; // e.g. '5m', '10m', '15m'. Default is '1m'
48
52
  /**
49
53
  * Passkeys settings for WebAuthn API.
50
54
  */