@adminforth/two-factors-auth 3.3.4 → 3.3.5
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/TwoFAModal.vue +36 -21
- package/dist/custom/TwoFAModal.vue +36 -21
- package/dist/index.js +32 -25
- package/index.ts +34 -28
- package/package.json +1 -1
package/build.log
CHANGED
|
@@ -16,5 +16,5 @@ custom/pnpm-lock.yaml
|
|
|
16
16
|
custom/tsconfig.json
|
|
17
17
|
custom/utils.js
|
|
18
18
|
|
|
19
|
-
sent 286,
|
|
20
|
-
total size is 285,
|
|
19
|
+
sent 286,569 bytes received 229 bytes 573,596.00 bytes/sec
|
|
20
|
+
total size is 285,663 speedup is 1.00
|
package/custom/TwoFAModal.vue
CHANGED
|
@@ -164,7 +164,9 @@
|
|
|
164
164
|
isAwaiting2FAResult.value = true;
|
|
165
165
|
confirmationResult = await window.adminforthTwoFaModal.get2FaConfirmationResult();
|
|
166
166
|
} catch (error) {
|
|
167
|
-
|
|
167
|
+
if (!isTwoFaCancel(error)) {
|
|
168
|
+
console.error('[AdminForth 2FA] Error during 2FA confirmation', error);
|
|
169
|
+
}
|
|
168
170
|
}
|
|
169
171
|
isAwaiting2FAResult.value = false;
|
|
170
172
|
try {
|
|
@@ -226,28 +228,41 @@
|
|
|
226
228
|
let verifyFn: null | ((confirmationResult: string) => Promise<boolean> | boolean) = null;
|
|
227
229
|
let rejectFn: ((err?: any) => void) | null = null;
|
|
228
230
|
|
|
231
|
+
function isTwoFaCancel(error: unknown) {
|
|
232
|
+
return error === 'Cancel';
|
|
233
|
+
}
|
|
234
|
+
|
|
229
235
|
|
|
230
236
|
window.adminforthTwoFaModal = {
|
|
231
237
|
get2FaConfirmationResult: (title?: string, verifyingCallback?: (confirmationResult: string) => Promise<boolean>) =>
|
|
232
|
-
new Promise(
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
238
|
+
new Promise((resolve, reject) => {
|
|
239
|
+
(async () => {
|
|
240
|
+
if (modelShow.value) {
|
|
241
|
+
throw new Error(t('Modal is already open'));
|
|
242
|
+
}
|
|
243
|
+
const skipAllowModal = await checkIfSkipAllowModal();
|
|
244
|
+
if (skipAllowModal) {
|
|
245
|
+
resolve({ code: "123456" }); // dummy code
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
await checkIfUserHasPasskeys();
|
|
249
|
+
if (title) {
|
|
250
|
+
customDialogTitle.value = title;
|
|
251
|
+
}
|
|
252
|
+
resolveFn = resolve;
|
|
253
|
+
rejectFn = reject;
|
|
254
|
+
verifyFn = verifyingCallback ?? null;
|
|
255
|
+
modelShow.value = true;
|
|
256
|
+
if (modalMode.value === 'totp') {
|
|
257
|
+
await addEventListenerForOTPInput();
|
|
258
|
+
}
|
|
259
|
+
})().catch((error) => {
|
|
260
|
+
if (!isTwoFaCancel(error)) {
|
|
261
|
+
console.error('[AdminForth 2FA] Failed to open 2FA modal', error);
|
|
262
|
+
}
|
|
263
|
+
reject(error);
|
|
264
|
+
});
|
|
265
|
+
}),
|
|
251
266
|
};
|
|
252
267
|
|
|
253
268
|
const { t } = useI18n();
|
|
@@ -471,4 +486,4 @@
|
|
|
471
486
|
display: flex;
|
|
472
487
|
gap: 0.75rem;
|
|
473
488
|
}
|
|
474
|
-
</style>
|
|
489
|
+
</style>
|
|
@@ -164,7 +164,9 @@
|
|
|
164
164
|
isAwaiting2FAResult.value = true;
|
|
165
165
|
confirmationResult = await window.adminforthTwoFaModal.get2FaConfirmationResult();
|
|
166
166
|
} catch (error) {
|
|
167
|
-
|
|
167
|
+
if (!isTwoFaCancel(error)) {
|
|
168
|
+
console.error('[AdminForth 2FA] Error during 2FA confirmation', error);
|
|
169
|
+
}
|
|
168
170
|
}
|
|
169
171
|
isAwaiting2FAResult.value = false;
|
|
170
172
|
try {
|
|
@@ -226,28 +228,41 @@
|
|
|
226
228
|
let verifyFn: null | ((confirmationResult: string) => Promise<boolean> | boolean) = null;
|
|
227
229
|
let rejectFn: ((err?: any) => void) | null = null;
|
|
228
230
|
|
|
231
|
+
function isTwoFaCancel(error: unknown) {
|
|
232
|
+
return error === 'Cancel';
|
|
233
|
+
}
|
|
234
|
+
|
|
229
235
|
|
|
230
236
|
window.adminforthTwoFaModal = {
|
|
231
237
|
get2FaConfirmationResult: (title?: string, verifyingCallback?: (confirmationResult: string) => Promise<boolean>) =>
|
|
232
|
-
new Promise(
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
238
|
+
new Promise((resolve, reject) => {
|
|
239
|
+
(async () => {
|
|
240
|
+
if (modelShow.value) {
|
|
241
|
+
throw new Error(t('Modal is already open'));
|
|
242
|
+
}
|
|
243
|
+
const skipAllowModal = await checkIfSkipAllowModal();
|
|
244
|
+
if (skipAllowModal) {
|
|
245
|
+
resolve({ code: "123456" }); // dummy code
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
await checkIfUserHasPasskeys();
|
|
249
|
+
if (title) {
|
|
250
|
+
customDialogTitle.value = title;
|
|
251
|
+
}
|
|
252
|
+
resolveFn = resolve;
|
|
253
|
+
rejectFn = reject;
|
|
254
|
+
verifyFn = verifyingCallback ?? null;
|
|
255
|
+
modelShow.value = true;
|
|
256
|
+
if (modalMode.value === 'totp') {
|
|
257
|
+
await addEventListenerForOTPInput();
|
|
258
|
+
}
|
|
259
|
+
})().catch((error) => {
|
|
260
|
+
if (!isTwoFaCancel(error)) {
|
|
261
|
+
console.error('[AdminForth 2FA] Failed to open 2FA modal', error);
|
|
262
|
+
}
|
|
263
|
+
reject(error);
|
|
264
|
+
});
|
|
265
|
+
}),
|
|
251
266
|
};
|
|
252
267
|
|
|
253
268
|
const { t } = useI18n();
|
|
@@ -471,4 +486,4 @@
|
|
|
471
486
|
display: flex;
|
|
472
487
|
gap: 0.75rem;
|
|
473
488
|
}
|
|
474
|
-
</style>
|
|
489
|
+
</style>
|
package/dist/index.js
CHANGED
|
@@ -1035,42 +1035,49 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
1035
1035
|
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response, cookies, headers }) {
|
|
1036
1036
|
const sessionsIds = body === null || body === void 0 ? void 0 : body.sessionsIds;
|
|
1037
1037
|
const confirmationResult = body === null || body === void 0 ? void 0 : body.confirmationResult;
|
|
1038
|
-
const idsToResolve = sessionsIds;
|
|
1038
|
+
const idsToResolve = Array.isArray(sessionsIds) ? sessionsIds : [];
|
|
1039
1039
|
const resolveAllIdsAsFailed = (message) => {
|
|
1040
1040
|
for (const id of idsToResolve) {
|
|
1041
1041
|
this.resolveResponse(id, { ok: false, error: message });
|
|
1042
1042
|
}
|
|
1043
1043
|
return { ok: false, error: message };
|
|
1044
1044
|
};
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
for (const id of idsToResolve) {
|
|
1049
|
-
const validationResult = yield this.adminforth.auth.verify(id, 'auto2FA', false);
|
|
1050
|
-
if (!validationResult) {
|
|
1051
|
-
return (resolveAllIdsAsFailed('Invalid session ID or confirmation result'));
|
|
1045
|
+
try {
|
|
1046
|
+
if (!idsToResolve.length || !confirmationResult) {
|
|
1047
|
+
return (resolveAllIdsAsFailed('Confirmation window was closed or did not return required data'));
|
|
1052
1048
|
}
|
|
1053
|
-
|
|
1054
|
-
|
|
1049
|
+
for (const id of idsToResolve) {
|
|
1050
|
+
const validationResult = yield this.adminforth.auth.verify(id, 'auto2FA', false);
|
|
1051
|
+
if (!validationResult) {
|
|
1052
|
+
return (resolveAllIdsAsFailed('Invalid session ID or confirmation result'));
|
|
1053
|
+
}
|
|
1054
|
+
if (validationResult.adminUserPk !== adminUser.pk) {
|
|
1055
|
+
return (resolveAllIdsAsFailed('Session does not belong to the authenticated user'));
|
|
1056
|
+
}
|
|
1055
1057
|
}
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1058
|
+
const verificationResult = yield this.verify(confirmationResult, {
|
|
1059
|
+
adminUser: adminUser,
|
|
1060
|
+
userPk: adminUser.pk,
|
|
1061
|
+
cookies: cookies,
|
|
1062
|
+
response: response,
|
|
1063
|
+
extra: {
|
|
1064
|
+
headers: headers,
|
|
1065
|
+
}
|
|
1066
|
+
});
|
|
1067
|
+
if (!verificationResult || !('ok' in verificationResult)) {
|
|
1068
|
+
return (resolveAllIdsAsFailed('Verification failed'));
|
|
1069
|
+
}
|
|
1070
|
+
if ('ok' in verificationResult && verificationResult.ok) {
|
|
1071
|
+
for (const id of idsToResolve) {
|
|
1072
|
+
this.resolveResponse(id, { ok: true, passkeyConfirmed: verificationResult });
|
|
1073
|
+
}
|
|
1074
|
+
return { ok: true };
|
|
1064
1075
|
}
|
|
1065
|
-
});
|
|
1066
|
-
if (!verificationResult || !('ok' in verificationResult)) {
|
|
1067
1076
|
return (resolveAllIdsAsFailed('Verification failed'));
|
|
1068
1077
|
}
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
}
|
|
1073
|
-
return { ok: true };
|
|
1078
|
+
catch (error) {
|
|
1079
|
+
console.error('[AdminForth 2FA] Error resolving automatic 2FA verification', error);
|
|
1080
|
+
return (resolveAllIdsAsFailed(error instanceof Error ? error.message : 'Verification failed'));
|
|
1074
1081
|
}
|
|
1075
1082
|
})
|
|
1076
1083
|
});
|
package/index.ts
CHANGED
|
@@ -1100,7 +1100,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
1100
1100
|
handler: async ({ body, adminUser, response, cookies, headers }) => {
|
|
1101
1101
|
const sessionsIds = body?.sessionsIds;
|
|
1102
1102
|
const confirmationResult = body?.confirmationResult;
|
|
1103
|
-
const idsToResolve = sessionsIds;
|
|
1103
|
+
const idsToResolve = Array.isArray(sessionsIds) ? sessionsIds : [];
|
|
1104
1104
|
|
|
1105
1105
|
const resolveAllIdsAsFailed = (message) => {
|
|
1106
1106
|
for (const id of idsToResolve) {
|
|
@@ -1109,37 +1109,43 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
1109
1109
|
return { ok: false, error: message };
|
|
1110
1110
|
}
|
|
1111
1111
|
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
for (const id of idsToResolve) {
|
|
1117
|
-
const validationResult = await this.adminforth.auth.verify(id, 'auto2FA', false);
|
|
1118
|
-
if (!validationResult) {
|
|
1119
|
-
return(resolveAllIdsAsFailed('Invalid session ID or confirmation result'));
|
|
1120
|
-
}
|
|
1121
|
-
if (validationResult.adminUserPk !== adminUser.pk) {
|
|
1122
|
-
return(resolveAllIdsAsFailed('Session does not belong to the authenticated user'));
|
|
1112
|
+
try {
|
|
1113
|
+
if (!idsToResolve.length || !confirmationResult) {
|
|
1114
|
+
return(resolveAllIdsAsFailed('Confirmation window was closed or did not return required data'));
|
|
1123
1115
|
}
|
|
1124
|
-
}
|
|
1125
1116
|
|
|
1126
|
-
const verificationResult = await this.verify(confirmationResult, {
|
|
1127
|
-
adminUser: adminUser,
|
|
1128
|
-
userPk: adminUser.pk,
|
|
1129
|
-
cookies: cookies,
|
|
1130
|
-
response: response,
|
|
1131
|
-
extra: {
|
|
1132
|
-
headers: headers,
|
|
1133
|
-
} as HttpExtra
|
|
1134
|
-
});
|
|
1135
|
-
if ( !verificationResult || !('ok' in verificationResult) ) {
|
|
1136
|
-
return(resolveAllIdsAsFailed('Verification failed'));
|
|
1137
|
-
}
|
|
1138
|
-
if ('ok' in verificationResult && verificationResult.ok){
|
|
1139
1117
|
for (const id of idsToResolve) {
|
|
1140
|
-
this.
|
|
1118
|
+
const validationResult = await this.adminforth.auth.verify(id, 'auto2FA', false);
|
|
1119
|
+
if (!validationResult) {
|
|
1120
|
+
return(resolveAllIdsAsFailed('Invalid session ID or confirmation result'));
|
|
1121
|
+
}
|
|
1122
|
+
if (validationResult.adminUserPk !== adminUser.pk) {
|
|
1123
|
+
return(resolveAllIdsAsFailed('Session does not belong to the authenticated user'));
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
const verificationResult = await this.verify(confirmationResult, {
|
|
1128
|
+
adminUser: adminUser,
|
|
1129
|
+
userPk: adminUser.pk,
|
|
1130
|
+
cookies: cookies,
|
|
1131
|
+
response: response,
|
|
1132
|
+
extra: {
|
|
1133
|
+
headers: headers,
|
|
1134
|
+
} as HttpExtra
|
|
1135
|
+
});
|
|
1136
|
+
if ( !verificationResult || !('ok' in verificationResult) ) {
|
|
1137
|
+
return(resolveAllIdsAsFailed('Verification failed'));
|
|
1138
|
+
}
|
|
1139
|
+
if ('ok' in verificationResult && verificationResult.ok){
|
|
1140
|
+
for (const id of idsToResolve) {
|
|
1141
|
+
this.resolveResponse(id, { ok: true, passkeyConfirmed: verificationResult });
|
|
1142
|
+
}
|
|
1143
|
+
return { ok: true };
|
|
1141
1144
|
}
|
|
1142
|
-
return
|
|
1145
|
+
return(resolveAllIdsAsFailed('Verification failed'));
|
|
1146
|
+
} catch (error) {
|
|
1147
|
+
console.error('[AdminForth 2FA] Error resolving automatic 2FA verification', error);
|
|
1148
|
+
return(resolveAllIdsAsFailed(error instanceof Error ? error.message : 'Verification failed'));
|
|
1143
1149
|
}
|
|
1144
1150
|
}
|
|
1145
1151
|
});
|