@adminforth/two-factors-auth 7.4.0 → 7.4.2

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.
@@ -29,5 +29,5 @@ export declare const renamePasskeyBodySchema: z.ZodObject<{
29
29
  }, z.core.$strict>;
30
30
  export declare const resolveVerifyAutoBodySchema: z.ZodObject<{
31
31
  sessionsIds: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
32
- confirmationResult: z.ZodRecord<z.ZodString, z.ZodAny>;
32
+ confirmationResult: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodAny>>>;
33
33
  }, z.core.$strict>;
@@ -31,5 +31,6 @@ export const renamePasskeyBodySchema = z.object({
31
31
  }).strict();
32
32
  export const resolveVerifyAutoBodySchema = z.object({
33
33
  sessionsIds: z.array(z.string()).nullish(),
34
- confirmationResult: z.record(z.string(), z.any()),
34
+ // missing on Cancel in TwoFAModal; the handler then resolves the waiting sessions as cancelled
35
+ confirmationResult: z.record(z.string(), z.any()).nullish(),
35
36
  }).strict();
@@ -21,8 +21,8 @@ export class TotpService {
21
21
  this.options = options;
22
22
  this.userRepository = userRepository;
23
23
  this.adminforth = adminforth;
24
- this.codeAttemptLimiters = ((_a = this.options.totpRateLimit) !== null && _a !== void 0 ? _a : DEFAULT_TOTP_RATE_LIMIT).map((rate) => new RateLimiter(rate));
25
24
  this.lastUsedCodeSteps = new Map();
25
+ this.codeAttemptLimiters = ((_a = options.totpRateLimit) !== null && _a !== void 0 ? _a : DEFAULT_TOTP_RATE_LIMIT).map((rate) => new RateLimiter(rate));
26
26
  }
27
27
  generateSecret(issuerName, userName) {
28
28
  return twofactor.generateSecret({ name: issuerName, account: userName }).secret;
@@ -39,5 +39,6 @@ export const renamePasskeyBodySchema = z.object({
39
39
 
40
40
  export const resolveVerifyAutoBodySchema = z.object({
41
41
  sessionsIds: z.array(z.string()).nullish(),
42
- confirmationResult: z.record(z.string(), z.any()),
42
+ // missing on Cancel in TwoFAModal; the handler then resolves the waiting sessions as cancelled
43
+ confirmationResult: z.record(z.string(), z.any()).nullish(),
43
44
  }).strict();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/two-factors-auth",
3
- "version": "7.4.0",
3
+ "version": "7.4.2",
4
4
  "description": "AdminForth plugin for two factors authentication",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -12,14 +12,16 @@ const TOTP_STEP_SECONDS = 30;
12
12
  const RATE_LIMITED_ERROR = "Too many attempts to enter the code. Try again later.";
13
13
 
14
14
  export class TotpService {
15
- private readonly codeAttemptLimiters = (this.options.totpRateLimit ?? DEFAULT_TOTP_RATE_LIMIT).map((rate) => new RateLimiter(rate));
15
+ private readonly codeAttemptLimiters: RateLimiter[];
16
16
  private readonly lastUsedCodeSteps = new Map<string, number>();
17
17
 
18
18
  constructor(
19
19
  private readonly options: PluginOptions,
20
20
  private readonly userRepository: UserRepository,
21
21
  private readonly adminforth: IAdminForth,
22
- ) {}
22
+ ) {
23
+ this.codeAttemptLimiters = (options.totpRateLimit ?? DEFAULT_TOTP_RATE_LIMIT).map((rate) => new RateLimiter(rate));
24
+ }
23
25
 
24
26
  public generateSecret(issuerName: string, userName: string): string {
25
27
  return twofactor.generateSecret({ name: issuerName, account: userName }).secret;
@@ -0,0 +1,9 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { resolveVerifyAutoBodySchema } from '../dist/endpoints/validation.js';
4
+
5
+ test('resolveVerifyAuto accepts a cancelled confirmation, so the handler can release the waiting request', () => {
6
+ // TwoFAModal sends confirmationResult: undefined on Cancel, JSON drops it
7
+ const cancelBody = JSON.parse(JSON.stringify({ confirmationResult: undefined, sessionsIds: ['session'] }));
8
+ assert.equal(resolveVerifyAutoBodySchema.safeParse(cancelBody).success, true);
9
+ });