@adminforth/two-factors-auth 4.3.0 → 4.3.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.
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 288,176 bytes received 248 bytes 576,848.00 bytes/sec
21
- total size is 287,203 speedup is 1.00
20
+ sent 288,139 bytes received 248 bytes 576,774.00 bytes/sec
21
+ total size is 287,166 speedup is 1.00
@@ -249,8 +249,7 @@ async function sendCode (value) {
249
249
  method: 'POST',
250
250
  path: '/plugin/twofa/confirmLogin',
251
251
  body: {
252
- code: value,
253
- secret: totp.value.newSecret,
252
+ code: value
254
253
  }
255
254
  })
256
255
  if (resp.allowedLogin) {
@@ -249,8 +249,7 @@ async function sendCode (value) {
249
249
  method: 'POST',
250
250
  path: '/plugin/twofa/confirmLogin',
251
251
  body: {
252
- code: value,
253
- secret: totp.value.newSecret,
252
+ code: value
254
253
  }
255
254
  })
256
255
  if (resp.allowedLogin) {
@@ -6,7 +6,7 @@ export declare const confirmLoginBodySchema: z.ZodObject<{
6
6
  passkeyOptions: z.ZodOptional<z.ZodAny>;
7
7
  }, z.core.$strict>;
8
8
  export declare const confirmLoginWithPasskeyBodySchema: z.ZodObject<{
9
- passkeyResponse: z.ZodOptional<z.ZodAny>;
9
+ passkeyResponse: z.ZodRecord<z.ZodString, z.ZodAny>;
10
10
  rememberMe: z.ZodOptional<z.ZodBoolean>;
11
11
  }, z.core.$strict>;
12
12
  export declare const verifyTotpBodySchema: z.ZodObject<{
@@ -14,11 +14,11 @@ export declare const verifyTotpBodySchema: z.ZodObject<{
14
14
  }, z.core.$strict>;
15
15
  export declare const registrationOptionsBodySchema: z.ZodObject<{
16
16
  mode: z.ZodOptional<z.ZodNullable<z.ZodString>>;
17
- confirmationResult: z.ZodOptional<z.ZodAny>;
17
+ confirmationResult: z.ZodRecord<z.ZodString, z.ZodAny>;
18
18
  }, z.core.$strict>;
19
19
  export declare const finishRegistrationBodySchema: z.ZodObject<{
20
20
  credential: z.ZodAny;
21
- origin: z.ZodOptional<z.ZodString>;
21
+ origin: z.ZodString;
22
22
  }, z.core.$strict>;
23
23
  export declare const deletePasskeyBodySchema: z.ZodObject<{
24
24
  passkeyId: z.ZodString;
@@ -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.ZodOptional<z.ZodAny>;
32
+ confirmationResult: z.ZodRecord<z.ZodString, z.ZodAny>;
33
33
  }, z.core.$strict>;
@@ -7,7 +7,7 @@ export const confirmLoginBodySchema = z.object({
7
7
  passkeyOptions: z.any().optional(),
8
8
  }).strict();
9
9
  export const confirmLoginWithPasskeyBodySchema = z.object({
10
- passkeyResponse: z.any().optional(),
10
+ passkeyResponse: z.record(z.string(), z.any()),
11
11
  rememberMe: z.boolean().optional(),
12
12
  }).strict();
13
13
  export const verifyTotpBodySchema = z.object({
@@ -16,11 +16,11 @@ export const verifyTotpBodySchema = z.object({
16
16
  // passkey endpoints
17
17
  export const registrationOptionsBodySchema = z.object({
18
18
  mode: z.string().nullish(),
19
- confirmationResult: z.any().optional(),
19
+ confirmationResult: z.record(z.string(), z.any()),
20
20
  }).strict();
21
21
  export const finishRegistrationBodySchema = z.object({
22
22
  credential: z.any(),
23
- origin: z.string().optional(),
23
+ origin: z.string(),
24
24
  }).strict();
25
25
  export const deletePasskeyBodySchema = z.object({
26
26
  passkeyId: z.string(),
@@ -31,5 +31,5 @@ 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.any().optional(),
34
+ confirmationResult: z.record(z.string(), z.any()),
35
35
  }).strict();
@@ -199,6 +199,10 @@ export class PasskeyService {
199
199
  const credentialID = credential.id;
200
200
  const base64CredentialID = credentialID;
201
201
  const base64PublicKey = isoBase64URL.fromBuffer(credentialPublicKey);
202
+ const existingPasskey = yield this.passkeyRepository.getByCredentialId(base64CredentialID);
203
+ if (existingPasskey) {
204
+ throw new Error('This passkey is already registered');
205
+ }
202
206
  yield this.passkeyRepository.create({
203
207
  [this.options.passkeys.credentialIdFieldName]: base64CredentialID,
204
208
  [this.options.passkeys.credentialUserIdFieldName]: adminUser.pk,
@@ -9,7 +9,7 @@ export const confirmLoginBodySchema = z.object({
9
9
  }).strict();
10
10
 
11
11
  export const confirmLoginWithPasskeyBodySchema = z.object({
12
- passkeyResponse: z.any().optional(),
12
+ passkeyResponse: z.record(z.string(), z.any()),
13
13
  rememberMe: z.boolean().optional(),
14
14
  }).strict();
15
15
 
@@ -20,12 +20,12 @@ export const verifyTotpBodySchema = z.object({
20
20
  // passkey endpoints
21
21
  export const registrationOptionsBodySchema = z.object({
22
22
  mode: z.string().nullish(),
23
- confirmationResult: z.any().optional(),
23
+ confirmationResult: z.record(z.string(), z.any()),
24
24
  }).strict();
25
25
 
26
26
  export const finishRegistrationBodySchema = z.object({
27
27
  credential: z.any(),
28
- origin: z.string().optional(),
28
+ origin: z.string(),
29
29
  }).strict();
30
30
 
31
31
  export const deletePasskeyBodySchema = z.object({
@@ -39,5 +39,5 @@ 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.any().optional(),
42
+ confirmationResult: z.record(z.string(), z.any()),
43
43
  }).strict();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/two-factors-auth",
3
- "version": "4.3.0",
3
+ "version": "4.3.2",
4
4
  "description": "AdminForth plugin for two factors authentication",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -214,6 +214,11 @@ export class PasskeyService {
214
214
  const base64CredentialID = credentialID;
215
215
  const base64PublicKey = isoBase64URL.fromBuffer(credentialPublicKey);
216
216
 
217
+ const existingPasskey = await this.passkeyRepository.getByCredentialId(base64CredentialID);
218
+ if (existingPasskey) {
219
+ throw new Error('This passkey is already registered');
220
+ }
221
+
217
222
  await this.passkeyRepository.create({
218
223
  [this.options.passkeys.credentialIdFieldName] : base64CredentialID,
219
224
  [this.options.passkeys.credentialUserIdFieldName] : adminUser.pk,