@adminforth/two-factors-auth 2.10.1 → 2.10.3

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 CHANGED
@@ -15,5 +15,5 @@ custom/package.json
15
15
  custom/tsconfig.json
16
16
  custom/utils.js
17
17
 
18
- sent 273,593 bytes received 210 bytes 547,606.00 bytes/sec
19
- total size is 272,766 speedup is 1.00
18
+ sent 273,585 bytes received 210 bytes 547,590.00 bytes/sec
19
+ total size is 272,758 speedup is 1.00
@@ -85,9 +85,9 @@
85
85
  declare global {
86
86
  interface Window {
87
87
  adminforthTwoFaModal: {
88
- get2FaConfirmationResult: (
89
- verifyingCallback?: (confirmationResult: string) => Promise<boolean>,
90
- title?: string
88
+ get2FaConfirmationResult: (
89
+ title?: string,
90
+ verifyingCallback?: (confirmationResult: string) => Promise<boolean>
91
91
  ) => Promise<any>;
92
92
  };
93
93
  }
@@ -127,7 +127,7 @@
127
127
 
128
128
 
129
129
  window.adminforthTwoFaModal = {
130
- get2FaConfirmationResult: (verifyingCallback?: (confirmationResult: string) => Promise<boolean>, title?: string) =>
130
+ get2FaConfirmationResult: (title?: string, verifyingCallback?: (confirmationResult: string) => Promise<boolean>) =>
131
131
  new Promise(async (resolve, reject) => {
132
132
  if (modelShow.value) throw new Error('Modal is already open');
133
133
  const skipAllowModal = await checkIfSkipAllowModal();
@@ -85,9 +85,9 @@
85
85
  declare global {
86
86
  interface Window {
87
87
  adminforthTwoFaModal: {
88
- get2FaConfirmationResult: (
89
- verifyingCallback?: (confirmationResult: string) => Promise<boolean>,
90
- title?: string
88
+ get2FaConfirmationResult: (
89
+ title?: string,
90
+ verifyingCallback?: (confirmationResult: string) => Promise<boolean>
91
91
  ) => Promise<any>;
92
92
  };
93
93
  }
@@ -127,7 +127,7 @@
127
127
 
128
128
 
129
129
  window.adminforthTwoFaModal = {
130
- get2FaConfirmationResult: (verifyingCallback?: (confirmationResult: string) => Promise<boolean>, title?: string) =>
130
+ get2FaConfirmationResult: (title?: string, verifyingCallback?: (confirmationResult: string) => Promise<boolean>) =>
131
131
  new Promise(async (resolve, reject) => {
132
132
  if (modelShow.value) throw new Error('Modal is already open');
133
133
  const skipAllowModal = await checkIfSkipAllowModal();
package/dist/index.js CHANGED
@@ -51,6 +51,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
51
51
  const userAgent = headers['user-agent'] || '';
52
52
  const acceptLanguage = headers['accept-language'] || '';
53
53
  const session_cookie = this.adminforth.auth.getCustomCookie({ cookies: cookies, name: "jwt" });
54
+ console.log("👺👺👺👺👺👺👺👺👺 Generating hash for Step-Up MFA grace cookie with ip:", ip, "userAgent:", userAgent, "acceptLanguage:", acceptLanguage, "session_cookie:", session_cookie);
54
55
  if (!ip || !userAgent || !acceptLanguage || !session_cookie) {
55
56
  console.error("❗️❗️❗️ Cannot set step-up MFA grace cookie: missing required request headers to identify client ❗️❗️❗️");
56
57
  return null;
@@ -59,18 +60,23 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
59
60
  const hmac = crypto.createHmac('sha256', process.env.ADMINFORTH_SECRET)
60
61
  .update(`${acceptLanguage}_${userAgent}_${ip}_${session_cookie}`)
61
62
  .digest('hex');
63
+ console.log("👺👺👺👺👺👺👺👺👺 Generated hash for Step-Up MFA grace cookie:", hmac);
62
64
  return hmac;
63
65
  }
64
66
  }
65
67
  issueTempSkip2FAGraceJWT(opts) {
68
+ console.log("👺👺👺👺👺👺👺👺👺 Issuing TempSkip2FAGraceJWT");
66
69
  if (opts.response) {
67
70
  if (opts.extra.headers) {
71
+ console.log("👺👺👺👺👺👺👺👺👺 Issuing TempSkip2FAGraceJWT with headers:", opts.extra.headers);
68
72
  const hash = this.generateHashForStepUpMfaGraceCookie(opts.extra.headers, opts.cookies);
69
73
  if (!hash) {
70
74
  return;
71
75
  }
76
+ console.log("👺👺👺👺👺👺👺👺👺 Issuing TempSkip2FAGraceJWT with hash:", hash);
72
77
  const jwt = this.adminforth.auth.issueJWT({ hash: hash }, 'MfaGrace', `${this.options.stepUpMfaGracePeriodSeconds}s`);
73
78
  //TODO: fix ts-ignore after releasing new version of adminforth with updated types
79
+ console.log("👺👺👺👺👺👺👺👺👺 Issuing TempSkip2FAGraceJWT with jwt:", jwt);
74
80
  //@ts-ignore
75
81
  this.adminforth.auth.setCustomCookie({ response: opts.response, payload: { name: "TempSkip2FA_Modal_JWT", value: jwt, expirySeconds: this.options.stepUpMfaGracePeriodSeconds, httpOnly: true } });
76
82
  }
@@ -104,27 +110,35 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
104
110
  verify(confirmationResult, opts) {
105
111
  return __awaiter(this, void 0, void 0, function* () {
106
112
  var _a, _b, _c, _d, _e;
113
+ console.log("🥵🥵🥵🥵🥵🥵🥵🥵TFA Verify called with confirmationResult:", confirmationResult);
107
114
  if (!confirmationResult)
108
115
  return { error: "Confirmation result is required" };
109
116
  if (this.options.usersFilterToApply) {
117
+ console.log("🥵🥵🥵🥵🥵🥵🥵🥵TFA Verify called with adminUser:", opts.adminUser);
110
118
  const res = this.options.usersFilterToApply(opts.adminUser);
111
119
  if (res === false) {
120
+ console.log("🥵🥵🥵🥵🥵🥵🥵🥵TFA Verify skipped due to usersFilterToApply");
112
121
  return { ok: true };
113
122
  }
114
123
  }
115
124
  if (this.options.usersFilterToAllowSkipSetup) {
125
+ console.log("🥵🥵🥵🥵🥵🥵🥵🥵TFA Verify called with adminUser for usersFilterToAllowSkipSetup:", opts.adminUser);
116
126
  const res = yield this.checkIfSkipSetupAllowSkipVerify(opts.adminUser);
117
127
  if (res.skipAllowed === true) {
128
+ console.log("🥵🥵🥵🥵🥵🥵🥵🥵TFA Verify skipped due to usersFilterToAllowSkipVerify");
118
129
  return { ok: true };
119
130
  }
120
131
  }
121
132
  if (this.options.stepUpMfaGracePeriodSeconds && ((_a = opts.extra) === null || _a === void 0 ? void 0 : _a.headers) && !confirmationResult.mode) {
133
+ console.log("🥵🥵🥵🥵🥵🥵🥵🥵TFA Verify called with stepUpMfaGracePeriodSeconds and no mode");
122
134
  const verificationResult = yield this.isTempSkip2FAGraceValid(opts.extra.headers, opts.cookies);
123
135
  if (verificationResult === true) {
136
+ console.log("🥵🥵🥵🥵🥵🥵🥵🥵TFA Verify skipped due to valid step-up MFA grace cookie");
124
137
  return { ok: true };
125
138
  }
126
139
  }
127
140
  if (confirmationResult.mode === "totp") {
141
+ console.log("🥵🥵🥵🥵🥵🥵🥵🥵TFA Verify called with mode totp");
128
142
  const code = confirmationResult.result;
129
143
  const authRes = this.adminforth.config.resources
130
144
  .find(r => r.resourceId === this.adminforth.config.auth.usersResourceId);
@@ -147,6 +161,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
147
161
  //* SET GRACE COOKIE *//
148
162
  if (verified) {
149
163
  if (this.options.stepUpMfaGracePeriodSeconds) {
164
+ console.log("🥵🥵🥵🥵🥵🥵🥵🥵TFA Setting grace cookie due to stepUpMfaGracePeriodSeconds");
150
165
  this.issueTempSkip2FAGraceJWT(opts);
151
166
  }
152
167
  return { ok: true };
@@ -167,8 +182,10 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
167
182
  }
168
183
  const verificationResult = yield this.verifyPasskeyResponse(confirmationResult.result, opts.userPk, decodedPasskeysCookies);
169
184
  if (verificationResult.ok && verificationResult.passkeyConfirmed) {
185
+ console.log("🥵🥵🥵🥵🥵🥵🥵🥵TFA Verify passed with mode passkey");
170
186
  //* SET GRACE COOKIE *//
171
187
  if (this.options.stepUpMfaGracePeriodSeconds) {
188
+ console.log("🥵🥵🥵🥵🥵🥵🥵🥵TFA Setting grace cookie due to stepUpMfaGracePeriodSeconds");
172
189
  this.issueTempSkip2FAGraceJWT(opts);
173
190
  }
174
191
  return { ok: true };
package/index.ts CHANGED
@@ -60,6 +60,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
60
60
  const userAgent = headers['user-agent'] || '';
61
61
  const acceptLanguage = headers['accept-language'] || '';
62
62
  const session_cookie = this.adminforth.auth.getCustomCookie({cookies: cookies, name: "jwt"});
63
+ console.log("👺👺👺👺👺👺👺👺👺 Generating hash for Step-Up MFA grace cookie with ip:", ip, "userAgent:", userAgent, "acceptLanguage:", acceptLanguage, "session_cookie:", session_cookie);
63
64
  if (!ip || !userAgent || !acceptLanguage || !session_cookie) {
64
65
  console.error("❗️❗️❗️ Cannot set step-up MFA grace cookie: missing required request headers to identify client ❗️❗️❗️");
65
66
  return null;
@@ -67,19 +68,24 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
67
68
  const hmac = crypto.createHmac('sha256', process.env.ADMINFORTH_SECRET)
68
69
  .update(`${acceptLanguage}_${userAgent}_${ip}_${session_cookie}`)
69
70
  .digest('hex');
71
+ console.log("👺👺👺👺👺👺👺👺👺 Generated hash for Step-Up MFA grace cookie:", hmac);
70
72
  return hmac;
71
73
  }
72
74
  }
73
75
 
74
76
  private issueTempSkip2FAGraceJWT(opts): void {
77
+ console.log("👺👺👺👺👺👺👺👺👺 Issuing TempSkip2FAGraceJWT");
75
78
  if (opts.response) {
76
79
  if (opts.extra.headers) {
80
+ console.log("👺👺👺👺👺👺👺👺👺 Issuing TempSkip2FAGraceJWT with headers:", opts.extra.headers);
77
81
  const hash = this.generateHashForStepUpMfaGraceCookie(opts.extra.headers, opts.cookies);
78
82
  if (!hash) {
79
83
  return;
80
84
  }
85
+ console.log("👺👺👺👺👺👺👺👺👺 Issuing TempSkip2FAGraceJWT with hash:", hash);
81
86
  const jwt = this.adminforth.auth.issueJWT({ hash: hash }, 'MfaGrace', `${this.options.stepUpMfaGracePeriodSeconds}s`);
82
87
  //TODO: fix ts-ignore after releasing new version of adminforth with updated types
88
+ console.log("👺👺👺👺👺👺👺👺👺 Issuing TempSkip2FAGraceJWT with jwt:", jwt);
83
89
  //@ts-ignore
84
90
  this.adminforth.auth.setCustomCookie({response: opts.response, payload: {name: "TempSkip2FA_Modal_JWT", value: jwt, expirySeconds: this.options.stepUpMfaGracePeriodSeconds, httpOnly: true}});
85
91
  }
@@ -113,27 +119,35 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
113
119
  confirmationResult: Record<string, any>,
114
120
  opts?: { adminUser?: AdminUser; userPk?: string; cookies?: any, response?: IAdminForthHttpResponse, extra?: HttpExtra }
115
121
  ): Promise<{ ok: true } | { error: string }> {
122
+ console.log("🥵🥵🥵🥵🥵🥵🥵🥵TFA Verify called with confirmationResult:", confirmationResult);
116
123
  if (!confirmationResult) return { error: "Confirmation result is required" };
117
124
  if (this.options.usersFilterToApply) {
125
+ console.log("🥵🥵🥵🥵🥵🥵🥵🥵TFA Verify called with adminUser:", opts.adminUser);
118
126
  const res = this.options.usersFilterToApply(opts.adminUser);
119
127
  if ( res === false ) {
128
+ console.log("🥵🥵🥵🥵🥵🥵🥵🥵TFA Verify skipped due to usersFilterToApply");
120
129
  return { ok: true };
121
130
  }
122
131
  }
123
132
  if (this.options.usersFilterToAllowSkipSetup) {
133
+ console.log("🥵🥵🥵🥵🥵🥵🥵🥵TFA Verify called with adminUser for usersFilterToAllowSkipSetup:", opts.adminUser);
124
134
  const res = await this.checkIfSkipSetupAllowSkipVerify(opts.adminUser);
125
135
  if ( res.skipAllowed === true ) {
136
+ console.log("🥵🥵🥵🥵🥵🥵🥵🥵TFA Verify skipped due to usersFilterToAllowSkipVerify");
126
137
  return { ok: true };
127
138
  }
128
139
  }
129
140
  if ( this.options.stepUpMfaGracePeriodSeconds && opts.extra?.headers && !confirmationResult.mode) {
141
+ console.log("🥵🥵🥵🥵🥵🥵🥵🥵TFA Verify called with stepUpMfaGracePeriodSeconds and no mode");
130
142
  const verificationResult = await this.isTempSkip2FAGraceValid(opts.extra.headers, opts.cookies);
131
143
  if ( verificationResult === true ) {
144
+ console.log("🥵🥵🥵🥵🥵🥵🥵🥵TFA Verify skipped due to valid step-up MFA grace cookie");
132
145
  return { ok: true };
133
146
  }
134
147
  }
135
148
 
136
149
  if (confirmationResult.mode === "totp") {
150
+ console.log("🥵🥵🥵🥵🥵🥵🥵🥵TFA Verify called with mode totp");
137
151
  const code = confirmationResult.result;
138
152
  const authRes = this.adminforth.config.resources
139
153
  .find(r => r.resourceId === this.adminforth.config.auth.usersResourceId);
@@ -158,6 +172,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
158
172
  //* SET GRACE COOKIE *//
159
173
  if ( verified ) {
160
174
  if (this.options.stepUpMfaGracePeriodSeconds) {
175
+ console.log("🥵🥵🥵🥵🥵🥵🥵🥵TFA Setting grace cookie due to stepUpMfaGracePeriodSeconds");
161
176
  this.issueTempSkip2FAGraceJWT(opts);
162
177
  }
163
178
  return { ok: true }
@@ -177,9 +192,10 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
177
192
  const verificationResult = await this.verifyPasskeyResponse(confirmationResult.result, opts.userPk, decodedPasskeysCookies );
178
193
 
179
194
  if (verificationResult.ok && verificationResult.passkeyConfirmed) {
180
-
195
+ console.log("🥵🥵🥵🥵🥵🥵🥵🥵TFA Verify passed with mode passkey");
181
196
  //* SET GRACE COOKIE *//
182
197
  if (this.options.stepUpMfaGracePeriodSeconds) {
198
+ console.log("🥵🥵🥵🥵🥵🥵🥵🥵TFA Setting grace cookie due to stepUpMfaGracePeriodSeconds");
183
199
  this.issueTempSkip2FAGraceJWT(opts);
184
200
  }
185
201
  return { ok: true }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/two-factors-auth",
3
- "version": "2.10.1",
3
+ "version": "2.10.3",
4
4
  "description": "AdminForth plugin for two factors authentication",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",