@adminforth/two-factors-auth 4.2.0 → 4.2.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/dist/endpoints/registerTwoFaEndpoints.js +1 -1
- package/dist/handlers/createTwoFaHandlers.d.ts +2 -1
- package/dist/handlers/createTwoFaHandlers.js +5 -1
- package/dist/index.js +3 -4
- package/endpoints/registerTwoFaEndpoints.ts +1 -1
- package/handlers/createTwoFaHandlers.ts +6 -1
- package/index.ts +3 -4
- package/package.json +1 -1
|
@@ -18,7 +18,7 @@ export function registerTwoFaEndpoints(server, handlers) {
|
|
|
18
18
|
method: 'POST',
|
|
19
19
|
path: `/plugin/twofa/confirmLogin`,
|
|
20
20
|
noAuth: true,
|
|
21
|
-
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response, cookies }) { return handlers.confirmLogin({ body, response, cookies }); }),
|
|
21
|
+
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response, cookies, headers }) { return handlers.confirmLogin({ body, response, cookies, headers }); }),
|
|
22
22
|
});
|
|
23
23
|
server.endpoint({
|
|
24
24
|
method: 'POST',
|
|
@@ -5,10 +5,11 @@ export declare function createTwoFaHandlers(ctx: any): {
|
|
|
5
5
|
totpJWT: any;
|
|
6
6
|
status: string;
|
|
7
7
|
}>;
|
|
8
|
-
confirmLogin: ({ body, response, cookies }: {
|
|
8
|
+
confirmLogin: ({ body, response, cookies, headers }: {
|
|
9
9
|
body: any;
|
|
10
10
|
response: any;
|
|
11
11
|
cookies: any;
|
|
12
|
+
headers: any;
|
|
12
13
|
}) => Promise<{
|
|
13
14
|
status: string;
|
|
14
15
|
allowedLogin: boolean;
|
|
@@ -17,8 +17,12 @@ export function createTwoFaHandlers(ctx) {
|
|
|
17
17
|
}
|
|
18
18
|
return toReturn;
|
|
19
19
|
}),
|
|
20
|
-
confirmLogin: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response, cookies }) {
|
|
20
|
+
confirmLogin: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response, cookies, headers }) {
|
|
21
21
|
var _b, _c;
|
|
22
|
+
if (!(yield ctx.checkPasskeyLoginRateLimit(headers))) {
|
|
23
|
+
response.setStatus(429);
|
|
24
|
+
return { error: 'Too many login attempts, please try again later' };
|
|
25
|
+
}
|
|
22
26
|
const totpTemporaryJWT = ctx.cookieService.getTotpTemporary(cookies);
|
|
23
27
|
if (!totpTemporaryJWT) {
|
|
24
28
|
return { error: 'Login session expired. Please log in again.' };
|
package/dist/index.js
CHANGED
|
@@ -45,10 +45,9 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
45
45
|
//check if user has 2FA set up
|
|
46
46
|
const users2FASecret = this.userRepository.getSecret(userRecord);
|
|
47
47
|
//check if user has any passkeys registered
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
48
|
+
const userHasPasskeys = this.options.passkeys
|
|
49
|
+
? yield this.passkeyService.hasPasskeysForUser(adminUser.dbUser[userPkFieldName])
|
|
50
|
+
: false;
|
|
52
51
|
// If user has either 2FA secret or any passkeys, they cannot skip
|
|
53
52
|
if (users2FASecret || userHasPasskeys) {
|
|
54
53
|
return { skipAllowed: false };
|
|
@@ -12,7 +12,7 @@ export function registerTwoFaEndpoints(server: IHttpServer, handlers: any): void
|
|
|
12
12
|
method: 'POST',
|
|
13
13
|
path: `/plugin/twofa/confirmLogin`,
|
|
14
14
|
noAuth: true,
|
|
15
|
-
handler: async ({ body, response, cookies }) => handlers.confirmLogin({ body, response, cookies }),
|
|
15
|
+
handler: async ({ body, response, cookies, headers }) => handlers.confirmLogin({ body, response, cookies, headers }),
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
server.endpoint({
|
|
@@ -9,7 +9,12 @@ export function createTwoFaHandlers(ctx: any) {
|
|
|
9
9
|
return toReturn
|
|
10
10
|
},
|
|
11
11
|
|
|
12
|
-
confirmLogin: async ({ body, response, cookies }) => {
|
|
12
|
+
confirmLogin: async ({ body, response, cookies, headers }) => {
|
|
13
|
+
if (!(await ctx.checkPasskeyLoginRateLimit(headers))) {
|
|
14
|
+
response.setStatus(429);
|
|
15
|
+
return { error: 'Too many login attempts, please try again later' };
|
|
16
|
+
}
|
|
17
|
+
|
|
13
18
|
const totpTemporaryJWT = ctx.cookieService.getTotpTemporary(cookies);
|
|
14
19
|
if (!totpTemporaryJWT) {
|
|
15
20
|
return { error: 'Login session expired. Please log in again.' }
|
package/index.ts
CHANGED
|
@@ -54,10 +54,9 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
54
54
|
//check if user has 2FA set up
|
|
55
55
|
const users2FASecret = this.userRepository.getSecret(userRecord);
|
|
56
56
|
//check if user has any passkeys registered
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
57
|
+
const userHasPasskeys = this.options.passkeys
|
|
58
|
+
? await this.passkeyService.hasPasskeysForUser(adminUser.dbUser[userPkFieldName])
|
|
59
|
+
: false;
|
|
61
60
|
|
|
62
61
|
// If user has either 2FA secret or any passkeys, they cannot skip
|
|
63
62
|
if (users2FASecret || userHasPasskeys) {
|