@crossauth/backend 1.1.4 → 1.1.6

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/index.js CHANGED
@@ -13,7 +13,7 @@ import Z from "nunjucks";
13
13
  import xe from "nodemailer";
14
14
  import Ze from "twilio";
15
15
  import Xe from "qrcode";
16
- import { authenticator as _e } from "otplib";
16
+ import { authenticator as ke } from "otplib";
17
17
  import ae from "jsonwebtoken";
18
18
  import ue from "node:fs";
19
19
  import { createPublicKey as Qe } from "crypto";
@@ -916,8 +916,8 @@ class jt extends ve {
916
916
  ...d,
917
917
  userid: C,
918
918
  client_secret: d.client_secret ?? void 0,
919
- redirect_uri: f.map((_) => _.uri),
920
- valid_flow: y.map((_) => _.flow)
919
+ redirect_uri: f.map((k) => k.uri),
920
+ valid_flow: y.map((k) => k.flow)
921
921
  }];
922
922
  } else {
923
923
  const d = await r[this.clientTable].findMany({
@@ -929,8 +929,8 @@ class jt extends ve {
929
929
  });
930
930
  for (let f of d) {
931
931
  const y = f.redirect_uri, C = f.valid_flow;
932
- let _ = f[this.useridForeignKeyColumn];
933
- _ == null && (_ = void 0), f.userid = _, this.useridForeignKeyColumn != "userid" && delete f[this.useridForeignKeyColumn], f.client_secret = f.client_secret ?? void 0, f.redirect_uri = y.map((p) => p.uri), f.valid_flow = C.map((p) => p.flow);
932
+ let k = f[this.useridForeignKeyColumn];
933
+ k == null && (k = void 0), f.userid = k, this.useridForeignKeyColumn != "userid" && delete f[this.useridForeignKeyColumn], f.client_secret = f.client_secret ?? void 0, f.redirect_uri = y.map((p) => p.uri), f.valid_flow = C.map((p) => p.flow);
934
934
  }
935
935
  return d;
936
936
  }
@@ -1899,18 +1899,18 @@ class te extends q {
1899
1899
  let d = `select * from ${this.userTable} where ${e} = ` + c.nextParameter(), f = await i.execute(d, [t]);
1900
1900
  if (f.length == 0)
1901
1901
  throw new o(l.UserNotExist);
1902
- let y, C, _;
1902
+ let y, C, k;
1903
1903
  if (this.idColumn in f[0]) y = f[0][this.idColumn];
1904
1904
  else throw new o(l.Configuration, "ID column " + this.idColumn + " not present in user table");
1905
1905
  if ("username" in f[0]) C = f[0].username;
1906
1906
  else throw new o(l.Configuration, "username column " + this.idColumn + " not present in user table");
1907
- if ("state" in f[0]) _ = f[0].state;
1907
+ if ("state" in f[0]) k = f[0].state;
1908
1908
  else throw new o(l.Configuration, "state column " + this.idColumn + " not present in user table");
1909
1909
  if (s = {
1910
1910
  ...f[0],
1911
1911
  id: y,
1912
1912
  username: C,
1913
- state: _
1913
+ state: k
1914
1914
  }, !s) throw new o(l.UserNotExist);
1915
1915
  if (c = this.dbPool.parameters(), d = `select * from ${this.userSecretsTable} where ${this.useridForeignKeyColumn} = ` + c.nextParameter(), f = await i.execute(d, [s.id]), f.length == 0)
1916
1916
  throw new o(l.UserNotExist);
@@ -1949,8 +1949,8 @@ class te extends q {
1949
1949
  if (y.length == 0)
1950
1950
  throw new o(l.UserNotExist);
1951
1951
  for (let C of y) {
1952
- let _, p, T;
1953
- if (this.idColumn in C) _ = C[this.idColumn];
1952
+ let k, p, T;
1953
+ if (this.idColumn in C) k = C[this.idColumn];
1954
1954
  else throw new o(l.Configuration, "ID column " + this.idColumn + " not present in user table");
1955
1955
  if ("username" in C) p = C.username;
1956
1956
  else throw new o(l.Configuration, "username column " + this.idColumn + " not present in user table");
@@ -1958,7 +1958,7 @@ class te extends q {
1958
1958
  else throw new o(l.Configuration, "state column " + this.idColumn + " not present in user table");
1959
1959
  let v = {
1960
1960
  ...C,
1961
- id: _,
1961
+ id: k,
1962
1962
  username: p,
1963
1963
  state: T
1964
1964
  };
@@ -1997,8 +1997,8 @@ class te extends q {
1997
1997
  if (f.length > 0) {
1998
1998
  let C = f.join(", ");
1999
1999
  y.push(e.id);
2000
- let _ = `update ${this.userTable} set ${C} where ${this.idColumn} = ` + i.nextParameter();
2001
- await r.execute(_, y);
2000
+ let k = `update ${this.userTable} set ${C} where ${this.idColumn} = ` + i.nextParameter();
2001
+ await r.execute(k, y);
2002
2002
  }
2003
2003
  if (t) {
2004
2004
  f = [], y = [], i = this.dbPool.parameters();
@@ -2007,8 +2007,8 @@ class te extends q {
2007
2007
  if (f.length > 0) {
2008
2008
  let C = f.join(", ");
2009
2009
  y.push(e.id);
2010
- let _ = `update ${this.userSecretsTable} set ${C} where userid = ` + i.nextParameter();
2011
- await r.execute(_, y);
2010
+ let k = `update ${this.userSecretsTable} set ${C} where userid = ` + i.nextParameter();
2011
+ await r.execute(k, y);
2012
2012
  }
2013
2013
  }
2014
2014
  await r.commit();
@@ -2038,21 +2038,21 @@ class te extends q {
2038
2038
  "email" in s && s.email && (s = { email_normalized: this.normalizeEmail ? te.normalize(s.email) : s.email, ...s }), "username" in s && s.username && (s = { username_normalized: this.normalizeUsername ? te.normalize(s.username) : s.username, ...s });
2039
2039
  let c = [], d = [], f = [];
2040
2040
  const y = this.dbPool.parameters();
2041
- for (let _ in s)
2042
- s[_] != null && _ != "id" && (c.push(_), d.push(y.nextParameter()), f.push(s[_]));
2041
+ for (let k in s)
2042
+ s[k] != null && k != "id" && (c.push(k), d.push(y.nextParameter()), f.push(s[k]));
2043
2043
  if (c.length > 0) {
2044
- let _ = c.join(", "), p = d.join(", ");
2045
- const T = `insert into ${this.userTable} (${_}) values (${p}) returning ${this.idColumn}`, v = await r.execute(T, f);
2044
+ let k = c.join(", "), p = d.join(", ");
2045
+ const T = `insert into ${this.userTable} (${k}) values (${p}) returning ${this.idColumn}`, v = await r.execute(T, f);
2046
2046
  if (v.length == 0 || !v[0][this.idColumn]) throw new o(l.Connection, "Couldn't create user");
2047
2047
  i = v[0][this.idColumn];
2048
2048
  }
2049
2049
  if (!i) throw new o(l.Connection, "Couldn't create user");
2050
2050
  if (t) {
2051
2051
  c = [], d = [], f = [];
2052
- const _ = this.dbPool.parameters();
2053
- c.push("userid"), d.push(_.nextParameter()), f.push(i);
2052
+ const k = this.dbPool.parameters();
2053
+ c.push("userid"), d.push(k.nextParameter()), f.push(i);
2054
2054
  for (let p in n)
2055
- n[p] != null && p != "userid" && (c.push(p), d.push(_.nextParameter()), f.push(n[p]));
2055
+ n[p] != null && p != "userid" && (c.push(p), d.push(k.nextParameter()), f.push(n[p]));
2056
2056
  if (c.length > 0) {
2057
2057
  let p = c.join(", "), T = d.join(", ");
2058
2058
  const v = `insert into ${this.userSecretsTable} (${p}) values (${T})`;
@@ -2168,10 +2168,10 @@ class ot extends V {
2168
2168
  let C = [e ?? null, t, r, i ?? null, s ?? ""];
2169
2169
  for (let v in n)
2170
2170
  d.push(v), y.push(f.nextParameter()), C.push(n[v]);
2171
- let _ = d.join(", "), p = y.join(", ");
2171
+ let k = d.join(", "), p = y.join(", ");
2172
2172
  const T = await this.dbPool.connect();
2173
2173
  try {
2174
- const v = `insert into ${this.keyTable} (${_}) values (${p})`;
2174
+ const v = `insert into ${this.keyTable} (${k}) values (${p})`;
2175
2175
  await T.execute(v, C);
2176
2176
  } catch (v) {
2177
2177
  o.asCrossauthError(v).code == l.ConstraintViolation ? (h.logger.warn(m({ msg: "Attempt to create key that already exists. Stack trace follows" })), h.logger.debug(m({ err: v })), c = new o(l.KeyExists)) : (h.logger.debug(m({ err: v })), c = new o(l.Connection, "Error saving key"));
@@ -2412,9 +2412,9 @@ class lt extends ve {
2412
2412
  async getClientWithTransaction(e, t, r, i, s, n) {
2413
2413
  let c = [], d = this.dbPool.parameters(), f = [], y = `select c.*, r.uri as uri, null as flow from ${this.clientTable} as c left join ${this.redirectUriTable} r on c.client_id = r.client_id `, C = "";
2414
2414
  t && r && (C = `where c.${t} = ` + d.nextParameter(), f.push(r)), i !== null && i == null || (C == "" ? C = "where " : C += " and ", i == null ? C += "userid is null" : (C += `${this.useridForeignKeyColumn} = ` + d.nextParameter(), f.push(i)));
2415
- let _ = `select c.*, null as uri, f.flow as flow from ${this.clientTable} as c left join ${this.validFlowTable} f on c.client_id = f.client_id `, p = "";
2416
- t && r && (p = `where c.${t} = ` + d.nextParameter(), f.push(r)), i !== null && i == null || (p == "" ? p = "where " : p += " and ", i == null ? p += "userid is null" : (p += `${this.useridForeignKeyColumn} = ` + d.nextParameter(), f.push(i))), n && (s || (s = 0), s = Number(s), n = Number(n), C == "" ? C = "where " : C += " and ", C += ` c.client_id in (select client_id from ${this.clientTable} limit ${n} offset ${s})`, p == "" ? p = "where " : p += " and ", p += ` c.client_id in (select client_id from ${this.clientTable} limit ${n} offset ${s})`), y += C, _ += p;
2417
- let T = y + " union " + _ + " order by client_id";
2415
+ let k = `select c.*, null as uri, f.flow as flow from ${this.clientTable} as c left join ${this.validFlowTable} f on c.client_id = f.client_id `, p = "";
2416
+ t && r && (p = `where c.${t} = ` + d.nextParameter(), f.push(r)), i !== null && i == null || (p == "" ? p = "where " : p += " and ", i == null ? p += "userid is null" : (p += `${this.useridForeignKeyColumn} = ` + d.nextParameter(), f.push(i))), n && (s || (s = 0), s = Number(s), n = Number(n), C == "" ? C = "where " : C += " and ", C += ` c.client_id in (select client_id from ${this.clientTable} limit ${n} offset ${s})`, p == "" ? p = "where " : p += " and ", p += ` c.client_id in (select client_id from ${this.clientTable} limit ${n} offset ${s})`), y += C, k += p;
2417
+ let T = y + " union " + k + " order by client_id";
2418
2418
  const v = await e.execute(T, f);
2419
2419
  let b;
2420
2420
  for (let M of v)
@@ -2470,20 +2470,20 @@ class lt extends ve {
2470
2470
  let C = await this.getClientWithTransaction(e, "client_id", t.client_id, t.userid);
2471
2471
  if (C.length == 0)
2472
2472
  throw h.logger.error(m({ msg: "Attempt to create key that already exists. Stack trace follows" })), new o(l.KeyExists);
2473
- let _ = C[0];
2473
+ let k = C[0];
2474
2474
  if (r)
2475
2475
  for (let p = 0; p < r.length; ++p) {
2476
2476
  f = [], y = this.dbPool.parameters();
2477
2477
  let T = `insert into ${this.redirectUriTable} (client_id, uri) values (` + y.nextParameter() + ", " + y.nextParameter() + ")";
2478
- f.push(_.client_id), f.push(r[p]), await e.execute(T, f);
2478
+ f.push(k.client_id), f.push(r[p]), await e.execute(T, f);
2479
2479
  }
2480
2480
  if (i)
2481
2481
  for (let p = 0; p < i.length; ++p) {
2482
2482
  f = [], y = this.dbPool.parameters();
2483
2483
  let T = `insert into ${this.validFlowTable} (client_id, flow) values (` + y.nextParameter() + ", " + y.nextParameter() + ")";
2484
- f.push(_.client_id), f.push(i[p]), await e.execute(T, f);
2484
+ f.push(k.client_id), f.push(i[p]), await e.execute(T, f);
2485
2485
  }
2486
- return { ..._, redirect_uri: r, valid_flow: i };
2486
+ return { ...k, redirect_uri: r, valid_flow: i };
2487
2487
  }
2488
2488
  /**
2489
2489
  *
@@ -2545,12 +2545,12 @@ class lt extends ve {
2545
2545
  n || (n = []), c || (c = []);
2546
2546
  let f = this.dbPool.parameters(), y = `delete from ${this.redirectUriTable} where client_id = ` + f.nextParameter();
2547
2547
  await e.execute(y, [t.client_id]), f = this.dbPool.parameters(), y = `delete from ${this.validFlowTable} where client_id = ` + f.nextParameter(), await e.execute(y, [t.client_id]);
2548
- let C = [], _ = [], p = [];
2548
+ let C = [], k = [], p = [];
2549
2549
  f = this.dbPool.parameters(), y = `delete from ${this.validFlowTable} where client_id = ` + f.nextParameter();
2550
2550
  for (let T in d)
2551
- C.push(T), _.push(f.nextParameter()), p.push(d[T]);
2551
+ C.push(T), k.push(f.nextParameter()), p.push(d[T]);
2552
2552
  if (C.length > 0) {
2553
- let T = C.join(", "), v = _.join(", ");
2553
+ let T = C.join(", "), v = k.join(", ");
2554
2554
  y = `update ${this.clientTable} set (${T}) values (${v})`, await e.execute(y, p);
2555
2555
  }
2556
2556
  if (n)
@@ -3060,7 +3060,7 @@ const Ie = process.env.PBKDF2_DIGEST || "sha256", Pe = Number(process.env.PBKDF2
3060
3060
  }
3061
3061
  };
3062
3062
  u(G, "Base32", "ABCDEFGHJKLMNPQRSTUVWXYZ23456789".split(""));
3063
- let k = G;
3063
+ let _ = G;
3064
3064
  function wt(S) {
3065
3065
  let a = [];
3066
3066
  if (!S.password) a.push("Password not provided");
@@ -3114,7 +3114,7 @@ const we = class we extends Re {
3114
3114
  async authenticateUser(e, t, r) {
3115
3115
  if (!r.password) throw new o(l.PasswordInvalid, "Password not provided");
3116
3116
  if (!t.password) throw new o(l.PasswordInvalid);
3117
- if (!await k.passwordsEqual(r.password, t.password, this.secret))
3117
+ if (!await _.passwordsEqual(r.password, t.password, this.secret))
3118
3118
  throw h.logger.debug(m({ msg: "Invalid password hash", user: e.username })), new o(l.PasswordInvalid);
3119
3119
  if (e.state == E.awaitingTwoFactorSetup) throw new o(l.TwoFactorIncomplete);
3120
3120
  if (e.state == E.awaitingEmailVerification) throw new o(l.EmailNotVerified);
@@ -3144,7 +3144,7 @@ const we = class we extends Re {
3144
3144
  * @returns the encoded hash string.
3145
3145
  */
3146
3146
  async createPasswordHash(e, t, r = !0) {
3147
- return await k.passwordHash(e, {
3147
+ return await _.passwordHash(e, {
3148
3148
  salt: t,
3149
3149
  encode: r,
3150
3150
  secret: this.enableSecretForPasswords ? this.secret : void 0,
@@ -3169,7 +3169,7 @@ const we = class we extends Re {
3169
3169
  * @returns true if match, false otherwise
3170
3170
  */
3171
3171
  async passwordMatchesHash(e, t, r) {
3172
- return t == we.NoPassword ? !1 : await k.passwordsEqual(e, t, r);
3172
+ return t == we.NoPassword ? !1 : await _.passwordsEqual(e, t, r);
3173
3173
  }
3174
3174
  /**
3175
3175
  * This will return p hash of the passed password.
@@ -3963,9 +3963,9 @@ class Qt extends de {
3963
3963
  return "none";
3964
3964
  }
3965
3965
  async createSecret(e, t) {
3966
- t || (t = _e.generateSecret());
3966
+ t || (t = ke.generateSecret());
3967
3967
  let r = "";
3968
- return await Xe.toDataURL(_e.keyuri(e, this.appName, t)).then((i) => {
3968
+ return await Xe.toDataURL(ke.keyuri(e, this.appName, t)).then((i) => {
3969
3969
  r = i;
3970
3970
  }).catch((i) => {
3971
3971
  throw h.logger.debug(m({ err: i })), new o(
@@ -4048,7 +4048,7 @@ class Qt extends de {
4048
4048
  "TOTP secret or code not given"
4049
4049
  );
4050
4050
  const i = r.otp, s = t.totpsecret;
4051
- if (!_e.check(i, s))
4051
+ if (!ke.check(i, s))
4052
4052
  throw new o(
4053
4053
  l.InvalidToken,
4054
4054
  "Invalid TOTP code"
@@ -4270,24 +4270,24 @@ class L {
4270
4270
  * correct prefix for inserting into storage.
4271
4271
  */
4272
4272
  static hashEmailVerificationToken(a) {
4273
- return U.emailVerificationToken + k.hash(a);
4273
+ return U.emailVerificationToken + _.hash(a);
4274
4274
  }
4275
4275
  /**
4276
4276
  * Produces a hash of the given password reset token with the
4277
4277
  * correct prefix for inserting into storage.
4278
4278
  */
4279
4279
  static hashPasswordResetToken(a) {
4280
- return U.passwordResetToken + k.hash(a);
4280
+ return U.passwordResetToken + _.hash(a);
4281
4281
  }
4282
4282
  async createAndSaveEmailVerificationToken(a, e = "") {
4283
4283
  let r = 0;
4284
4284
  const i = /* @__PURE__ */ new Date(), s = new Date(i.getTime() + 1e3 * this.verifyEmailExpires);
4285
4285
  for (; r < 10; ) {
4286
- let n = k.randomValue(fe), c = L.hashEmailVerificationToken(n);
4286
+ let n = _.randomValue(fe), c = L.hashEmailVerificationToken(n);
4287
4287
  try {
4288
4288
  return await this.keyStorage.saveKey(a, c, i, s, e), n;
4289
4289
  } catch {
4290
- n = k.randomValue(fe), c = L.hashEmailVerificationToken(n), r++;
4290
+ n = _.randomValue(fe), c = L.hashEmailVerificationToken(n), r++;
4291
4291
  }
4292
4292
  }
4293
4293
  throw new o(l.Connection, "failed creating a unique key");
@@ -4372,11 +4372,11 @@ class L {
4372
4372
  let t = 0;
4373
4373
  const r = /* @__PURE__ */ new Date(), i = new Date(r.getTime() + 1e3 * this.passwordResetExpires);
4374
4374
  for (; t < 10; ) {
4375
- let s = k.randomValue(fe), n = L.hashPasswordResetToken(s);
4375
+ let s = _.randomValue(fe), n = L.hashPasswordResetToken(s);
4376
4376
  try {
4377
4377
  return await this.keyStorage.saveKey(a, n, r, i), s;
4378
4378
  } catch {
4379
- s = k.randomValue(fe), n = L.hashPasswordResetToken(s), t++;
4379
+ s = _.randomValue(fe), n = L.hashPasswordResetToken(s), t++;
4380
4380
  }
4381
4381
  }
4382
4382
  throw new o(l.Connection, "failed creating a unique key");
@@ -4508,7 +4508,7 @@ class yt {
4508
4508
  * @returns a random CSRF token.
4509
4509
  */
4510
4510
  createCsrfToken() {
4511
- return k.randomValue(Fe);
4511
+ return _.randomValue(Fe);
4512
4512
  }
4513
4513
  /**
4514
4514
  * Returns a {@link Cookie } object with the given session key.
@@ -4517,7 +4517,7 @@ class yt {
4517
4517
  * @returns a {@link Cookie } object,
4518
4518
  */
4519
4519
  makeCsrfCookie(a) {
4520
- const e = k.signSecureToken(a, this.secret);
4520
+ const e = _.signSecureToken(a, this.secret);
4521
4521
  let t = {};
4522
4522
  return this.domain && (t.domain = this.domain), this.path && (t.path = this.path), t.sameSite = this.sameSite, this.httpOnly && (t.httpOnly = this.httpOnly), this.secure && (t.secure = this.secure), {
4523
4523
  name: this.cookieName,
@@ -4529,7 +4529,7 @@ class yt {
4529
4529
  return this.maskCsrfToken(a);
4530
4530
  }
4531
4531
  unsignCookie(a) {
4532
- return k.unsignSecureToken(a, this.secret);
4532
+ return _.unsignSecureToken(a, this.secret);
4533
4533
  }
4534
4534
  /**
4535
4535
  * Takes a session ID and creates a string representation of the cookie (value of the HTTP `Cookie` header).
@@ -4542,14 +4542,14 @@ class yt {
4542
4542
  return this.domain && (e += "; " + this.domain), this.path && (e += "; " + this.path), this.httpOnly && (e += "; httpOnly"), this.secure && (e += "; secure"), e;
4543
4543
  }
4544
4544
  maskCsrfToken(a) {
4545
- const e = k.randomValue(Fe), t = k.xor(a, e);
4545
+ const e = _.randomValue(Fe), t = _.xor(a, e);
4546
4546
  return e + "." + t;
4547
4547
  }
4548
4548
  unmaskCsrfToken(a) {
4549
4549
  const e = a.split(".");
4550
4550
  if (e.length != 2) throw new o(l.InvalidCsrf, "CSRF token in header or form not in correct format");
4551
4551
  const t = e[0], r = e[1];
4552
- return k.xor(r, t);
4552
+ return _.xor(r, t);
4553
4553
  }
4554
4554
  /**
4555
4555
  * Validates the passed CSRF token.
@@ -4566,12 +4566,12 @@ class yt {
4566
4566
  const t = this.unmaskCsrfToken(e);
4567
4567
  let r;
4568
4568
  try {
4569
- r = k.unsignSecureToken(a, this.secret);
4569
+ r = _.unsignSecureToken(a, this.secret);
4570
4570
  } catch (i) {
4571
4571
  throw h.logger.error(m({ err: i })), new o(l.InvalidCsrf, "Invalid CSRF cookie");
4572
4572
  }
4573
4573
  if (r != t)
4574
- throw h.logger.warn(m({ msg: "Invalid CSRF token received - form/header value does not match", csrfCookieHash: k.hash(a) })), new o(l.InvalidCsrf);
4574
+ throw h.logger.warn(m({ msg: "Invalid CSRF token received - form/header value does not match", csrfCookieHash: _.hash(a) })), new o(l.InvalidCsrf);
4575
4575
  }
4576
4576
  /**
4577
4577
  * Validates the passed CSRF cookie (doesn't check it matches the token, just that the cookie is valid).
@@ -4585,7 +4585,7 @@ class yt {
4585
4585
  */
4586
4586
  validateCsrfCookie(a) {
4587
4587
  try {
4588
- return k.unsignSecureToken(a, this.secret);
4588
+ return _.unsignSecureToken(a, this.secret);
4589
4589
  } catch (e) {
4590
4590
  throw h.logger.error(m({ err: e })), new o(l.InvalidCsrf, "Invalid CSRF cookie");
4591
4591
  }
@@ -4620,7 +4620,7 @@ class j {
4620
4620
  u(this, "sameSite", "lax");
4621
4621
  // hasher settings
4622
4622
  u(this, "secret", "");
4623
- e.userStorage && (this.userStorage = e.userStorage), this.keyStorage = a, w("idleTimeout", g.Number, this, e, "SESSION_IDLE_TIMEOUT"), w("persist", g.Boolean, this, e, "PERSIST_SESSION_ID"), this.filterFunction = e.filterFunction, w("cookieName", g.String, this, e, "SESSION_COOKIE_NAME"), w("maxAge", g.String, this, e, "SESSION_COOKIE_MAX_AGE"), w("domain", g.String, this, e, "SESSION_COOKIE_DOMAIN"), w("httpOnly", g.Boolean, this, e, "SESSIONCOOKIE_HTTPONLY"), w("path", g.String, this, e, "SESSION_COOKIE_PATH"), w("secure", g.Boolean, this, e, "SESSION_COOKIE_SECURE"), w("sameSite", g.String, this, e, "SESSION_COOKIE_SAMESITE"), w("secret", g.String, this, e, "SECRET", !0);
4623
+ e.userStorage && (this.userStorage = e.userStorage), this.keyStorage = a, w("idleTimeout", g.Number, this, e, "SESSION_IDLE_TIMEOUT"), w("persist", g.Boolean, this, e, "PERSIST_SESSION_ID"), this.filterFunction = e.filterFunction, w("cookieName", g.String, this, e, "SESSION_COOKIE_NAME"), w("maxAge", g.String, this, e, "SESSION_COOKIE_MAX_AGE"), w("domain", g.String, this, e, "SESSION_COOKIE_DOMAIN"), w("httpOnly", g.Boolean, this, e, "SESSION_COOKIE_HTTPONLY"), w("path", g.String, this, e, "SESSION_COOKIE_PATH"), w("secure", g.Boolean, this, e, "SESSION_COOKIE_SECURE"), w("sameSite", g.String, this, e, "SESSION_COOKIE_SAMESITE"), w("secret", g.String, this, e, "SECRET", !0);
4624
4624
  }
4625
4625
  expiry(a) {
4626
4626
  let e;
@@ -4634,7 +4634,7 @@ class j {
4634
4634
  * @returns a base64-url-encoded string that can go into the storage
4635
4635
  */
4636
4636
  static hashSessionId(a) {
4637
- return U.session + k.hash(a);
4637
+ return U.session + _.hash(a);
4638
4638
  }
4639
4639
  /**
4640
4640
  * Creates a session key and saves in storage
@@ -4653,7 +4653,7 @@ class j {
4653
4653
  * attempts exceeded trying to create a unique session id
4654
4654
  */
4655
4655
  async createSessionKey(a, e = {}) {
4656
- let r = 0, i = k.randomValue(Ne);
4656
+ let r = 0, i = _.randomValue(Ne);
4657
4657
  const s = /* @__PURE__ */ new Date();
4658
4658
  let n = this.expiry(s), c = !1;
4659
4659
  for (; r < 10 && !c; ) {
@@ -4663,7 +4663,7 @@ class j {
4663
4663
  } catch (f) {
4664
4664
  let y = o.asCrossauthError(f);
4665
4665
  if (y.code == l.KeyExists || y.code == l.InvalidKey) {
4666
- if (r++, i = k.randomValue(Ne), r > 10)
4666
+ if (r++, i = _.randomValue(Ne), r > 10)
4667
4667
  throw h.logger.error(m({ msg: "Max attempts exceeded trying to create session ID" })), new o(l.KeyExists);
4668
4668
  } else
4669
4669
  throw h.logger.debug(m({ err: f })), f;
@@ -4686,8 +4686,8 @@ class j {
4686
4686
  * @returns a {@link Cookie } object,
4687
4687
  */
4688
4688
  makeCookie(a, e) {
4689
- let t = k.signSecureToken(a.value, this.secret), r = {};
4690
- return e == null && (e = this.persist), this.domain && (r.domain = this.domain), a.expires && e && (r.expires = a.expires), this.path && (r.path = this.path), r.sameSite = this.sameSite, this.httpOnly && (r.httpOnly = this.httpOnly), this.secure && (r.secure = this.secure), {
4689
+ let t = _.signSecureToken(a.value, this.secret), r = {};
4690
+ return e == null && (e = this.persist), this.domain && (r.domain = this.domain), a.expires && e && (r.expires = a.expires), this.path && (r.path = this.path), r.sameSite = this.sameSite, this.httpOnly ? r.httpOnly = this.httpOnly : this.httpOnly === !1 && (r.httpOnly = this.httpOnly), this.secure ? r.secure = this.secure : this.secure === !1 && (r.secure = this.secure), h.logger.debug(m({ msg: `Setting session cookie ${this.cookieName} options ${JSON.stringify(r)}` })), {
4691
4691
  name: this.cookieName,
4692
4692
  value: t,
4693
4693
  options: r
@@ -4723,7 +4723,7 @@ class j {
4723
4723
  * is invalid.
4724
4724
  */
4725
4725
  unsignCookie(a) {
4726
- return k.unsignSecureToken(a, this.secret);
4726
+ return _.unsignSecureToken(a, this.secret);
4727
4727
  }
4728
4728
  /**
4729
4729
  * Returns the user matching the given session key in session storage, or throws an exception.
@@ -4763,11 +4763,11 @@ class j {
4763
4763
  async getSessionKey(a) {
4764
4764
  const e = Date.now(), t = j.hashSessionId(a), r = await this.keyStorage.getKey(t);
4765
4765
  if (r.value = a, r.expires && e > r.expires.getTime())
4766
- throw h.logger.warn(m({ msg: "Session id in cookie expired in key storage", hashedSessionCookie: k.hash(a) })), new o(l.Expired);
4766
+ throw h.logger.warn(m({ msg: "Session id in cookie expired in key storage", hashedSessionCookie: _.hash(a) })), new o(l.Expired);
4767
4767
  if (r.userid && this.idleTimeout > 0 && r.lastactive && e > r.lastactive.getTime() + this.idleTimeout * 1e3)
4768
- throw h.logger.warn(m({ msg: "Session cookie with expired idle time received", hashedSessionCookie: k.hash(a) })), new o(l.Expired);
4768
+ throw h.logger.warn(m({ msg: "Session cookie with expired idle time received", hashedSessionCookie: _.hash(a) })), new o(l.Expired);
4769
4769
  if (this.filterFunction && !this.filterFunction(r))
4770
- throw h.logger.warn(m({ msg: "Filter function on session id in cookie failed", hashedSessionCookie: k.hash(a) })), new o(l.InvalidKey);
4770
+ throw h.logger.warn(m({ msg: "Filter function on session id in cookie failed", hashedSessionCookie: _.hash(a) })), new o(l.InvalidKey);
4771
4771
  return r;
4772
4772
  }
4773
4773
  /**
@@ -4863,17 +4863,17 @@ class rr {
4863
4863
  if (i)
4864
4864
  n = (await this.userStorage.getUserByUsername(i.username, { skipActiveCheck: !0, skipEmailVerifiedCheck: !0 })).secrets;
4865
4865
  else {
4866
- let _ = { username: "", state: "active" };
4866
+ let k = { username: "", state: "active" };
4867
4867
  try {
4868
4868
  let T = await this.userStorage.getUserByUsername(a, { skipActiveCheck: !0, skipEmailVerifiedCheck: !0 });
4869
- n = T.secrets, i = T.user, _ = T.user;
4869
+ n = T.secrets, i = T.user, k = T.user;
4870
4870
  } catch (T) {
4871
4871
  if (o.asCrossauthError(T).code == l.Connection) throw T;
4872
4872
  for (let b in this.authenticators)
4873
- this.authenticators[b].requireUserEntry() || (_ = { username: e.username, state: "active" }, c = b);
4873
+ this.authenticators[b].requireUserEntry() || (k = { username: e.username, state: "active" }, c = b);
4874
4874
  }
4875
- if (_.username == "") throw new o(l.UserNotExist);
4876
- await this.authenticators[(i == null ? void 0 : i.factor1) ?? c].authenticateUser(_, n, e);
4875
+ if (k.username == "") throw new o(l.UserNotExist);
4876
+ await this.authenticators[(i == null ? void 0 : i.factor1) ?? c].authenticateUser(k, n, e);
4877
4877
  let p = await this.userStorage.getUserByUsername(a, { skipActiveCheck: !0, skipEmailVerifiedCheck: !0 });
4878
4878
  n = p.secrets, i = p.user;
4879
4879
  }
@@ -4883,11 +4883,11 @@ class rr {
4883
4883
  else if (i.state == E.factor2ResetNeeded)
4884
4884
  d = (await this.createAnonymousSession({ data: JSON.stringify({ factor2change: { username: i.username } }) })).sessionCookie;
4885
4885
  else if (!s && i.factor2 && i.factor2 != "") {
4886
- const { sessionCookie: _ } = await this.initiateTwoFactorLogin(i);
4887
- d = _;
4886
+ const { sessionCookie: k } = await this.initiateTwoFactorLogin(i);
4887
+ d = k;
4888
4888
  } else {
4889
- const _ = await this.session.createSessionKey(i.id, t);
4890
- d = this.session.makeCookie(_, r);
4889
+ const k = await this.session.createSessionKey(i.id, t);
4890
+ d = this.session.makeCookie(k, r);
4891
4891
  }
4892
4892
  const f = this.csrfTokens.createCsrfToken(), y = this.csrfTokens.makeCsrfCookie(f), C = this.csrfTokens.makeCsrfFormOrHeaderToken(f);
4893
4893
  try {
@@ -4895,8 +4895,8 @@ class rr {
4895
4895
  i.id,
4896
4896
  U.passwordResetToken
4897
4897
  );
4898
- } catch (_) {
4899
- h.logger.warn(m({ msg: "Couldn't delete password reset tokens while logging in", user: a })), h.logger.debug(m({ err: _ }));
4898
+ } catch (k) {
4899
+ h.logger.warn(m({ msg: "Couldn't delete password reset tokens while logging in", user: a })), h.logger.debug(m({ err: k }));
4900
4900
  }
4901
4901
  return {
4902
4902
  sessionCookie: d,
@@ -5082,7 +5082,7 @@ class rr {
5082
5082
  */
5083
5083
  async updateSessionData(a, e, t) {
5084
5084
  const r = j.hashSessionId(a);
5085
- h.logger.debug(m({ msg: `Updating session data value ${e}`, hashedSessionCookie: k.hash(a) })), await this.keyStorage.updateData(r, e, t);
5085
+ h.logger.debug(m({ msg: `Updating session data value ${e}`, hashedSessionCookie: _.hash(a) })), await this.keyStorage.updateData(r, e, t);
5086
5086
  }
5087
5087
  /**
5088
5088
  * Update field sin the session data.
@@ -5094,7 +5094,7 @@ class rr {
5094
5094
  */
5095
5095
  async updateManySessionData(a, e) {
5096
5096
  const t = j.hashSessionId(a);
5097
- h.logger.debug(m({ msg: "Updating session data", hashedSessionCookie: k.hash(a) })), await this.keyStorage.updateManyData(t, e);
5097
+ h.logger.debug(m({ msg: "Updating session data", hashedSessionCookie: _.hash(a) })), await this.keyStorage.updateManyData(t, e);
5098
5098
  }
5099
5099
  /**
5100
5100
  * Deletes a field from the session data.
@@ -5106,7 +5106,7 @@ class rr {
5106
5106
  */
5107
5107
  async deleteSessionData(a, e) {
5108
5108
  const t = j.hashSessionId(a);
5109
- h.logger.debug(m({ msg: `Updating session data value ${e}`, hashedSessionCookie: k.hash(a) })), await this.keyStorage.deleteData(t, e);
5109
+ h.logger.debug(m({ msg: `Updating session data value ${e}`, hashedSessionCookie: _.hash(a) })), await this.keyStorage.deleteData(t, e);
5110
5110
  }
5111
5111
  /**
5112
5112
  * Deletes the given session ID from the key storage (not the cookie)
@@ -5245,8 +5245,8 @@ class rr {
5245
5245
  const n = this.authenticators[i.factor2];
5246
5246
  if (!n) throw new o(l.Configuration, "Unrecognised second factor authentication");
5247
5247
  const c = {}, d = n.secretNames();
5248
- for (let _ in i)
5249
- d.includes(_) && (c[_] = i[_]);
5248
+ for (let k in i)
5249
+ d.includes(k) && (c[k] = i[k]);
5250
5250
  if (await n.authenticateUser(void 0, i, a), t || (t = (await this.userStorage.getUserByUsername(s, { skipActiveCheck: !0, skipEmailVerifiedCheck: !0 })).user), !t) throw new o(l.UserNotExist, "Couldn't fetch user");
5251
5251
  let f = E.active;
5252
5252
  t.state == E.awaitingTwoFactorSetupAndEmailVerification && (f = E.awaitingEmailVerification);
@@ -5360,7 +5360,7 @@ class rr {
5360
5360
  await y.authenticateUser(d, { ...f, ...s }, a);
5361
5361
  const C = await this.session.createSessionKey(d.id, t);
5362
5362
  await this.keyStorage.deleteKey(j.hashSessionId(i.value));
5363
- const _ = this.session.makeCookie(C, r), p = this.csrfTokens.createCsrfToken(), T = this.csrfTokens.makeCsrfCookie(p), v = this.csrfTokens.makeCsrfFormOrHeaderToken(p);
5363
+ const k = this.session.makeCookie(C, r), p = this.csrfTokens.createCsrfToken(), T = this.csrfTokens.makeCsrfCookie(p), v = this.csrfTokens.makeCsrfFormOrHeaderToken(p);
5364
5364
  try {
5365
5365
  this.emailTokenStorage.deleteAllForUser(
5366
5366
  d.id,
@@ -5370,7 +5370,7 @@ class rr {
5370
5370
  h.logger.warn(m({ msg: "Couldn't delete password reset tokens while logging in", user: n })), h.logger.debug(m({ err: b }));
5371
5371
  }
5372
5372
  return {
5373
- sessionCookie: _,
5373
+ sessionCookie: k,
5374
5374
  csrfCookie: T,
5375
5375
  csrfFormOrHeaderValue: v,
5376
5376
  user: d
@@ -5506,7 +5506,7 @@ class rr {
5506
5506
  return { ...i, state: n };
5507
5507
  }
5508
5508
  }
5509
- class ke {
5509
+ class _e {
5510
5510
  /**
5511
5511
  * Constructor.
5512
5512
  *
@@ -5544,7 +5544,7 @@ class ke {
5544
5544
  * Authorization header (with the signature appended.)
5545
5545
  */
5546
5546
  async createKey(a, e, t, r, i) {
5547
- const s = k.randomValue(this.keyLength), n = /* @__PURE__ */ new Date(), c = r ? new Date(n.getTime() + r * 1e3) : void 0, d = ke.hashApiKeyValue(s), f = {
5547
+ const s = _.randomValue(this.keyLength), n = /* @__PURE__ */ new Date(), c = r ? new Date(n.getTime() + r * 1e3) : void 0, d = _e.hashApiKeyValue(s), f = {
5548
5548
  name: a,
5549
5549
  value: s,
5550
5550
  userid: e,
@@ -5565,7 +5565,7 @@ class ke {
5565
5565
  return { key: f, token: y };
5566
5566
  }
5567
5567
  static hashApiKeyValue(a) {
5568
- return k.hash(a);
5568
+ return _.hash(a);
5569
5569
  }
5570
5570
  /**
5571
5571
  * Returns the hash of the bearer value from the Authorization header.
@@ -5576,20 +5576,20 @@ class ke {
5576
5576
  * @returns a hash of the value (without the prefix).
5577
5577
  */
5578
5578
  static hashSignedApiKeyValue(a) {
5579
- return k.hash(a.split(".")[0]);
5579
+ return _.hash(a.split(".")[0]);
5580
5580
  }
5581
5581
  unsignApiKeyValue(a) {
5582
- return k.unsign(a, this.secret).v;
5582
+ return _.unsign(a, this.secret).v;
5583
5583
  }
5584
5584
  signApiKeyValue(a) {
5585
- return k.sign({ v: a }, this.secret);
5585
+ return _.sign({ v: a }, this.secret);
5586
5586
  }
5587
5587
  async getKey(a) {
5588
5588
  if (this.authScheme != "" && a.startsWith(this.authScheme + " ")) {
5589
5589
  const i = new RegExp(`^${this.authScheme} `);
5590
5590
  a = a.replace(i, "");
5591
5591
  }
5592
- const e = this.unsignApiKeyValue(a), t = ke.hashApiKeyValue(e), r = await this.apiKeyStorage.getKey(this.prefix + t);
5592
+ const e = this.unsignApiKeyValue(a), t = _e.hashApiKeyValue(e), r = await this.apiKeyStorage.getKey(this.prefix + t);
5593
5593
  if (!("name" in r)) throw new o(l.InvalidKey, "Not a valid API key");
5594
5594
  return { ...r, name: r.name };
5595
5595
  }
@@ -5638,7 +5638,7 @@ class Q {
5638
5638
  async createClient(a, e, t, r = !0, i) {
5639
5639
  const s = Q.randomClientId();
5640
5640
  let n, c;
5641
- r && (c = Q.randomClientSecret(), n = await k.passwordHash(c, {
5641
+ r && (c = Q.randomClientSecret(), n = await _.passwordHash(c, {
5642
5642
  encode: !0,
5643
5643
  iterations: this.oauthPbkdf2Iterations,
5644
5644
  keyLen: this.oauthPbkdf2KeyLength,
@@ -5681,7 +5681,7 @@ class Q {
5681
5681
  async updateClient(a, e, t = !1) {
5682
5682
  const r = await this.clientStorage.getClientById(a);
5683
5683
  let i = !1, s;
5684
- e.confidential === !0 && !r.confidential || e.confidential === !0 && t ? (s = Q.randomClientSecret(), e.client_secret = await k.passwordHash(s, {
5684
+ e.confidential === !0 && !r.confidential || e.confidential === !0 && t ? (s = Q.randomClientSecret(), e.client_secret = await _.passwordHash(s, {
5685
5685
  encode: !0,
5686
5686
  iterations: this.oauthPbkdf2Iterations,
5687
5687
  keyLen: this.oauthPbkdf2KeyLength,
@@ -5696,13 +5696,13 @@ class Q {
5696
5696
  * Create a random OAuth client id
5697
5697
  */
5698
5698
  static randomClientId() {
5699
- return k.randomValue(pt);
5699
+ return _.randomValue(pt);
5700
5700
  }
5701
5701
  /**
5702
5702
  * Create a random OAuth client secret
5703
5703
  */
5704
5704
  static randomClientSecret() {
5705
- return k.randomValue(Ct);
5705
+ return _.randomValue(Ct);
5706
5706
  }
5707
5707
  /** If the passed redirect URI is not in the set of valid ones,
5708
5708
  * throw {@link @crossauth/common!CrossauthError} with
@@ -5779,7 +5779,7 @@ class St extends je {
5779
5779
  * @returns Base64-url-encoded hash
5780
5780
  */
5781
5781
  async hash(e) {
5782
- return k.hash(e);
5782
+ return _.hash(e);
5783
5783
  }
5784
5784
  /**
5785
5785
  * If the given token is valid, the paylaod is returned. Otherwise
@@ -5800,7 +5800,7 @@ class St extends je {
5800
5800
  const i = await super.tokenAuthorized(e, t, r);
5801
5801
  if (i && t == "access" && this.persistAccessToken && this.keyStorage)
5802
5802
  try {
5803
- const n = U.accessToken + k.hash(i.jti ? i.jti : i.sid ? i.sid : ""), c = await this.keyStorage.getKey(n), d = /* @__PURE__ */ new Date();
5803
+ const n = U.accessToken + _.hash(i.jti ? i.jti : i.sid ? i.sid : ""), c = await this.keyStorage.getKey(n), d = /* @__PURE__ */ new Date();
5804
5804
  if (c.expires && ((s = c.expires) == null ? void 0 : s.getTime()) < d.getTime()) {
5805
5805
  h.logger.error(m({ msg: "Access token expired in storage but not in JWT" }));
5806
5806
  return;
@@ -5808,7 +5808,7 @@ class St extends je {
5808
5808
  } catch (n) {
5809
5809
  h.logger.warn(m({
5810
5810
  msg: "Couldn't get token from database - is it valid?",
5811
- hashedAccessToken: k.hash(i.jti ? i.jti : i.sid ? i.sid : "")
5811
+ hashedAccessToken: _.hash(i.jti ? i.jti : i.sid ? i.sid : "")
5812
5812
  })), h.logger.debug(m({ err: n }));
5813
5813
  return;
5814
5814
  }
@@ -5848,7 +5848,7 @@ class De extends He {
5848
5848
  u(this, "userStorage");
5849
5849
  this.client_id = r.client_id;
5850
5850
  let i = {};
5851
- if (w("stateLength", g.String, this, t, "OAUTH_STATE_LENGTH"), w("verifierLength", g.String, this, t, "OAUTH_VERIFIER_LENGTH"), w("client_secret", g.String, i, t, "OAUTH_CLIENT_SECRET"), w("codeChallengeMethod", g.String, this, t, "OAUTH_CODE_CHALLENGE_METHOD"), w("deviceAuthorizationUrl", g.String, this, t, "OAUTH_DEVICE_AUTHORIZATION_URL"), w("oauthLogFetch", g.Boolean, this, t, "OAUTH_LOG_FETCH"), this.deviceAuthorizationUrl.startsWith("/") && (this.deviceAuthorizationUrl = this.deviceAuthorizationUrl.substring(1)), i.client_secret && (this.client_secret = i.client_secret), w("userCreationType", g.String, this, t, "OAUTH_USER_CREATION_TYPE"), w("userMatchField", g.String, this, t, "OAUTH_USER_MATCH_FIELD"), w("idTokenMatchField", g.String, this, t, "OAUTH_IDTOKEN_MaTCH_FIELD"), this.userCreationType == "merge" ? this.userCreationFn = Tt : this.userCreationType == "embed" ? this.userCreationFn = _t : t.userCreationFn && this.userCreationType == "custom" ? this.userCreationFn = t.userCreationFn : this.userCreationFn = kt, t.userStorage && (this.userStorage = t.userStorage), w("oauthPostType", g.String, this, t, "OAUTH_POST_TYPE"), w("oauthUseUserInfoEndpoint", g.Boolean, this, t, "OAUTH_USE_USER_INFO_ENDPOINT"), w("oauthAuthorizeRedirect", g.String, this, t, "OAUTH_AUTHORIZE_REDIRECT"), this.oauthPostType != "json" && this.oauthPostType != "form")
5851
+ if (w("stateLength", g.String, this, t, "OAUTH_STATE_LENGTH"), w("verifierLength", g.String, this, t, "OAUTH_VERIFIER_LENGTH"), w("client_secret", g.String, i, t, "OAUTH_CLIENT_SECRET"), w("codeChallengeMethod", g.String, this, t, "OAUTH_CODE_CHALLENGE_METHOD"), w("deviceAuthorizationUrl", g.String, this, t, "OAUTH_DEVICE_AUTHORIZATION_URL"), w("oauthLogFetch", g.Boolean, this, t, "OAUTH_LOG_FETCH"), this.deviceAuthorizationUrl.startsWith("/") && (this.deviceAuthorizationUrl = this.deviceAuthorizationUrl.substring(1)), i.client_secret && (this.client_secret = i.client_secret), w("userCreationType", g.String, this, t, "OAUTH_USER_CREATION_TYPE"), w("userMatchField", g.String, this, t, "OAUTH_USER_MATCH_FIELD"), w("idTokenMatchField", g.String, this, t, "OAUTH_IDTOKEN_MaTCH_FIELD"), this.userCreationType == "merge" ? this.userCreationFn = Tt : this.userCreationType == "embed" ? this.userCreationFn = kt : t.userCreationFn && this.userCreationType == "custom" ? this.userCreationFn = t.userCreationFn : this.userCreationFn = _t, t.userStorage && (this.userStorage = t.userStorage), w("oauthPostType", g.String, this, t, "OAUTH_POST_TYPE"), w("oauthUseUserInfoEndpoint", g.Boolean, this, t, "OAUTH_USE_USER_INFO_ENDPOINT"), w("oauthAuthorizeRedirect", g.String, this, t, "OAUTH_AUTHORIZE_REDIRECT"), this.oauthPostType != "json" && this.oauthPostType != "form")
5852
5852
  throw new o(l.Configuration, "oauthPostType must be json or form");
5853
5853
  }
5854
5854
  /**
@@ -5858,7 +5858,7 @@ class De extends He {
5858
5858
  * @returns the Base64-URL-encoded random string
5859
5859
  */
5860
5860
  randomValue(e) {
5861
- return k.randomValue(e);
5861
+ return _.randomValue(e);
5862
5862
  }
5863
5863
  /**
5864
5864
  * Uses {@link @crossauth/backend!Crypto.sha256} to create hash a string using SHA256
@@ -5866,7 +5866,7 @@ class De extends He {
5866
5866
  * @returns the Base64-URL-encoded hash
5867
5867
  */
5868
5868
  async sha256(e) {
5869
- return k.sha256(e);
5869
+ return _.sha256(e);
5870
5870
  }
5871
5871
  }
5872
5872
  async function Tt(S, a, e, t) {
@@ -5881,7 +5881,7 @@ async function Tt(S, a, e, t) {
5881
5881
  throw h.logger.error(m({ err: r })), r;
5882
5882
  }
5883
5883
  }
5884
- async function _t(S, a, e, t) {
5884
+ async function kt(S, a, e, t) {
5885
5885
  if (!a) throw new o(l.Configuration, "userCreationType set to embed but no user storage set");
5886
5886
  try {
5887
5887
  let r;
@@ -5893,7 +5893,7 @@ async function _t(S, a, e, t) {
5893
5893
  throw h.logger.error({ err: r }), r;
5894
5894
  }
5895
5895
  }
5896
- async function kt(S, a, e, t) {
5896
+ async function _t(S, a, e, t) {
5897
5897
  return {
5898
5898
  ...S,
5899
5899
  id: S.userid ?? S.sub,
@@ -6122,11 +6122,11 @@ class ir {
6122
6122
  const {
6123
6123
  scopes: y,
6124
6124
  error: C,
6125
- error_description: _
6125
+ error_description: k
6126
6126
  } = await this.validateAndPersistScope(e, r, c);
6127
6127
  if (C) return {
6128
6128
  error: C,
6129
- error_description: _
6129
+ error_description: k
6130
6130
  };
6131
6131
  const p = this.inferFlowFromGet(a, y || [], s);
6132
6132
  if (!p || !this.validFlows.includes(p))
@@ -6247,7 +6247,7 @@ class ir {
6247
6247
  } : r && (!t || !e.client_secret) ? {
6248
6248
  error: "access_denied",
6249
6249
  error_description: "Client is confidential but either secret not passed or is missing in database"
6250
- } : r && !await k.passwordsEqual(
6250
+ } : r && !await _.passwordsEqual(
6251
6251
  t ?? "",
6252
6252
  e.client_secret ?? ""
6253
6253
  ) ? {
@@ -6294,7 +6294,7 @@ class ir {
6294
6294
  mfaToken: f,
6295
6295
  oobCode: y,
6296
6296
  bindingCode: C,
6297
- otp: _,
6297
+ otp: k,
6298
6298
  deviceCode: p
6299
6299
  }) {
6300
6300
  var R, Y, W, ie;
@@ -6366,6 +6366,7 @@ class ir {
6366
6366
  }
6367
6367
  if (n)
6368
6368
  if (h.logger.debug(m({ msg: "token endpoint: refresh token flow" })), F && D && K && P) {
6369
+ h.logger.debug(m({ msg: "token endpoint: refreshing locally and upstream" }));
6369
6370
  let A;
6370
6371
  if (F.username)
6371
6372
  try {
@@ -6383,7 +6384,7 @@ class ir {
6383
6384
  }
6384
6385
  let x = F.scope;
6385
6386
  try {
6386
- const H = U.refreshToken + k.hash(n);
6387
+ const H = U.refreshToken + _.hash(n);
6387
6388
  await this.keyStorage.deleteKey(H);
6388
6389
  } catch (H) {
6389
6390
  const J = o.asCrossauthError(H);
@@ -6435,6 +6436,7 @@ class ir {
6435
6436
  error_description: z.error_description
6436
6437
  };
6437
6438
  } else if (D && K && P) {
6439
+ h.logger.debug(m({ msg: "token endpoint: refreshing upstream" }));
6438
6440
  let A = await K.refreshTokenFlow(D);
6439
6441
  if (!A.access_token)
6440
6442
  return {
@@ -6461,7 +6463,7 @@ class ir {
6461
6463
  error_description: B.error_description
6462
6464
  };
6463
6465
  } else {
6464
- if (F = await this.getRefreshTokenData(n), !n || !F || !this.userStorage)
6466
+ if (h.logger.debug(m({ msg: "token endpoint: refreshing locally" })), F = await this.getRefreshTokenData(n), !n || !F || !this.userStorage)
6465
6467
  return {
6466
6468
  error: "access_denied",
6467
6469
  error_description: "Refresh token is invalid"
@@ -6483,7 +6485,7 @@ class ir {
6483
6485
  }
6484
6486
  let X = F.scopes;
6485
6487
  try {
6486
- const z = U.refreshToken + k.hash(n);
6488
+ const z = U.refreshToken + _.hash(n);
6487
6489
  await this.keyStorage.deleteKey(z);
6488
6490
  } catch (z) {
6489
6491
  const H = o.asCrossauthError(z);
@@ -6615,7 +6617,7 @@ class ir {
6615
6617
  error: P,
6616
6618
  error_description: D
6617
6619
  };
6618
- if (!_)
6620
+ if (!k)
6619
6621
  return {
6620
6622
  error: "access_denied",
6621
6623
  error_description: "OTP not provided"
@@ -6625,7 +6627,7 @@ class ir {
6625
6627
  error: "access_denied",
6626
6628
  error_description: "MFA token not provided"
6627
6629
  };
6628
- const O = await this.validateMfaToken(f), F = U.mfaToken + k.hash(f);
6630
+ const O = await this.validateMfaToken(f), F = U.mfaToken + _.hash(f);
6629
6631
  if (!O.user || !O.key)
6630
6632
  return {
6631
6633
  error: "access_denied",
@@ -6642,7 +6644,7 @@ class ir {
6642
6644
  await A.authenticateUser(
6643
6645
  O.user,
6644
6646
  x,
6645
- { otp: _ }
6647
+ { otp: k }
6646
6648
  );
6647
6649
  } catch (x) {
6648
6650
  return h.logger.debug(m({ err: x })), {
@@ -6858,7 +6860,7 @@ class ir {
6858
6860
  const f = /* @__PURE__ */ new Date(), y = this.userCodeExpiry, C = new Date(f.getTime() + this.userCodeExpiry * 1e3 + this.clockTolerance * 1e3);
6859
6861
  for (let T = 0; T < 10 && !d; ++T)
6860
6862
  try {
6861
- c = k.randomValue(this.deviceCodeLength), await this.keyStorage.saveKey(
6863
+ c = _.randomValue(this.deviceCodeLength), await this.keyStorage.saveKey(
6862
6864
  void 0,
6863
6865
  U.deviceCode + c,
6864
6866
  f,
@@ -6873,13 +6875,13 @@ class ir {
6873
6875
  error: "server_error",
6874
6876
  error_description: "Couldn't create device code"
6875
6877
  };
6876
- let _;
6878
+ let k;
6877
6879
  d = !1;
6878
6880
  for (let T = 0; T < 10 && !d; ++T)
6879
6881
  try {
6880
- _ = k.randomBase32(this.userCodeLength), await this.keyStorage.saveKey(
6882
+ k = _.randomBase32(this.userCodeLength), await this.keyStorage.saveKey(
6881
6883
  void 0,
6882
- U.userCode + _,
6884
+ U.userCode + k,
6883
6885
  f,
6884
6886
  C,
6885
6887
  JSON.stringify({ deviceCode: c })
@@ -6887,20 +6889,20 @@ class ir {
6887
6889
  } catch {
6888
6890
  h.logger.debug(m({ msg: `Attempt number${T} at creating a unique authozation code failed` }));
6889
6891
  }
6890
- if (!d || !_)
6892
+ if (!d || !k)
6891
6893
  return await this.deleteDeviceCode(c), {
6892
6894
  error: "server_error",
6893
6895
  error_description: "Couldn't create device code"
6894
6896
  };
6895
- if (_ && this.userCodeDashEvery) {
6897
+ if (k && this.userCodeDashEvery) {
6896
6898
  const T = new RegExp(String.raw`(.{1,${this.userCodeDashEvery}})`, "g");
6897
- _ = (p = _.match(T)) == null ? void 0 : p.join("-");
6899
+ k = (p = k.match(T)) == null ? void 0 : p.join("-");
6898
6900
  }
6899
6901
  return {
6900
6902
  device_code: c,
6901
- user_code: _,
6903
+ user_code: k,
6902
6904
  verification_uri: this.deviceCodeVerificationUri,
6903
- verification_uri_complete: this.deviceCodeVerificationUri + "?user_code=" + _,
6905
+ verification_uri_complete: this.deviceCodeVerificationUri + "?user_code=" + k,
6904
6906
  expires_in: y,
6905
6907
  interval: this.deviceCodePollInterval
6906
6908
  };
@@ -6933,7 +6935,7 @@ class ir {
6933
6935
  };
6934
6936
  }
6935
6937
  if (!r.deviceCode)
6936
- return h.logger.error(m({ msg: "No device code for user code", userCodeHash: k.hash(a) })), await this.deleteUserCode(a), {
6938
+ return h.logger.error(m({ msg: "No device code for user code", userCodeHash: _.hash(a) })), await this.deleteUserCode(a), {
6937
6939
  ok: !1,
6938
6940
  error: "server_error",
6939
6941
  error_description: "No device code for user code"
@@ -6945,8 +6947,8 @@ class ir {
6945
6947
  const C = o.asCrossauthError(y);
6946
6948
  return h.logger.debug(m({ err: C })), h.logger.error(m({
6947
6949
  msg: "Invalid device code for user code",
6948
- userCodeHash: k.hash(a),
6949
- deviceCodeHash: k.hash(r.deviceCode),
6950
+ userCodeHash: _.hash(a),
6951
+ deviceCodeHash: _.hash(r.deviceCode),
6950
6952
  cerr: C
6951
6953
  })), await this.deleteUserCode(a), {
6952
6954
  ok: !1,
@@ -7041,7 +7043,7 @@ class ir {
7041
7043
  };
7042
7044
  }
7043
7045
  if (!t.deviceCode)
7044
- return h.logger.error(m({ msg: "No device code for user code", userCodeHash: k.hash(a) })), await this.deleteUserCode(a), {
7046
+ return h.logger.error(m({ msg: "No device code for user code", userCodeHash: _.hash(a) })), await this.deleteUserCode(a), {
7045
7047
  ok: !1,
7046
7048
  error: "server_error",
7047
7049
  error_description: "No device code for user code"
@@ -7053,8 +7055,8 @@ class ir {
7053
7055
  const c = o.asCrossauthError(n);
7054
7056
  return h.logger.debug(m({ err: c })), h.logger.error(m({
7055
7057
  msg: "Invalid device code for user code",
7056
- userCodeHash: k.hash(a),
7057
- deviceCodeHash: k.hash(t.deviceCode),
7058
+ userCodeHash: _.hash(a),
7059
+ deviceCodeHash: _.hash(t.deviceCode),
7058
7060
  cerr: c
7059
7061
  })), await this.deleteUserCode(a), {
7060
7062
  ok: !1,
@@ -7092,7 +7094,7 @@ class ir {
7092
7094
  };
7093
7095
  }
7094
7096
  async createMfaRequest(a) {
7095
- const e = k.randomValue(this.codeLength), t = U.mfaToken + k.hash(e), r = /* @__PURE__ */ new Date();
7097
+ const e = _.randomValue(this.codeLength), t = U.mfaToken + _.hash(e), r = /* @__PURE__ */ new Date();
7096
7098
  try {
7097
7099
  await this.keyStorage.saveKey(
7098
7100
  a.id,
@@ -7118,7 +7120,7 @@ class ir {
7118
7120
  var r;
7119
7121
  let e, t;
7120
7122
  try {
7121
- const i = U.mfaToken + k.hash(a);
7123
+ const i = U.mfaToken + _.hash(a);
7122
7124
  if (t = await this.keyStorage.getKey(i), !t.userid)
7123
7125
  return {
7124
7126
  error: "access_denied",
@@ -7221,7 +7223,7 @@ class ir {
7221
7223
  };
7222
7224
  let y = {};
7223
7225
  r == "oob" && (y = {
7224
- oobCode: k.randomValue(this.codeLength)
7226
+ oobCode: _.randomValue(this.codeLength)
7225
7227
  });
7226
7228
  try {
7227
7229
  const C = this.authenticators[f.user.factor2];
@@ -7230,11 +7232,11 @@ class ir {
7230
7232
  l.Configuration,
7231
7233
  "User's authenticator has not been loaded"
7232
7234
  );
7233
- const _ = await C.createOneTimeSecrets(f.user);
7235
+ const k = await C.createOneTimeSecrets(f.user);
7234
7236
  await this.keyStorage.updateData(
7235
7237
  f.key.value,
7236
7238
  "omfa",
7237
- { ...y, ..._ }
7239
+ { ...y, ...k }
7238
7240
  );
7239
7241
  } catch (C) {
7240
7242
  return h.logger.debug(m({ err: C })), {
@@ -7303,22 +7305,22 @@ class ir {
7303
7305
  client_id: a.client_id,
7304
7306
  redirect_uri: e
7305
7307
  };
7306
- t && (y.scope = t), i && (y.challengeMethod = s, y.challenge = k.hash(i)), n && (y.username = n.username, y.id = n.id);
7308
+ t && (y.scope = t), i && (y.challengeMethod = s, y.challenge = _.hash(i)), n && (y.username = n.username, y.id = n.id);
7307
7309
  const C = JSON.stringify(y);
7308
- let _ = !1, p = "";
7309
- for (let T = 0; T < 10 && !_; ++T)
7310
+ let k = !1, p = "";
7311
+ for (let T = 0; T < 10 && !k; ++T)
7310
7312
  try {
7311
- p = k.randomValue(this.codeLength), await this.keyStorage.saveKey(
7313
+ p = _.randomValue(this.codeLength), await this.keyStorage.saveKey(
7312
7314
  void 0,
7313
- U.authorizationCode + k.hash(p),
7315
+ U.authorizationCode + _.hash(p),
7314
7316
  d,
7315
7317
  f,
7316
7318
  C
7317
- ), _ = !0;
7319
+ ), k = !0;
7318
7320
  } catch {
7319
7321
  h.logger.debug(m({ msg: `Attempt number${T} at creating a unique authozation code failed` }));
7320
7322
  }
7321
- if (!_)
7323
+ if (!k)
7322
7324
  throw new o(
7323
7325
  l.KeyExists,
7324
7326
  "Couldn't create a authorization code"
@@ -7328,7 +7330,7 @@ class ir {
7328
7330
  async getAuthorizationCodeData(a) {
7329
7331
  let e, t = {};
7330
7332
  try {
7331
- e = await this.keyStorage.getKey(U.authorizationCode + k.hash(a)), t = V.decodeData(e.data);
7333
+ e = await this.keyStorage.getKey(U.authorizationCode + _.hash(a)), t = V.decodeData(e.data);
7332
7334
  } catch (r) {
7333
7335
  h.logger.debug(m({ err: r }));
7334
7336
  return;
@@ -7337,7 +7339,7 @@ class ir {
7337
7339
  }
7338
7340
  async deleteAuthorizationCodeData(a) {
7339
7341
  try {
7340
- await this.keyStorage.deleteKey(U.authorizationCode + k.hash(a));
7342
+ await this.keyStorage.deleteKey(U.authorizationCode + _.hash(a));
7341
7343
  } catch (e) {
7342
7344
  h.logger.warn(m({
7343
7345
  err: e,
@@ -7346,7 +7348,7 @@ class ir {
7346
7348
  }
7347
7349
  }
7348
7350
  async setAuthorizationCodeData(a, e) {
7349
- const t = await this.keyStorage.getKey(U.authorizationCode + k.hash(a));
7351
+ const t = await this.keyStorage.getKey(U.authorizationCode + _.hash(a));
7350
7352
  t.data = JSON.stringify(e), this.keyStorage.updateKey(t);
7351
7353
  }
7352
7354
  /**
@@ -7364,7 +7366,7 @@ class ir {
7364
7366
  var M, $;
7365
7367
  let c = !0;
7366
7368
  try {
7367
- a.client_secret != null && (c = await k.passwordsEqual(
7369
+ a.client_secret != null && (c = await _.passwordsEqual(
7368
7370
  t ?? "",
7369
7371
  a.client_secret ?? ""
7370
7372
  ));
@@ -7379,7 +7381,7 @@ class ir {
7379
7381
  if (e) {
7380
7382
  let N;
7381
7383
  try {
7382
- N = await this.keyStorage.getKey(U.authorizationCode + k.hash(e)), d = V.decodeData(N.data);
7384
+ N = await this.keyStorage.getKey(U.authorizationCode + _.hash(e)), d = V.decodeData(N.data);
7383
7385
  } catch (R) {
7384
7386
  return h.logger.debug(m({ err: R })), {
7385
7387
  error: "access_denied",
@@ -7403,8 +7405,8 @@ class ir {
7403
7405
  error_description: "Invalid code challenge/code challenge method method for authorization code"
7404
7406
  };
7405
7407
  if (d.challenge) {
7406
- const N = d.challengeMethod == "plain" ? r ?? "" : k.sha256(r ?? "");
7407
- if (k.hash(N) != d.challenge)
7408
+ const N = d.challengeMethod == "plain" ? r ?? "" : _.sha256(r ?? "");
7409
+ if (_.hash(N) != d.challenge)
7408
7410
  return {
7409
7411
  error: "access_denied",
7410
7412
  error_description: "Code verifier is incorrect"
@@ -7422,9 +7424,9 @@ class ir {
7422
7424
  error_description: "Couldn't load user data"
7423
7425
  };
7424
7426
  }
7425
- const _ = k.uuid();
7427
+ const k = _.uuid();
7426
7428
  let p = {
7427
- jti: _,
7429
+ jti: k,
7428
7430
  iat: y,
7429
7431
  iss: this.oauthIssuer,
7430
7432
  sub: d.username,
@@ -7447,13 +7449,13 @@ class ir {
7447
7449
  this.persistAccessToken && this.keyStorage && await ((M = this.keyStorage) == null ? void 0 : M.saveKey(
7448
7450
  void 0,
7449
7451
  // to avoid user storage dependency, we don't set this
7450
- U.accessToken + k.hash(_),
7452
+ U.accessToken + _.hash(k),
7451
7453
  f,
7452
7454
  C
7453
7455
  ));
7454
7456
  let v;
7455
7457
  if (i && i.includes("openid")) {
7456
- const N = k.uuid();
7458
+ const N = _.uuid();
7457
7459
  let R = {
7458
7460
  aud: a.client_id,
7459
7461
  jti: N,
@@ -7506,7 +7508,7 @@ class ir {
7506
7508
  i && (N.scope = i);
7507
7509
  let R;
7508
7510
  const W = {
7509
- jti: k.uuid(),
7511
+ jti: _.uuid(),
7510
7512
  iat: y,
7511
7513
  iss: this.oauthIssuer,
7512
7514
  sub: d.username,
@@ -7527,7 +7529,7 @@ class ir {
7527
7529
  }), b && await (($ = this.keyStorage) == null ? void 0 : $.saveKey(
7528
7530
  void 0,
7529
7531
  // to avoid user storage dependency
7530
- U.refreshToken + k.hash(b),
7532
+ U.refreshToken + _.hash(b),
7531
7533
  f,
7532
7534
  R,
7533
7535
  JSON.stringify(N)
@@ -7560,7 +7562,7 @@ class ir {
7560
7562
  r && (y.scope = r), e && (y.upstreamRefreshToken = e, y.upstreamLabel = t);
7561
7563
  let C;
7562
7564
  const p = {
7563
- jti: k.uuid(),
7565
+ jti: _.uuid(),
7564
7566
  iat: d,
7565
7567
  iss: this.oauthIssuer,
7566
7568
  sub: i,
@@ -7582,7 +7584,7 @@ class ir {
7582
7584
  return f && await ((T = this.keyStorage) == null ? void 0 : T.saveKey(
7583
7585
  void 0,
7584
7586
  // to avoid user storage dependency
7585
- U.refreshToken + k.hash(f),
7587
+ U.refreshToken + _.hash(f),
7586
7588
  c,
7587
7589
  C,
7588
7590
  JSON.stringify(y)
@@ -7596,7 +7598,7 @@ class ir {
7596
7598
  const r = /* @__PURE__ */ new Date(), i = Math.ceil(r.getTime() / 1e3);
7597
7599
  let s, n, c, d;
7598
7600
  if (e) {
7599
- const y = k.uuid();
7601
+ const y = _.uuid();
7600
7602
  let C = {
7601
7603
  ...e,
7602
7604
  jti: y,
@@ -7604,13 +7606,13 @@ class ir {
7604
7606
  iss: this.oauthIssuer,
7605
7607
  type: "access"
7606
7608
  };
7607
- this.accessTokenExpiry != null && (C.exp = i + this.accessTokenExpiry, s = new Date(r.getTime() + this.accessTokenExpiry * 1e3 + this.clockTolerance * 1e3)), this.audience && (C.aud = this.audience), n = await new Promise((_, p) => {
7609
+ this.accessTokenExpiry != null && (C.exp = i + this.accessTokenExpiry, s = new Date(r.getTime() + this.accessTokenExpiry * 1e3 + this.clockTolerance * 1e3)), this.audience && (C.aud = this.audience), n = await new Promise((k, p) => {
7608
7610
  ae.sign(
7609
7611
  C,
7610
7612
  this.secretOrPrivateKey,
7611
7613
  { algorithm: this.jwtAlgorithmChecked, keyid: "1" },
7612
7614
  (T, v) => {
7613
- v ? _(v) : p(T || new o(
7615
+ v ? k(v) : p(T || new o(
7614
7616
  l.Unauthorized,
7615
7617
  "Couldn't create jwt"
7616
7618
  ));
@@ -7619,13 +7621,13 @@ class ir {
7619
7621
  }), d = C, this.persistAccessToken && this.keyStorage && await ((f = this.keyStorage) == null ? void 0 : f.saveKey(
7620
7622
  void 0,
7621
7623
  // to avoid user storage dependency, we don't set this
7622
- U.accessToken + k.hash(y),
7624
+ U.accessToken + _.hash(y),
7623
7625
  r,
7624
7626
  s
7625
7627
  ));
7626
7628
  }
7627
7629
  if (t != null) {
7628
- const y = k.uuid();
7630
+ const y = _.uuid();
7629
7631
  if (t = {
7630
7632
  ...t,
7631
7633
  aud: a,
@@ -7635,7 +7637,7 @@ class ir {
7635
7637
  type: "id"
7636
7638
  }, t) {
7637
7639
  const C = t;
7638
- c = await new Promise((_, p) => {
7640
+ c = await new Promise((k, p) => {
7639
7641
  ae.sign(
7640
7642
  C,
7641
7643
  this.secretOrPrivateKey,
@@ -7644,7 +7646,7 @@ class ir {
7644
7646
  keyid: this.jwtKid
7645
7647
  },
7646
7648
  (T, v) => {
7647
- v ? _(v) : p(T || new o(
7649
+ v ? k(v) : p(T || new o(
7648
7650
  l.Unauthorized,
7649
7651
  "Couldn't create jwt"
7650
7652
  ));
@@ -7701,7 +7703,7 @@ class ir {
7701
7703
  */
7702
7704
  async validAuthorizationCode(a) {
7703
7705
  try {
7704
- const e = U.authorizationCode + k.hash(a);
7706
+ const e = U.authorizationCode + _.hash(a);
7705
7707
  return await this.keyStorage.getKey(e), !0;
7706
7708
  } catch (e) {
7707
7709
  return h.logger.debug(m({ err: e })), !1;
@@ -7715,7 +7717,7 @@ class ir {
7715
7717
  */
7716
7718
  async validRefreshToken(a) {
7717
7719
  try {
7718
- const e = U.refreshToken + k.hash(a);
7720
+ const e = U.refreshToken + _.hash(a);
7719
7721
  return await this.keyStorage.getKey(e), !0;
7720
7722
  } catch (e) {
7721
7723
  return h.logger.debug(m({ err: e })), !1;
@@ -7730,7 +7732,7 @@ class ir {
7730
7732
  async getRefreshTokenData(a) {
7731
7733
  if (a)
7732
7734
  try {
7733
- const e = U.refreshToken + k.hash(a), t = await this.keyStorage.getKey(e);
7735
+ const e = U.refreshToken + _.hash(a), t = await this.keyStorage.getKey(e);
7734
7736
  return JSON.parse(t.data || "{}");
7735
7737
  } catch (e) {
7736
7738
  h.logger.debug(m({ err: e }));
@@ -7764,7 +7766,7 @@ class ir {
7764
7766
  try {
7765
7767
  const e = await this.validateJwt(a, "access");
7766
7768
  if (this.persistAccessToken) {
7767
- const t = U.accessToken + k.hash(e.payload.jti);
7769
+ const t = U.accessToken + _.hash(e.payload.jti);
7768
7770
  await this.keyStorage.getKey(t);
7769
7771
  }
7770
7772
  return e;
@@ -8000,9 +8002,9 @@ class ar {
8000
8002
  }
8001
8003
  }
8002
8004
  export {
8003
- ke as ApiKeyManager,
8005
+ _e as ApiKeyManager,
8004
8006
  de as Authenticator,
8005
- k as Crypto,
8007
+ _ as Crypto,
8006
8008
  yt as DoubleSubmitCsrfToken,
8007
8009
  Zt as DummyFactor2Authenticator,
8008
8010
  ne as EmailAuthenticator,