@adminforth/two-factors-auth 4.4.8 → 4.4.9

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.
@@ -20,8 +20,8 @@ export function registerTwoFaEndpoints(server, handlers) {
20
20
  path: `/plugin/twofa/confirmLogin`,
21
21
  noAuth: true,
22
22
  request_schema: confirmLoginBodySchema,
23
- handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response, cookies, headers }) {
24
- return handlers.confirmLogin({ body, response, cookies, headers });
23
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response, cookies, headers, requestUrl, query }) {
24
+ return handlers.confirmLogin({ body, response, cookies, headers, requestUrl, query });
25
25
  }),
26
26
  });
27
27
  server.endpoint({
@@ -5,11 +5,13 @@ export declare function createTwoFaHandlers(ctx: any): {
5
5
  totpJWT: any;
6
6
  status: string;
7
7
  }>;
8
- confirmLogin: ({ body, response, cookies, headers }: {
8
+ confirmLogin: ({ body, response, cookies, headers, requestUrl, query }: {
9
9
  body: any;
10
10
  response: any;
11
11
  cookies: any;
12
12
  headers: any;
13
+ requestUrl: any;
14
+ query: any;
13
15
  }) => Promise<{
14
16
  error: any;
15
17
  } | {
@@ -18,8 +18,9 @@ export function createTwoFaHandlers(ctx) {
18
18
  }
19
19
  return toReturn;
20
20
  }),
21
- confirmLogin: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response, cookies, headers }) {
21
+ confirmLogin: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response, cookies, headers, requestUrl, query }) {
22
22
  var _b, _c;
23
+ const extra = { body, headers, cookies, query, requestUrl, response };
23
24
  if (!(yield ctx.checkPasskeyLoginRateLimit(headers))) {
24
25
  return respondWithStatus({ error: 'Too many login attempts, please try again later' }, response, HttpStatus.TOO_MANY_REQUESTS);
25
26
  }
@@ -38,7 +39,7 @@ export function createTwoFaHandlers(ctx) {
38
39
  yield ctx.totpService.saveSecret(decoded.pk, decoded.newSecret);
39
40
  }
40
41
  ctx.cookieService.removeTotpTemporary(response);
41
- yield ctx.cookieService.setAuthCookie({ expireInDuration: decoded.sessionDuration, response, username: decoded.userName, pk: decoded.pk });
42
+ yield ctx.cookieService.setAuthCookie({ expireInDuration: decoded.sessionDuration, response, username: decoded.userName, pk: decoded.pk, extra });
42
43
  return { status: 'ok', allowedLogin: true };
43
44
  }
44
45
  else {
@@ -69,7 +70,7 @@ export function createTwoFaHandlers(ctx) {
69
70
  }
70
71
  if (verified) {
71
72
  ctx.cookieService.removeTotpTemporary(response);
72
- yield ctx.cookieService.setAuthCookie({ expireInDuration: decoded.sessionDuration, response, username: decoded.userName, pk: decoded.pk });
73
+ yield ctx.cookieService.setAuthCookie({ expireInDuration: decoded.sessionDuration, response, username: decoded.userName, pk: decoded.pk, extra });
73
74
  return { status: 'ok', allowedLogin: true };
74
75
  }
75
76
  else {
@@ -108,7 +109,7 @@ export function createTwoFaHandlers(ctx) {
108
109
  const expireInDuration = rememberMe
109
110
  ? ((_b = rememberDaysAfterPasskeyLogin !== null && rememberDaysAfterPasskeyLogin !== void 0 ? rememberDaysAfterPasskeyLogin : ctx.adminforth.config.auth.rememberMeDuration) !== null && _b !== void 0 ? _b : '30d')
110
111
  : '1d';
111
- yield ctx.adminforth.restApi.processLoginCallbacks(adminUser, toReturn, response, {
112
+ const extra = {
112
113
  headers,
113
114
  cookies,
114
115
  requestUrl,
@@ -118,13 +119,15 @@ export function createTwoFaHandlers(ctx) {
118
119
  meta: {
119
120
  loginAllowedByPasskeyDirectSignIn: true
120
121
  },
121
- }, expireInDuration);
122
+ };
123
+ yield ctx.adminforth.restApi.processLoginCallbacks(adminUser, toReturn, response, extra, expireInDuration);
122
124
  if (toReturn.allowedLogin === true) {
123
125
  yield ctx.cookieService.setAuthCookie({
124
126
  response,
125
127
  username,
126
128
  pk: userPk,
127
129
  expireInDuration,
130
+ extra,
128
131
  });
129
132
  }
130
133
  return toReturn;
@@ -1,4 +1,4 @@
1
- import type { IAdminForth, IAdminForthHttpResponse } from "adminforth";
1
+ import type { HttpExtra, IAdminForth, IAdminForthHttpResponse } from "adminforth";
2
2
  import type { PluginOptions } from "../types.js";
3
3
  import type { CookieList, HttpHeaders } from "../utils/types.js";
4
4
  export type TotpTemporaryPayload = {
@@ -30,6 +30,7 @@ export declare class CookieService {
30
30
  username: string;
31
31
  pk: string;
32
32
  expireInDuration: string;
33
+ extra: HttpExtra;
33
34
  }): Promise<string>;
34
35
  getTotpTemporary(cookies: CookieList): string | null;
35
36
  verifyTotpTemporary(cookies: CookieList): Promise<TotpTemporaryPayload | null>;
@@ -18,8 +18,8 @@ export function registerTwoFaEndpoints(server: IHttpServer, handlers: any): void
18
18
  path: `/plugin/twofa/confirmLogin`,
19
19
  noAuth: true,
20
20
  request_schema: confirmLoginBodySchema,
21
- handler: async ({ body, response, cookies, headers }) => {
22
- return handlers.confirmLogin({ body, response, cookies, headers });
21
+ handler: async ({ body, response, cookies, headers, requestUrl, query }) => {
22
+ return handlers.confirmLogin({ body, response, cookies, headers, requestUrl, query });
23
23
  },
24
24
  });
25
25
 
@@ -11,7 +11,8 @@ export function createTwoFaHandlers(ctx: any) {
11
11
  return toReturn
12
12
  },
13
13
 
14
- confirmLogin: async ({ body, response, cookies, headers }) => {
14
+ confirmLogin: async ({ body, response, cookies, headers, requestUrl, query }) => {
15
+ const extra = { body, headers, cookies, query, requestUrl, response };
15
16
  if (!(await ctx.checkPasskeyLoginRateLimit(headers))) {
16
17
  return respondWithStatus({ error: 'Too many login attempts, please try again later' }, response, HttpStatus.TOO_MANY_REQUESTS);
17
18
  }
@@ -32,7 +33,7 @@ export function createTwoFaHandlers(ctx: any) {
32
33
  await ctx.totpService.saveSecret(decoded.pk, decoded.newSecret);
33
34
  }
34
35
  ctx.cookieService.removeTotpTemporary(response)
35
- await ctx.cookieService.setAuthCookie({expireInDuration: decoded.sessionDuration, response, username:decoded.userName, pk:decoded.pk})
36
+ await ctx.cookieService.setAuthCookie({expireInDuration: decoded.sessionDuration, response, username:decoded.userName, pk:decoded.pk, extra})
36
37
  return { status: 'ok', allowedLogin: true }
37
38
  } else {
38
39
  return respondWithStatus({ error: 'Wrong or expired OTP code' }, response, HttpStatus.FORBIDDEN)
@@ -61,7 +62,7 @@ export function createTwoFaHandlers(ctx: any) {
61
62
  }
62
63
  if (verified) {
63
64
  ctx.cookieService.removeTotpTemporary(response)
64
- await ctx.cookieService.setAuthCookie({expireInDuration: decoded.sessionDuration, response, username:decoded.userName, pk:decoded.pk})
65
+ await ctx.cookieService.setAuthCookie({expireInDuration: decoded.sessionDuration, response, username:decoded.userName, pk:decoded.pk, extra})
65
66
  return { status: 'ok', allowedLogin: true }
66
67
  } else {
67
68
  return respondWithStatus({ error: verificationError }, response, HttpStatus.FORBIDDEN)
@@ -105,21 +106,23 @@ export function createTwoFaHandlers(ctx: any) {
105
106
  ? (rememberDaysAfterPasskeyLogin ?? ctx.adminforth.config.auth.rememberMeDuration ?? '30d')
106
107
  : '1d';
107
108
 
109
+ const extra = {
110
+ headers,
111
+ cookies,
112
+ requestUrl,
113
+ query,
114
+ body: {},
115
+ response,
116
+ meta: {
117
+ loginAllowedByPasskeyDirectSignIn: true
118
+ },
119
+ };
120
+
108
121
  await ctx.adminforth.restApi.processLoginCallbacks(
109
122
  adminUser,
110
123
  toReturn,
111
124
  response,
112
- {
113
- headers,
114
- cookies,
115
- requestUrl,
116
- query,
117
- body: {},
118
- response,
119
- meta: {
120
- loginAllowedByPasskeyDirectSignIn: true
121
- },
122
- },
125
+ extra,
123
126
  expireInDuration,
124
127
  );
125
128
 
@@ -129,6 +132,7 @@ export function createTwoFaHandlers(ctx: any) {
129
132
  username,
130
133
  pk: userPk,
131
134
  expireInDuration,
135
+ extra,
132
136
  });
133
137
  }
134
138
  return toReturn;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/two-factors-auth",
3
- "version": "4.4.8",
3
+ "version": "4.4.9",
4
4
  "description": "AdminForth plugin for two factors authentication",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,4 +1,4 @@
1
- import type { IAdminForth, IAdminForthHttpResponse } from "adminforth";
1
+ import type { HttpExtra, IAdminForth, IAdminForthHttpResponse } from "adminforth";
2
2
  import { convertPeriodToSeconds } from "adminforth";
3
3
  import type { PluginOptions } from "../types.js";
4
4
  import type { CookieList, HttpHeaders } from "../utils/types.js";
@@ -43,7 +43,7 @@ export class CookieService {
43
43
  return this.adminforth.auth.getCustomCookie({ cookies, name: AUTH_COOKIE });
44
44
  }
45
45
 
46
- public setAuthCookie(opts: { response: IAdminForthHttpResponse; username: string; pk: string; expireInDuration: string }): Promise<string> {
46
+ public setAuthCookie(opts: { response: IAdminForthHttpResponse; username: string; pk: string; expireInDuration: string; extra: HttpExtra }): Promise<string> {
47
47
  return this.adminforth.auth.setAuthCookie(opts);
48
48
  }
49
49