@adminforth/two-factors-auth 3.3.0 → 3.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/custom/TwoFAModal.vue +1 -1
- package/dist/custom/TwoFAModal.vue +1 -1
- package/dist/index.js +16 -4
- package/index.ts +21 -5
- package/package.json +1 -1
package/custom/TwoFAModal.vue
CHANGED
|
@@ -178,7 +178,7 @@
|
|
|
178
178
|
} else if (!response.ok) {
|
|
179
179
|
alert({message: response.error || t('Verification failed'), variant: 'danger'});
|
|
180
180
|
} else if (response.ok) {
|
|
181
|
-
alert({message:
|
|
181
|
+
// alert({message: 'Verification successful', variant: 'success'});
|
|
182
182
|
}
|
|
183
183
|
sessionsIdsToResolve.value = [];
|
|
184
184
|
} catch (error) {
|
|
@@ -178,7 +178,7 @@
|
|
|
178
178
|
} else if (!response.ok) {
|
|
179
179
|
alert({message: response.error || t('Verification failed'), variant: 'danger'});
|
|
180
180
|
} else if (response.ok) {
|
|
181
|
-
alert({message:
|
|
181
|
+
// alert({message: 'Verification successful', variant: 'success'});
|
|
182
182
|
}
|
|
183
183
|
sessionsIdsToResolve.value = [];
|
|
184
184
|
} catch (error) {
|
package/dist/index.js
CHANGED
|
@@ -134,24 +134,36 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
134
134
|
return false;
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
|
-
waitForResponse(id) {
|
|
137
|
+
waitForResponse(id, timeoutMs) {
|
|
138
138
|
return new Promise((resolve) => {
|
|
139
|
-
|
|
139
|
+
let timeout;
|
|
140
|
+
const cleanup = () => {
|
|
141
|
+
clearTimeout(timeout);
|
|
142
|
+
this.pending.delete(id);
|
|
143
|
+
};
|
|
144
|
+
timeout = setTimeout(() => {
|
|
145
|
+
cleanup();
|
|
146
|
+
resolve({ ok: false, error: 'Verification timed out' });
|
|
147
|
+
}, timeoutMs);
|
|
148
|
+
this.pending.set(id, (value) => {
|
|
149
|
+
cleanup();
|
|
150
|
+
resolve(value);
|
|
151
|
+
});
|
|
140
152
|
});
|
|
141
153
|
}
|
|
142
154
|
resolveResponse(id, data) {
|
|
143
155
|
const resolve = this.pending.get(id);
|
|
144
156
|
if (resolve) {
|
|
145
157
|
resolve(data);
|
|
146
|
-
this.pending.delete(id);
|
|
147
158
|
}
|
|
148
159
|
}
|
|
149
160
|
verifyAuto(adminUser) {
|
|
150
161
|
return __awaiter(this, void 0, void 0, function* () {
|
|
151
162
|
const sessionId = crypto.randomUUID();
|
|
152
163
|
const jwt = this.adminforth.auth.issueJWT({ sessionId, adminUserPk: adminUser.pk }, 'auto2FA', '5m');
|
|
164
|
+
const resultPromise = this.waitForResponse(jwt, 5 * 60 * 1000);
|
|
153
165
|
this.adminforth.websocket.publish(`/user2fa/${adminUser.pk}`, { sessionId: jwt });
|
|
154
|
-
const result = yield
|
|
166
|
+
const result = yield resultPromise;
|
|
155
167
|
this.adminforth.websocket.publish(`/user2fa/${adminUser.pk}-resolve`, { sessionId: jwt });
|
|
156
168
|
return result;
|
|
157
169
|
});
|
package/index.ts
CHANGED
|
@@ -143,9 +143,21 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
143
143
|
|
|
144
144
|
private pending = new Map<string, (value: any) => void>();
|
|
145
145
|
|
|
146
|
-
private waitForResponse(id: string): Promise<any> {
|
|
146
|
+
private waitForResponse(id: string, timeoutMs: number): Promise<any> {
|
|
147
147
|
return new Promise((resolve) => {
|
|
148
|
-
|
|
148
|
+
let timeout: ReturnType<typeof setTimeout>;
|
|
149
|
+
const cleanup = () => {
|
|
150
|
+
clearTimeout(timeout);
|
|
151
|
+
this.pending.delete(id);
|
|
152
|
+
};
|
|
153
|
+
timeout = setTimeout(() => {
|
|
154
|
+
cleanup();
|
|
155
|
+
resolve({ ok: false, error: 'Verification timed out' });
|
|
156
|
+
}, timeoutMs);
|
|
157
|
+
this.pending.set(id, (value: any) => {
|
|
158
|
+
cleanup();
|
|
159
|
+
resolve(value);
|
|
160
|
+
});
|
|
149
161
|
});
|
|
150
162
|
}
|
|
151
163
|
|
|
@@ -153,16 +165,20 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
153
165
|
const resolve = this.pending.get(id);
|
|
154
166
|
if (resolve) {
|
|
155
167
|
resolve(data);
|
|
156
|
-
this.pending.delete(id);
|
|
157
168
|
}
|
|
158
169
|
}
|
|
159
170
|
|
|
160
171
|
public async verifyAuto(adminUser: AdminUser) {
|
|
161
172
|
const sessionId = crypto.randomUUID();
|
|
162
173
|
const jwt = this.adminforth.auth.issueJWT({sessionId, adminUserPk: adminUser.pk}, 'auto2FA', '5m');
|
|
174
|
+
const resultPromise = this.waitForResponse(jwt, 5 * 60 * 1000);
|
|
175
|
+
|
|
163
176
|
this.adminforth.websocket.publish(`/user2fa/${adminUser.pk}`, { sessionId: jwt });
|
|
164
|
-
|
|
177
|
+
|
|
178
|
+
const result = await resultPromise;
|
|
179
|
+
|
|
165
180
|
this.adminforth.websocket.publish(`/user2fa/${adminUser.pk}-resolve`, { sessionId: jwt });
|
|
181
|
+
|
|
166
182
|
return result;
|
|
167
183
|
}
|
|
168
184
|
|
|
@@ -1127,4 +1143,4 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
1127
1143
|
}
|
|
1128
1144
|
});
|
|
1129
1145
|
}
|
|
1130
|
-
}
|
|
1146
|
+
}
|