@adminforth/two-factors-auth 7.4.4 → 7.5.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 +2 -2
- package/custom/TwoFactorsPasskeysSettings.vue +15 -13
- package/dist/custom/TwoFactorsPasskeysSettings.vue +15 -13
- package/dist/endpoints/registerPasskeyEndpoints.js +2 -2
- package/dist/endpoints/validation.d.ts +1 -0
- package/dist/endpoints/validation.js +1 -0
- package/dist/handlers/createPasskeyHandlers.d.ts +3 -1
- package/dist/handlers/createPasskeyHandlers.js +23 -13
- package/endpoints/registerPasskeyEndpoints.ts +2 -2
- package/endpoints/validation.ts +1 -0
- package/handlers/createPasskeyHandlers.ts +29 -17
- package/package.json +1 -1
- package/tests/validation.test.mjs +6 -1
package/build.log
CHANGED
|
@@ -21,5 +21,5 @@ custom/tsconfig.json
|
|
|
21
21
|
custom/use2faApi.ts
|
|
22
22
|
custom/utils.js
|
|
23
23
|
|
|
24
|
-
sent 300,
|
|
25
|
-
total size is 299,
|
|
24
|
+
sent 300,893 bytes received 324 bytes 602,434.00 bytes/sec
|
|
25
|
+
total size is 299,642 speedup is 0.99
|
|
@@ -131,7 +131,7 @@
|
|
|
131
131
|
|
|
132
132
|
<script setup lang="ts">
|
|
133
133
|
import { callAdminForthApi, formatDateTime } from '@/utils';
|
|
134
|
-
import adminforth
|
|
134
|
+
import adminforth from '@/adminforth';
|
|
135
135
|
import { onMounted, ref, Ref } from 'vue';
|
|
136
136
|
import { useI18n } from 'vue-i18n';
|
|
137
137
|
import { Button, Card, Dialog, Tooltip, Spinner, Input } from '@/afcl';
|
|
@@ -287,29 +287,31 @@
|
|
|
287
287
|
}
|
|
288
288
|
|
|
289
289
|
async function confirmAndDelete(passkeyId: string) {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
290
|
+
let confirmationResult: TwoFaConfirmationResult;
|
|
291
|
+
try {
|
|
292
|
+
confirmationResult = await twoFactorsAuth.get2FaConfirmationResult(
|
|
293
|
+
t('To remove passkey first verify yourself')
|
|
294
|
+
);
|
|
295
|
+
} catch {
|
|
296
|
+
// user cancelled 2FA dialog
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
deletePasskey(passkeyId, confirmationResult);
|
|
298
300
|
}
|
|
299
301
|
|
|
300
|
-
async function deletePasskey(passkeyId: string) {
|
|
302
|
+
async function deletePasskey(passkeyId: string, confirmationResult: TwoFaConfirmationResult) {
|
|
301
303
|
try {
|
|
302
304
|
const response = await callAdminForthApi({
|
|
303
305
|
path: '/plugin/passkeys/deletePasskey',
|
|
304
306
|
method: 'DELETE',
|
|
305
|
-
body: { passkeyId },
|
|
307
|
+
body: { passkeyId, confirmationResult },
|
|
306
308
|
});
|
|
307
309
|
if (response.ok) {
|
|
308
310
|
adminforth.alert({ message: t('Passkey deleted successfully!'), variant: 'success' });
|
|
309
311
|
getPasskeys();
|
|
310
312
|
} else {
|
|
311
|
-
console.error('Error deleting passkey:', response
|
|
312
|
-
adminforth.alert({ message: t('Error deleting passkey.'), variant: 'warning' });
|
|
313
|
+
console.error('Error deleting passkey:', response.error);
|
|
314
|
+
adminforth.alert({ message: response.error ?? t('Error deleting passkey.'), variant: 'warning' });
|
|
313
315
|
}
|
|
314
316
|
} catch (error) {
|
|
315
317
|
console.error('Error deleting passkey:', error);
|
|
@@ -131,7 +131,7 @@
|
|
|
131
131
|
|
|
132
132
|
<script setup lang="ts">
|
|
133
133
|
import { callAdminForthApi, formatDateTime } from '@/utils';
|
|
134
|
-
import adminforth
|
|
134
|
+
import adminforth from '@/adminforth';
|
|
135
135
|
import { onMounted, ref, Ref } from 'vue';
|
|
136
136
|
import { useI18n } from 'vue-i18n';
|
|
137
137
|
import { Button, Card, Dialog, Tooltip, Spinner, Input } from '@/afcl';
|
|
@@ -287,29 +287,31 @@
|
|
|
287
287
|
}
|
|
288
288
|
|
|
289
289
|
async function confirmAndDelete(passkeyId: string) {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
290
|
+
let confirmationResult: TwoFaConfirmationResult;
|
|
291
|
+
try {
|
|
292
|
+
confirmationResult = await twoFactorsAuth.get2FaConfirmationResult(
|
|
293
|
+
t('To remove passkey first verify yourself')
|
|
294
|
+
);
|
|
295
|
+
} catch {
|
|
296
|
+
// user cancelled 2FA dialog
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
deletePasskey(passkeyId, confirmationResult);
|
|
298
300
|
}
|
|
299
301
|
|
|
300
|
-
async function deletePasskey(passkeyId: string) {
|
|
302
|
+
async function deletePasskey(passkeyId: string, confirmationResult: TwoFaConfirmationResult) {
|
|
301
303
|
try {
|
|
302
304
|
const response = await callAdminForthApi({
|
|
303
305
|
path: '/plugin/passkeys/deletePasskey',
|
|
304
306
|
method: 'DELETE',
|
|
305
|
-
body: { passkeyId },
|
|
307
|
+
body: { passkeyId, confirmationResult },
|
|
306
308
|
});
|
|
307
309
|
if (response.ok) {
|
|
308
310
|
adminforth.alert({ message: t('Passkey deleted successfully!'), variant: 'success' });
|
|
309
311
|
getPasskeys();
|
|
310
312
|
} else {
|
|
311
|
-
console.error('Error deleting passkey:', response
|
|
312
|
-
adminforth.alert({ message: t('Error deleting passkey.'), variant: 'warning' });
|
|
313
|
+
console.error('Error deleting passkey:', response.error);
|
|
314
|
+
adminforth.alert({ message: response.error ?? t('Error deleting passkey.'), variant: 'warning' });
|
|
313
315
|
}
|
|
314
316
|
} catch (error) {
|
|
315
317
|
console.error('Error deleting passkey:', error);
|
|
@@ -59,8 +59,8 @@ export function registerPasskeyEndpoints(server, handlers) {
|
|
|
59
59
|
},
|
|
60
60
|
noAuth: false,
|
|
61
61
|
request_schema: deletePasskeyBodySchema,
|
|
62
|
-
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response }) {
|
|
63
|
-
return handlers.deletePasskey({ body, adminUser, response });
|
|
62
|
+
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response, cookies, headers }) {
|
|
63
|
+
return handlers.deletePasskey({ body, adminUser, response, cookies, headers });
|
|
64
64
|
}),
|
|
65
65
|
});
|
|
66
66
|
server.endpoint({
|
|
@@ -22,6 +22,7 @@ export declare const finishRegistrationBodySchema: z.ZodObject<{
|
|
|
22
22
|
}, z.core.$strict>;
|
|
23
23
|
export declare const deletePasskeyBodySchema: z.ZodObject<{
|
|
24
24
|
passkeyId: z.ZodString;
|
|
25
|
+
confirmationResult: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
25
26
|
}, z.core.$strict>;
|
|
26
27
|
export declare const renamePasskeyBodySchema: z.ZodObject<{
|
|
27
28
|
passkeyId: z.ZodString;
|
|
@@ -24,6 +24,7 @@ export const finishRegistrationBodySchema = z.object({
|
|
|
24
24
|
}).strict();
|
|
25
25
|
export const deletePasskeyBodySchema = z.object({
|
|
26
26
|
passkeyId: z.string(),
|
|
27
|
+
confirmationResult: z.record(z.string(), z.any()),
|
|
27
28
|
}).strict();
|
|
28
29
|
export const renamePasskeyBodySchema = z.object({
|
|
29
30
|
passkeyId: z.string(),
|
|
@@ -20,10 +20,12 @@ export declare function createPasskeyHandlers(ctx: any): {
|
|
|
20
20
|
getPasskeys: ({ adminUser }: {
|
|
21
21
|
adminUser: any;
|
|
22
22
|
}) => Promise<any>;
|
|
23
|
-
deletePasskey: ({ body, adminUser, response }: {
|
|
23
|
+
deletePasskey: ({ body, adminUser, response, cookies, headers }: {
|
|
24
24
|
body: any;
|
|
25
25
|
adminUser: any;
|
|
26
26
|
response: any;
|
|
27
|
+
cookies: any;
|
|
28
|
+
headers: any;
|
|
27
29
|
}) => Promise<any>;
|
|
28
30
|
renamePasskey: ({ body, adminUser, response }: {
|
|
29
31
|
body: any;
|
|
@@ -9,21 +9,27 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { HttpStatus, TwoFactorErrorCode, errorMessage, respondWithStatus } from "../utils/errors.js";
|
|
11
11
|
export function createPasskeyHandlers(ctx) {
|
|
12
|
+
// returns a 403 response when the 2FA confirmation fails, nothing when it passes
|
|
13
|
+
const rejectUnconfirmed = (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response, cookies, headers }) {
|
|
14
|
+
const verificationResult = yield ctx.verifyMfaConfirmation(body === null || body === void 0 ? void 0 : body.confirmationResult, {
|
|
15
|
+
adminUser: adminUser,
|
|
16
|
+
userPk: adminUser.pk,
|
|
17
|
+
cookies: cookies,
|
|
18
|
+
response: response,
|
|
19
|
+
extra: {
|
|
20
|
+
headers,
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
if (!verificationResult || !('ok' in verificationResult)) {
|
|
24
|
+
return respondWithStatus({ ok: false, error: 'error' in verificationResult ? verificationResult.error : 'Verification failed' }, response, HttpStatus.FORBIDDEN);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
12
27
|
return {
|
|
13
28
|
createRegistrationOptions: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response, cookies, headers }) {
|
|
14
29
|
const mode = body === null || body === void 0 ? void 0 : body.mode;
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
userPk: adminUser.pk,
|
|
19
|
-
cookies: cookies,
|
|
20
|
-
response: response,
|
|
21
|
-
extra: {
|
|
22
|
-
headers,
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
if (!verificationResult || !('ok' in verificationResult)) {
|
|
26
|
-
return respondWithStatus({ ok: false, error: 'error' in verificationResult ? verificationResult.error : 'Verification failed' }, response, HttpStatus.FORBIDDEN);
|
|
30
|
+
const rejected = yield rejectUnconfirmed({ body, adminUser, response, cookies, headers });
|
|
31
|
+
if (rejected) {
|
|
32
|
+
return rejected;
|
|
27
33
|
}
|
|
28
34
|
const registrationOptions = yield ctx.passkeyService.createRegistrationOptions(mode, adminUser, response);
|
|
29
35
|
if (!registrationOptions.ok) {
|
|
@@ -51,7 +57,11 @@ export function createPasskeyHandlers(ctx) {
|
|
|
51
57
|
getPasskeys: (_a) => __awaiter(this, [_a], void 0, function* ({ adminUser }) {
|
|
52
58
|
return ctx.passkeyService.getPasskeys(adminUser);
|
|
53
59
|
}),
|
|
54
|
-
deletePasskey: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response }) {
|
|
60
|
+
deletePasskey: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response, cookies, headers }) {
|
|
61
|
+
const rejected = yield rejectUnconfirmed({ body, adminUser, response, cookies, headers });
|
|
62
|
+
if (rejected) {
|
|
63
|
+
return rejected;
|
|
64
|
+
}
|
|
55
65
|
const deleteResult = yield ctx.passkeyService.deletePasskey(body.passkeyId, adminUser);
|
|
56
66
|
if (!deleteResult.ok) {
|
|
57
67
|
return respondWithStatus(deleteResult, response, HttpStatus.NOT_FOUND);
|
|
@@ -62,8 +62,8 @@ export function registerPasskeyEndpoints(server: IHttpServer, handlers: any): vo
|
|
|
62
62
|
},
|
|
63
63
|
noAuth: false,
|
|
64
64
|
request_schema: deletePasskeyBodySchema,
|
|
65
|
-
handler: async ({ body, adminUser, response }) => {
|
|
66
|
-
return handlers.deletePasskey({ body, adminUser, response });
|
|
65
|
+
handler: async ({ body, adminUser, response, cookies, headers }) => {
|
|
66
|
+
return handlers.deletePasskey({ body, adminUser, response, cookies, headers });
|
|
67
67
|
},
|
|
68
68
|
});
|
|
69
69
|
|
package/endpoints/validation.ts
CHANGED
|
@@ -30,6 +30,7 @@ export const finishRegistrationBodySchema = z.object({
|
|
|
30
30
|
|
|
31
31
|
export const deletePasskeyBodySchema = z.object({
|
|
32
32
|
passkeyId: z.string(),
|
|
33
|
+
confirmationResult: z.record(z.string(), z.any()),
|
|
33
34
|
}).strict();
|
|
34
35
|
|
|
35
36
|
export const renamePasskeyBodySchema = z.object({
|
|
@@ -3,26 +3,33 @@ import { HttpStatus, TwoFactorErrorCode, errorMessage, respondWithStatus } from
|
|
|
3
3
|
import type { VerificationResult } from "../utils/types.js";
|
|
4
4
|
|
|
5
5
|
export function createPasskeyHandlers(ctx: any) {
|
|
6
|
+
// returns a 403 response when the 2FA confirmation fails, nothing when it passes
|
|
7
|
+
const rejectUnconfirmed = async ({ body, adminUser, response, cookies, headers }) => {
|
|
8
|
+
const verificationResult = await ctx.verifyMfaConfirmation(body?.confirmationResult, {
|
|
9
|
+
adminUser: adminUser,
|
|
10
|
+
userPk: adminUser.pk,
|
|
11
|
+
cookies: cookies,
|
|
12
|
+
response: response,
|
|
13
|
+
extra: {
|
|
14
|
+
headers,
|
|
15
|
+
} as HttpExtra
|
|
16
|
+
});
|
|
17
|
+
if (!verificationResult || !('ok' in verificationResult)) {
|
|
18
|
+
return respondWithStatus(
|
|
19
|
+
{ ok: false, error: 'error' in verificationResult ? verificationResult.error : 'Verification failed' },
|
|
20
|
+
response,
|
|
21
|
+
HttpStatus.FORBIDDEN,
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
6
26
|
return {
|
|
7
27
|
createRegistrationOptions: async ({ body, adminUser, response, cookies, headers }) => {
|
|
8
28
|
const mode = body?.mode;
|
|
9
29
|
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
userPk: adminUser.pk,
|
|
14
|
-
cookies: cookies,
|
|
15
|
-
response: response,
|
|
16
|
-
extra: {
|
|
17
|
-
headers,
|
|
18
|
-
} as HttpExtra
|
|
19
|
-
});
|
|
20
|
-
if (!verificationResult || !('ok' in verificationResult)) {
|
|
21
|
-
return respondWithStatus(
|
|
22
|
-
{ ok: false, error: 'error' in verificationResult ? verificationResult.error : 'Verification failed' },
|
|
23
|
-
response,
|
|
24
|
-
HttpStatus.FORBIDDEN,
|
|
25
|
-
);
|
|
30
|
+
const rejected = await rejectUnconfirmed({ body, adminUser, response, cookies, headers });
|
|
31
|
+
if (rejected) {
|
|
32
|
+
return rejected;
|
|
26
33
|
}
|
|
27
34
|
|
|
28
35
|
const registrationOptions = await ctx.passkeyService.createRegistrationOptions(mode, adminUser, response);
|
|
@@ -55,7 +62,12 @@ export function createPasskeyHandlers(ctx: any) {
|
|
|
55
62
|
return ctx.passkeyService.getPasskeys(adminUser);
|
|
56
63
|
},
|
|
57
64
|
|
|
58
|
-
deletePasskey: async ({ body, adminUser, response }) => {
|
|
65
|
+
deletePasskey: async ({ body, adminUser, response, cookies, headers }) => {
|
|
66
|
+
const rejected = await rejectUnconfirmed({ body, adminUser, response, cookies, headers });
|
|
67
|
+
if (rejected) {
|
|
68
|
+
return rejected;
|
|
69
|
+
}
|
|
70
|
+
|
|
59
71
|
const deleteResult = await ctx.passkeyService.deletePasskey(body.passkeyId, adminUser);
|
|
60
72
|
if (!deleteResult.ok) {
|
|
61
73
|
return respondWithStatus(deleteResult, response, HttpStatus.NOT_FOUND);
|
package/package.json
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import test from 'node:test';
|
|
2
2
|
import assert from 'node:assert/strict';
|
|
3
|
-
import { resolveVerifyAutoBodySchema } from '../dist/endpoints/validation.js';
|
|
3
|
+
import { resolveVerifyAutoBodySchema, deletePasskeyBodySchema } from '../dist/endpoints/validation.js';
|
|
4
4
|
|
|
5
5
|
test('resolveVerifyAuto accepts a cancelled confirmation, so the handler can release the waiting request', () => {
|
|
6
6
|
// TwoFAModal sends confirmationResult: undefined on Cancel, JSON drops it
|
|
7
7
|
const cancelBody = JSON.parse(JSON.stringify({ confirmationResult: undefined, sessionsIds: ['session'] }));
|
|
8
8
|
assert.equal(resolveVerifyAutoBodySchema.safeParse(cancelBody).success, true);
|
|
9
9
|
});
|
|
10
|
+
|
|
11
|
+
test('deletePasskey requires a 2FA confirmation result', () => {
|
|
12
|
+
assert.equal(deletePasskeyBodySchema.safeParse({ passkeyId: 'id' }).success, false);
|
|
13
|
+
assert.equal(deletePasskeyBodySchema.safeParse({ passkeyId: 'id', confirmationResult: { mode: 'totp', result: '123456' } }).success, true);
|
|
14
|
+
});
|