authhero 9.44.3 → 9.44.4
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/authhero.cjs +5 -5
- package/dist/authhero.d.ts +132 -132
- package/dist/authhero.mjs +6 -6
- package/dist/{mfa-CzRZIlzU.mjs → mfa-D56D6aKD.mjs} +1 -1
- package/dist/{mfa-Bo75sbdf.js → mfa-Es8y5_jQ.js} +1 -1
- package/dist/{mfa-attempts-CkOmlAmq.mjs → mfa-attempts-4i0wth1x.mjs} +432 -412
- package/dist/{mfa-attempts-SqFc5Xcs.js → mfa-attempts-DxkUcou5.js} +14 -14
- package/dist/{passkey-enrollment-B0D65nrS.js → passkey-enrollment-BTMWec3j.js} +1 -1
- package/dist/tsconfig.types.tsbuildinfo +1 -1
- package/dist/types/hooks/pre-defined/ensure-username.d.ts +3 -0
- package/dist/types/index.d.ts +132 -132
- package/dist/types/routes/auth-api/index.d.ts +6 -6
- package/dist/types/routes/auth-api/passwordless.d.ts +6 -6
- package/dist/types/routes/management-api/connections.d.ts +8 -8
- package/dist/types/routes/management-api/index.d.ts +124 -124
- package/dist/types/routes/management-api/users.d.ts +21 -21
- package/dist/types/routes/universal-login/common.d.ts +4 -4
- package/dist/types/routes/universal-login/identifier.d.ts +2 -2
- package/dist/types/routes/universal-login/index.d.ts +2 -2
- package/package.json +3 -3
|
@@ -25407,7 +25407,10 @@ function $R(e) {
|
|
|
25407
25407
|
let n = e.email.split("@")[0];
|
|
25408
25408
|
n && t.push(QR(n));
|
|
25409
25409
|
}
|
|
25410
|
-
e.phone_number && t.push(QR(e.phone_number))
|
|
25410
|
+
if (e.phone_number && t.push(QR(e.phone_number)), e.email) {
|
|
25411
|
+
let [n, r] = e.email.split("@"), i = (r?.split(".").filter(Boolean) ?? []).slice(0, -1).join("-");
|
|
25412
|
+
n && i && t.push(QR(`${n}-${i}`));
|
|
25413
|
+
}
|
|
25411
25414
|
let r = /* @__PURE__ */ new Set(), i = [];
|
|
25412
25415
|
for (let e of t) e && !r.has(e) && (r.add(e), i.push(e));
|
|
25413
25416
|
return i;
|
|
@@ -25424,7 +25427,8 @@ async function ez(e, t, n, r) {
|
|
|
25424
25427
|
}
|
|
25425
25428
|
return !1;
|
|
25426
25429
|
}
|
|
25427
|
-
|
|
25430
|
+
var tz = 5, nz = 6;
|
|
25431
|
+
async function rz(e, t, n, r, i) {
|
|
25428
25432
|
for (let a of n) {
|
|
25429
25433
|
if (!await ez(e, t, a, r)) return a;
|
|
25430
25434
|
for (let n = 2; n <= i + 1; n++) {
|
|
@@ -25432,11 +25436,27 @@ async function tz(e, t, n, r, i) {
|
|
|
25432
25436
|
if (!await ez(e, t, i, r)) return i;
|
|
25433
25437
|
}
|
|
25434
25438
|
}
|
|
25439
|
+
let a = n[0];
|
|
25440
|
+
if (a) for (let n = 0; n < tz; n++) {
|
|
25441
|
+
let n = `${a}-${Ql().slice(0, nz)}`;
|
|
25442
|
+
if (!await ez(e, t, n, r)) return n;
|
|
25443
|
+
}
|
|
25435
25444
|
}
|
|
25436
|
-
function
|
|
25445
|
+
function iz(e, t) {
|
|
25437
25446
|
return t(e.provider) && e.username ? !0 : e.identities ? e.identities.some((e) => t(e.provider) && e.profileData?.username) : !1;
|
|
25438
25447
|
}
|
|
25439
|
-
function
|
|
25448
|
+
async function az(e, t, n, r) {
|
|
25449
|
+
console.warn(r);
|
|
25450
|
+
try {
|
|
25451
|
+
await O(e.ctx, t, {
|
|
25452
|
+
type: E.FAILED_HOOK,
|
|
25453
|
+
description: r,
|
|
25454
|
+
userId: n,
|
|
25455
|
+
details: { template_id: "ensure-username" }
|
|
25456
|
+
});
|
|
25457
|
+
} catch {}
|
|
25458
|
+
}
|
|
25459
|
+
function oz(e) {
|
|
25440
25460
|
let t = e?.connection ?? Ko.USERNAME_PASSWORD, n = e?.provider ?? "auth0", r = e?.provider ? (t) => t === e.provider : Cu, i = e?.provider ? [e.provider] : xu, a = Math.max(0, Math.floor(e?.maxRetries ?? 10));
|
|
25441
25461
|
return async (e, o) => {
|
|
25442
25462
|
let { ctx: s, user: c } = e;
|
|
@@ -25444,7 +25464,7 @@ function rz(e) {
|
|
|
25444
25464
|
let l = e.tenant?.id;
|
|
25445
25465
|
if (!l) return;
|
|
25446
25466
|
let u = s.env.data;
|
|
25447
|
-
if (
|
|
25467
|
+
if (iz(c, r)) return;
|
|
25448
25468
|
if (!r(c.provider)) for (let e of i) {
|
|
25449
25469
|
let { users: t } = await u.users.list(l, {
|
|
25450
25470
|
page: 0,
|
|
@@ -25456,23 +25476,23 @@ function rz(e) {
|
|
|
25456
25476
|
}
|
|
25457
25477
|
let d = $R(c);
|
|
25458
25478
|
if (d.length === 0) {
|
|
25459
|
-
|
|
25479
|
+
await az(e, l, c.user_id, `[ensureUsername] No username candidates found for user ${c.user_id}`);
|
|
25460
25480
|
return;
|
|
25461
25481
|
}
|
|
25462
|
-
for (let
|
|
25463
|
-
let
|
|
25464
|
-
if (!
|
|
25465
|
-
|
|
25482
|
+
for (let o = 0; o <= a; o++) {
|
|
25483
|
+
let s = await rz(u.users, l, d, i, a);
|
|
25484
|
+
if (!s) {
|
|
25485
|
+
await az(e, l, c.user_id, `[ensureUsername] Could not find a unique username for user ${c.user_id} after ${a} retries`);
|
|
25466
25486
|
return;
|
|
25467
25487
|
}
|
|
25468
25488
|
try {
|
|
25469
|
-
if (r(c.provider)) await u.users.update(l, c.user_id, { username:
|
|
25489
|
+
if (r(c.provider)) await u.users.update(l, c.user_id, { username: s });
|
|
25470
25490
|
else {
|
|
25471
25491
|
let e = `${n}|${Ql()}`;
|
|
25472
25492
|
await u.users.create(l, {
|
|
25473
25493
|
user_id: e,
|
|
25474
|
-
username:
|
|
25475
|
-
name:
|
|
25494
|
+
username: s,
|
|
25495
|
+
name: s,
|
|
25476
25496
|
provider: n,
|
|
25477
25497
|
connection: t,
|
|
25478
25498
|
email_verified: !1,
|
|
@@ -25481,17 +25501,17 @@ function rz(e) {
|
|
|
25481
25501
|
});
|
|
25482
25502
|
}
|
|
25483
25503
|
return;
|
|
25484
|
-
} catch (
|
|
25485
|
-
if (!YR(
|
|
25486
|
-
console.info(`[ensureUsername] Username "${
|
|
25504
|
+
} catch (e) {
|
|
25505
|
+
if (!YR(e)) throw e;
|
|
25506
|
+
console.info(`[ensureUsername] Username "${s}" was claimed concurrently, retrying (attempt ${o + 1}/${a})`);
|
|
25487
25507
|
}
|
|
25488
25508
|
}
|
|
25489
|
-
|
|
25509
|
+
await az(e, l, c.user_id, `[ensureUsername] Could not allocate a username for user ${c.user_id} after ${a} conflict retries`);
|
|
25490
25510
|
};
|
|
25491
25511
|
}
|
|
25492
25512
|
//#endregion
|
|
25493
25513
|
//#region src/hooks/pre-defined/set-preferred-username.ts
|
|
25494
|
-
function
|
|
25514
|
+
function sz(e) {
|
|
25495
25515
|
if (e.username) return e.username;
|
|
25496
25516
|
if (e.preferred_username) return e.preferred_username;
|
|
25497
25517
|
if (e.identities) for (let t of e.identities) {
|
|
@@ -25499,17 +25519,17 @@ function iz(e) {
|
|
|
25499
25519
|
if (t.profileData?.username) return t.profileData.username;
|
|
25500
25520
|
}
|
|
25501
25521
|
}
|
|
25502
|
-
function
|
|
25522
|
+
function cz() {
|
|
25503
25523
|
return async (e, t) => {
|
|
25504
25524
|
let { user: n } = e;
|
|
25505
25525
|
if (!n) return;
|
|
25506
|
-
let r =
|
|
25526
|
+
let r = sz(n);
|
|
25507
25527
|
r && (t.idToken.setCustomClaim("preferred_username", r), t.accessToken.setCustomClaim("preferred_username", r));
|
|
25508
25528
|
};
|
|
25509
25529
|
}
|
|
25510
25530
|
//#endregion
|
|
25511
25531
|
//#region src/helpers/link-candidates.ts
|
|
25512
|
-
async function
|
|
25532
|
+
async function lz(e) {
|
|
25513
25533
|
let { userAdapter: t, connectionAdapter: n, tenantId: r, user: i } = e, a = async (e) => {
|
|
25514
25534
|
if (!n || e.length === 0) return e;
|
|
25515
25535
|
let t = await ou(n, r, [i, ...e]);
|
|
@@ -25539,7 +25559,7 @@ async function oz(e) {
|
|
|
25539
25559
|
}
|
|
25540
25560
|
return (await a(d)).sort(Iu);
|
|
25541
25561
|
}
|
|
25542
|
-
function
|
|
25562
|
+
function uz(e) {
|
|
25543
25563
|
let t = e[0];
|
|
25544
25564
|
return e.map((e) => ({
|
|
25545
25565
|
user_id: e.user_id,
|
|
@@ -25554,7 +25574,7 @@ function sz(e) {
|
|
|
25554
25574
|
}
|
|
25555
25575
|
//#endregion
|
|
25556
25576
|
//#region src/hooks/pre-defined/account-linking.ts
|
|
25557
|
-
function
|
|
25577
|
+
function dz(e) {
|
|
25558
25578
|
if (!e) return {};
|
|
25559
25579
|
if (typeof e == "string") try {
|
|
25560
25580
|
let t = JSON.parse(e);
|
|
@@ -25564,7 +25584,7 @@ function cz(e) {
|
|
|
25564
25584
|
}
|
|
25565
25585
|
return typeof e == "object" && !Array.isArray(e) ? e : {};
|
|
25566
25586
|
}
|
|
25567
|
-
var
|
|
25587
|
+
var fz = [
|
|
25568
25588
|
"name",
|
|
25569
25589
|
"given_name",
|
|
25570
25590
|
"family_name",
|
|
@@ -25581,17 +25601,17 @@ var lz = [
|
|
|
25581
25601
|
"phone_number",
|
|
25582
25602
|
"address"
|
|
25583
25603
|
];
|
|
25584
|
-
function
|
|
25604
|
+
function pz(e) {
|
|
25585
25605
|
return e == null || e === "";
|
|
25586
25606
|
}
|
|
25587
|
-
function
|
|
25607
|
+
function mz(e) {
|
|
25588
25608
|
let t = e?.requireVerifiedEmail ?? !0, n = e?.copyUserMetadata ?? !1, r = e?.copyProfileFields ?? !1;
|
|
25589
25609
|
return async (e) => {
|
|
25590
25610
|
let { ctx: i, user: a } = e;
|
|
25591
25611
|
if (!a || !i) return;
|
|
25592
25612
|
let o = e.tenant?.id;
|
|
25593
25613
|
if (!o || a.linked_to || !a.email || t && !a.email_verified) return;
|
|
25594
|
-
let s = i.env.data, c = (await
|
|
25614
|
+
let s = i.env.data, c = (await lz({
|
|
25595
25615
|
userAdapter: s.users,
|
|
25596
25616
|
connectionAdapter: s.connections,
|
|
25597
25617
|
tenantId: o,
|
|
@@ -25600,7 +25620,7 @@ function dz(e) {
|
|
|
25600
25620
|
if (!c) return;
|
|
25601
25621
|
let l, u;
|
|
25602
25622
|
if (Iu(a, c) < 0 ? (l = a, u = c, await s.users.update(o, c.user_id, { linked_to: a.user_id })) : (l = c, u = a, await s.users.update(o, a.user_id, { linked_to: c.user_id })), n) {
|
|
25603
|
-
let e =
|
|
25623
|
+
let e = dz(u.user_metadata), t = dz(l.user_metadata);
|
|
25604
25624
|
if (e && Object.keys(e).length > 0) {
|
|
25605
25625
|
let n = {
|
|
25606
25626
|
...e,
|
|
@@ -25611,24 +25631,24 @@ function dz(e) {
|
|
|
25611
25631
|
}
|
|
25612
25632
|
if (r) {
|
|
25613
25633
|
let e = l, t = u, n = {};
|
|
25614
|
-
for (let r of
|
|
25634
|
+
for (let r of fz) pz(e[r]) && !pz(t[r]) && (n[r] = t[r]);
|
|
25615
25635
|
Object.keys(n).length > 0 && await s.users.update(o, l.user_id, n);
|
|
25616
25636
|
}
|
|
25617
25637
|
};
|
|
25618
25638
|
}
|
|
25619
25639
|
//#endregion
|
|
25620
25640
|
//#region src/hooks/pre-defined/index.ts
|
|
25621
|
-
var
|
|
25622
|
-
accountLinking: () =>
|
|
25623
|
-
ensureUsername: () =>
|
|
25624
|
-
setPreferredUsername: () =>
|
|
25641
|
+
var hz = /* @__PURE__ */ p({
|
|
25642
|
+
accountLinking: () => mz,
|
|
25643
|
+
ensureUsername: () => oz,
|
|
25644
|
+
setPreferredUsername: () => cz
|
|
25625
25645
|
});
|
|
25626
25646
|
//#endregion
|
|
25627
25647
|
//#region src/hooks/templatehooks.ts
|
|
25628
|
-
function
|
|
25648
|
+
function gz(e) {
|
|
25629
25649
|
return typeof e == "object" && !!e && typeof e.template_id == "string" && typeof e.enabled == "boolean";
|
|
25630
25650
|
}
|
|
25631
|
-
var
|
|
25651
|
+
var _z = {
|
|
25632
25652
|
prompt: { render: () => {} },
|
|
25633
25653
|
multifactor: { enable: () => {} },
|
|
25634
25654
|
redirect: {
|
|
@@ -25638,7 +25658,7 @@ var mz = {
|
|
|
25638
25658
|
},
|
|
25639
25659
|
token: { createServiceToken: async () => "" }
|
|
25640
25660
|
};
|
|
25641
|
-
async function
|
|
25661
|
+
async function vz(e, t, n, r) {
|
|
25642
25662
|
return await r({
|
|
25643
25663
|
ctx: e,
|
|
25644
25664
|
user: n,
|
|
@@ -25649,18 +25669,18 @@ async function hz(e, t, n, r) {
|
|
|
25649
25669
|
method: e.req.method,
|
|
25650
25670
|
user_agent: e.get("useragent") || ""
|
|
25651
25671
|
}
|
|
25652
|
-
},
|
|
25672
|
+
}, _z), await e.env.data.users.get(t, n.user_id) || n;
|
|
25653
25673
|
}
|
|
25654
|
-
async function
|
|
25674
|
+
async function yz(e, t, n, r) {
|
|
25655
25675
|
let i = e.var.tenant_id || e.req.header("tenant-id");
|
|
25656
25676
|
if (!i) return n;
|
|
25657
25677
|
switch (t) {
|
|
25658
|
-
case "ensure-username": return
|
|
25659
|
-
case "account-linking": return
|
|
25678
|
+
case "ensure-username": return vz(e, i, n, oz());
|
|
25679
|
+
case "account-linking": return vz(e, i, n, mz({ copyUserMetadata: r?.copy_user_metadata === !0 }));
|
|
25660
25680
|
default: return console.warn(`[templatehooks] Unknown template_id: ${t}`), n;
|
|
25661
25681
|
}
|
|
25662
25682
|
}
|
|
25663
|
-
async function
|
|
25683
|
+
async function bz(e, t, n, r) {
|
|
25664
25684
|
let i = e.var.tenant_id || e.req.header("tenant-id");
|
|
25665
25685
|
if (!i) return;
|
|
25666
25686
|
let a = {
|
|
@@ -25676,14 +25696,14 @@ async function _z(e, t, n, r) {
|
|
|
25676
25696
|
};
|
|
25677
25697
|
switch (t) {
|
|
25678
25698
|
case "set-preferred-username":
|
|
25679
|
-
await
|
|
25699
|
+
await cz()(a, r);
|
|
25680
25700
|
break;
|
|
25681
25701
|
default: console.warn(`[templatehooks] Unknown credentials-exchange template_id: ${t}`);
|
|
25682
25702
|
}
|
|
25683
25703
|
}
|
|
25684
25704
|
//#endregion
|
|
25685
25705
|
//#region src/hooks/helpers/token-api.ts
|
|
25686
|
-
function
|
|
25706
|
+
function xz(e, t) {
|
|
25687
25707
|
return { createServiceToken: async (n) => {
|
|
25688
25708
|
if ("clientId" in n && n.clientId !== void 0) {
|
|
25689
25709
|
if (typeof n.clientId != "string" || n.clientId.length === 0) throw Error("createServiceToken: `clientId` must be a non-empty string.");
|
|
@@ -25699,12 +25719,12 @@ function vz(e, t) {
|
|
|
25699
25719
|
return (await gO(e, t, n.scope, n.expiresInSeconds, n.customClaims)).access_token;
|
|
25700
25720
|
} };
|
|
25701
25721
|
}
|
|
25702
|
-
var
|
|
25722
|
+
var Sz = new Set([
|
|
25703
25723
|
...Object.values(Ko),
|
|
25704
25724
|
Jo,
|
|
25705
25725
|
"auth2",
|
|
25706
25726
|
"samlp"
|
|
25707
|
-
].map((e) => e.toLowerCase())),
|
|
25727
|
+
].map((e) => e.toLowerCase())), Cz = [
|
|
25708
25728
|
"email",
|
|
25709
25729
|
"phone_number",
|
|
25710
25730
|
"name",
|
|
@@ -25713,11 +25733,11 @@ var yz = new Set([
|
|
|
25713
25733
|
"nickname",
|
|
25714
25734
|
"picture"
|
|
25715
25735
|
];
|
|
25716
|
-
function
|
|
25736
|
+
function wz(e) {
|
|
25717
25737
|
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
25718
25738
|
}
|
|
25719
|
-
function
|
|
25720
|
-
if (!
|
|
25739
|
+
function Tz(e) {
|
|
25740
|
+
if (!wz(e)) return {
|
|
25721
25741
|
ok: !1,
|
|
25722
25742
|
reason: "invalid_params"
|
|
25723
25743
|
};
|
|
@@ -25732,7 +25752,7 @@ function Sz(e) {
|
|
|
25732
25752
|
connection: t,
|
|
25733
25753
|
id: n
|
|
25734
25754
|
};
|
|
25735
|
-
if (r !== void 0 && !
|
|
25755
|
+
if (r !== void 0 && !wz(r) || i !== void 0 && !wz(i)) return {
|
|
25736
25756
|
ok: !1,
|
|
25737
25757
|
reason: "invalid_params",
|
|
25738
25758
|
connection: t,
|
|
@@ -25740,7 +25760,7 @@ function Sz(e) {
|
|
|
25740
25760
|
};
|
|
25741
25761
|
let a = {};
|
|
25742
25762
|
if (r) {
|
|
25743
|
-
for (let e of
|
|
25763
|
+
for (let e of Cz) {
|
|
25744
25764
|
let t = r[e];
|
|
25745
25765
|
typeof t == "string" && t.trim() && (a[e] = e === "email" ? ku(t) : t.trim());
|
|
25746
25766
|
}
|
|
@@ -25756,22 +25776,22 @@ function Sz(e) {
|
|
|
25756
25776
|
}
|
|
25757
25777
|
};
|
|
25758
25778
|
}
|
|
25759
|
-
var
|
|
25760
|
-
async function
|
|
25779
|
+
var Ez = 100, Dz = 50;
|
|
25780
|
+
async function Oz(e, t) {
|
|
25761
25781
|
let n = [];
|
|
25762
|
-
for (let r = 0; r <
|
|
25782
|
+
for (let r = 0; r < Dz; r++) {
|
|
25763
25783
|
let { connections: i } = await e.connections.list(t, {
|
|
25764
25784
|
page: r,
|
|
25765
|
-
per_page:
|
|
25785
|
+
per_page: Ez,
|
|
25766
25786
|
include_totals: !1
|
|
25767
25787
|
});
|
|
25768
|
-
if (n.push(...i), i.length <
|
|
25788
|
+
if (n.push(...i), i.length < Ez) break;
|
|
25769
25789
|
}
|
|
25770
25790
|
return n;
|
|
25771
25791
|
}
|
|
25772
|
-
function
|
|
25773
|
-
let r = null, i = () => (r ||=
|
|
25774
|
-
let t = new Set(
|
|
25792
|
+
function kz(e, t, n = []) {
|
|
25793
|
+
let r = null, i = () => (r ||= Oz(e, t).then((e) => {
|
|
25794
|
+
let t = new Set(Sz);
|
|
25775
25795
|
for (let e of n) t.add(e.toLowerCase());
|
|
25776
25796
|
for (let n of e) n.strategy !== Ko.EXTERNAL && t.add(n.strategy.toLowerCase());
|
|
25777
25797
|
return {
|
|
@@ -25790,7 +25810,7 @@ function Ez(e, t, n = []) {
|
|
|
25790
25810
|
}
|
|
25791
25811
|
};
|
|
25792
25812
|
}
|
|
25793
|
-
function
|
|
25813
|
+
function Az(e) {
|
|
25794
25814
|
let { ctx: t, data: n, tenantId: r, triggerId: i, externalConnections: a } = e, o = /* @__PURE__ */ new Set(), s = 0, c = (e, n, a = {}) => {
|
|
25795
25815
|
O(t, r, {
|
|
25796
25816
|
type: E.FAILED_HOOK,
|
|
@@ -25808,7 +25828,7 @@ function Dz(e) {
|
|
|
25808
25828
|
c("too_many_users", `${i} action called users.ensure more than 5 times`);
|
|
25809
25829
|
return;
|
|
25810
25830
|
}
|
|
25811
|
-
let l =
|
|
25831
|
+
let l = Tz(e);
|
|
25812
25832
|
if (!l.ok) {
|
|
25813
25833
|
c(l.reason, `${i} action passed invalid arguments to users.ensure`, { connection: l.connection });
|
|
25814
25834
|
return;
|
|
@@ -25863,7 +25883,7 @@ function Dz(e) {
|
|
|
25863
25883
|
}
|
|
25864
25884
|
//#endregion
|
|
25865
25885
|
//#region src/hooks/lifecycle-codehooks.ts
|
|
25866
|
-
async function
|
|
25886
|
+
async function jz(e, t, n) {
|
|
25867
25887
|
let r = _R(e), i = [];
|
|
25868
25888
|
for (let e = 0;; e++) {
|
|
25869
25889
|
let a = await r.hooks.list(t, {
|
|
@@ -25875,8 +25895,8 @@ async function Oz(e, t, n) {
|
|
|
25875
25895
|
}
|
|
25876
25896
|
return i.filter((e) => e.enabled && e.trigger_id === n).filter(TR).sort((e, t) => (t.priority ?? 0) - (e.priority ?? 0));
|
|
25877
25897
|
}
|
|
25878
|
-
async function
|
|
25879
|
-
let i = _R(e), a = await
|
|
25898
|
+
async function Mz(e, t, n, r) {
|
|
25899
|
+
let i = _R(e), a = await jz(e, t, n), o = [], s = n === "validate-registration-username" ? "Signup not allowed by Action" : "Operation denied by lifecycle Action", c = async () => {
|
|
25880
25900
|
let r = await RR(i, t, n, o, { logCapture: e.env.actionExecutionLogs });
|
|
25881
25901
|
r && e.set("action_execution_id", r);
|
|
25882
25902
|
};
|
|
@@ -25924,14 +25944,14 @@ async function kz(e, t, n, r) {
|
|
|
25924
25944
|
}
|
|
25925
25945
|
return await c(), { allowed: !0 };
|
|
25926
25946
|
}
|
|
25927
|
-
async function
|
|
25928
|
-
let i = await
|
|
25947
|
+
async function Nz(e, t, n, r) {
|
|
25948
|
+
let i = await Mz(e, t, n, r);
|
|
25929
25949
|
if (!i.allowed) throw new k(400, { message: i.reason });
|
|
25930
25950
|
}
|
|
25931
25951
|
//#endregion
|
|
25932
25952
|
//#region src/hooks/validate-signup.ts
|
|
25933
|
-
var
|
|
25934
|
-
async function
|
|
25953
|
+
var Pz = 1e4;
|
|
25954
|
+
async function Fz(e, t, n, r, i = "email", a = {}) {
|
|
25935
25955
|
let o = t.connections.find((e) => e.name === i);
|
|
25936
25956
|
if (!o) {
|
|
25937
25957
|
let e = t.connections.filter((e) => e.strategy === i);
|
|
@@ -25975,7 +25995,7 @@ async function Mz(e, t, n, r, i = "email", a = {}) {
|
|
|
25975
25995
|
deny: (e) => {
|
|
25976
25996
|
a = !0, o = e;
|
|
25977
25997
|
},
|
|
25978
|
-
token:
|
|
25998
|
+
token: xz(e, t.tenant.id)
|
|
25979
25999
|
}), a) return {
|
|
25980
26000
|
allowed: !1,
|
|
25981
26001
|
reason: o
|
|
@@ -25987,7 +26007,7 @@ async function Mz(e, t, n, r, i = "email", a = {}) {
|
|
|
25987
26007
|
};
|
|
25988
26008
|
}
|
|
25989
26009
|
}
|
|
25990
|
-
let c = await
|
|
26010
|
+
let c = await Mz(e, t.tenant.id, "validate-registration-username", {
|
|
25991
26011
|
client: t,
|
|
25992
26012
|
tenant: { id: t.tenant.id },
|
|
25993
26013
|
user: {
|
|
@@ -26004,7 +26024,7 @@ async function Mz(e, t, n, r, i = "email", a = {}) {
|
|
|
26004
26024
|
if (!c.allowed) return c;
|
|
26005
26025
|
let l = await SR(e, t.tenant.id);
|
|
26006
26026
|
if (l && "url" in l) try {
|
|
26007
|
-
let n = await gO(e, t.tenant.id, "webhook"), a = new AbortController(), o = setTimeout(() => a.abort(),
|
|
26027
|
+
let n = await gO(e, t.tenant.id, "webhook"), a = new AbortController(), o = setTimeout(() => a.abort(), Pz), s;
|
|
26008
26028
|
try {
|
|
26009
26029
|
s = await fetch(l.url, {
|
|
26010
26030
|
method: "POST",
|
|
@@ -26041,8 +26061,8 @@ async function Mz(e, t, n, r, i = "email", a = {}) {
|
|
|
26041
26061
|
}
|
|
26042
26062
|
return { allowed: !0 };
|
|
26043
26063
|
}
|
|
26044
|
-
async function
|
|
26045
|
-
let a = await
|
|
26064
|
+
async function Iz(e, t, n, r, i) {
|
|
26065
|
+
let a = await Fz(e, t, n, r, i);
|
|
26046
26066
|
if (!a.allowed) throw O(e, t.tenant.id, {
|
|
26047
26067
|
type: E.FAILED_SIGNUP,
|
|
26048
26068
|
description: a.reason || "Signup not allowed"
|
|
@@ -26051,7 +26071,7 @@ async function Nz(e, t, n, r, i) {
|
|
|
26051
26071
|
}
|
|
26052
26072
|
//#endregion
|
|
26053
26073
|
//#region src/helpers/user-linking.ts
|
|
26054
|
-
async function
|
|
26074
|
+
async function Lz(e, t, n) {
|
|
26055
26075
|
if (n) {
|
|
26056
26076
|
let r = await e.env.data.clients.get(t, n);
|
|
26057
26077
|
if (r?.user_linking_mode) return r.user_linking_mode;
|
|
@@ -26066,12 +26086,12 @@ async function Pz(e, t, n) {
|
|
|
26066
26086
|
}
|
|
26067
26087
|
return r ?? "builtin";
|
|
26068
26088
|
}
|
|
26069
|
-
async function
|
|
26070
|
-
return await
|
|
26089
|
+
async function Rz(e, t, n) {
|
|
26090
|
+
return await Lz(e, t, n) === "builtin";
|
|
26071
26091
|
}
|
|
26072
26092
|
//#endregion
|
|
26073
26093
|
//#region src/errors/signup-validation-error.ts
|
|
26074
|
-
var
|
|
26094
|
+
var zz = class e extends t {
|
|
26075
26095
|
code;
|
|
26076
26096
|
constructor(t, n) {
|
|
26077
26097
|
super(400, {
|
|
@@ -26085,18 +26105,18 @@ var Iz = class e extends t {
|
|
|
26085
26105
|
};
|
|
26086
26106
|
//#endregion
|
|
26087
26107
|
//#region src/hooks/user-registration.ts
|
|
26088
|
-
function
|
|
26108
|
+
function Bz(e, t, n, r) {
|
|
26089
26109
|
let i = e[t];
|
|
26090
26110
|
e[t] = {
|
|
26091
26111
|
...i && typeof i == "object" && !Array.isArray(i) ? i : {},
|
|
26092
26112
|
[n]: r
|
|
26093
26113
|
};
|
|
26094
26114
|
}
|
|
26095
|
-
function
|
|
26115
|
+
function Vz(e, n) {
|
|
26096
26116
|
return async (r, i) => {
|
|
26097
26117
|
if (e.var.client_id && e.var.client_id_from_token !== !0) {
|
|
26098
26118
|
let t = await rR(e.env, e.var.client_id, e.var.tenant_id);
|
|
26099
|
-
i.email && await
|
|
26119
|
+
i.email && await Iz(e, t, n, i.email, i.connection);
|
|
26100
26120
|
}
|
|
26101
26121
|
let a = {
|
|
26102
26122
|
method: e.req.method,
|
|
@@ -26105,9 +26125,9 @@ function Rz(e, n) {
|
|
|
26105
26125
|
url: e.var.loginSession?.authorization_url || ul(e.req.url),
|
|
26106
26126
|
body: e.var.signup_body
|
|
26107
26127
|
}, { hooks: o } = await n.hooks.list(r), s = o.filter((e) => e.trigger_id === "pre-user-registration" && e.enabled).filter(TR), c = (e, t) => {
|
|
26108
|
-
|
|
26128
|
+
Bz(i, "user_metadata", e, t);
|
|
26109
26129
|
}, l = (e, t) => {
|
|
26110
|
-
|
|
26130
|
+
Bz(i, "app_metadata", e, t);
|
|
26111
26131
|
}, u = i.linked_to, d, f = (e) => {
|
|
26112
26132
|
d = e, i.linked_to = e;
|
|
26113
26133
|
};
|
|
@@ -26127,9 +26147,9 @@ function Rz(e, n) {
|
|
|
26127
26147
|
throw new k(400, { message: t ? `Registration denied: ${e} - ${t}` : `Registration denied: ${e}` });
|
|
26128
26148
|
} },
|
|
26129
26149
|
validation: { error: (e, t) => {
|
|
26130
|
-
throw new
|
|
26150
|
+
throw new zz(e, t);
|
|
26131
26151
|
} },
|
|
26132
|
-
token:
|
|
26152
|
+
token: xz(e, r)
|
|
26133
26153
|
});
|
|
26134
26154
|
} catch (n) {
|
|
26135
26155
|
if (n instanceof t) throw n;
|
|
@@ -26151,12 +26171,12 @@ function Rz(e, n) {
|
|
|
26151
26171
|
});
|
|
26152
26172
|
}
|
|
26153
26173
|
{
|
|
26154
|
-
let o = [], u =
|
|
26174
|
+
let o = [], u = Az({
|
|
26155
26175
|
ctx: e,
|
|
26156
26176
|
data: n,
|
|
26157
26177
|
tenantId: r,
|
|
26158
26178
|
triggerId: "pre-user-registration",
|
|
26159
|
-
externalConnections:
|
|
26179
|
+
externalConnections: kz(n, r, Object.keys(e.env.STRATEGIES ?? {}))
|
|
26160
26180
|
}), d = () => RR(n, r, "pre-user-registration", o, { logCapture: e.env.actionExecutionLogs }), p = (e, t) => {
|
|
26161
26181
|
throw new k(400, { message: t ? `Registration denied: ${e} - ${t}` : `Registration denied: ${e}` });
|
|
26162
26182
|
};
|
|
@@ -26176,13 +26196,13 @@ function Rz(e, n) {
|
|
|
26176
26196
|
users: u.api.users,
|
|
26177
26197
|
access: { deny: p },
|
|
26178
26198
|
validation: { error: (e, t) => {
|
|
26179
|
-
throw new
|
|
26199
|
+
throw new zz(e, t);
|
|
26180
26200
|
} }
|
|
26181
26201
|
}), !m && s && (m = NR(r.code_id));
|
|
26182
26202
|
} catch (n) {
|
|
26183
26203
|
if (n instanceof t) {
|
|
26184
26204
|
let t = MR(r.code_id, n, !0);
|
|
26185
|
-
n instanceof
|
|
26205
|
+
n instanceof zz && t.result.error && (t.result.error.id = n.code), o.push(t), await BR(e, d, n);
|
|
26186
26206
|
}
|
|
26187
26207
|
m = MR(r.code_id, n);
|
|
26188
26208
|
}
|
|
@@ -26209,7 +26229,7 @@ function Rz(e, n) {
|
|
|
26209
26229
|
primary_user_id: d
|
|
26210
26230
|
}
|
|
26211
26231
|
}), p = !0, u ? i.linked_to = u : delete i.linked_to)), i = Au(i);
|
|
26212
|
-
let m = !p && await
|
|
26232
|
+
let m = !p && await Rz(e, r, e.var.client_id), h = WR(e, r, "post-user-registration", i), g = await XR(n)(r, i, {
|
|
26213
26233
|
resolveEmailLinkedPrimary: m,
|
|
26214
26234
|
outboxEvents: h ? [h] : void 0
|
|
26215
26235
|
});
|
|
@@ -26224,7 +26244,7 @@ function Rz(e, n) {
|
|
|
26224
26244
|
tenant: { id: r }
|
|
26225
26245
|
}, {
|
|
26226
26246
|
user: {},
|
|
26227
|
-
token:
|
|
26247
|
+
token: xz(e, r)
|
|
26228
26248
|
});
|
|
26229
26249
|
} catch (t) {
|
|
26230
26250
|
let n = t instanceof Error ? t.message : String(t), i = t instanceof Error ? t.stack : void 0, a = t instanceof Error ? t.name : void 0;
|
|
@@ -26245,9 +26265,9 @@ function Rz(e, n) {
|
|
|
26245
26265
|
});
|
|
26246
26266
|
}
|
|
26247
26267
|
{
|
|
26248
|
-
let { hooks: t } = await _R(e).hooks.list(r), n = t.filter((e) => e.trigger_id === "post-user-registration" && e.enabled &&
|
|
26249
|
-
for (let t of n) if (
|
|
26250
|
-
_ = await
|
|
26268
|
+
let { hooks: t } = await _R(e).hooks.list(r), n = t.filter((e) => e.trigger_id === "post-user-registration" && e.enabled && gz(e));
|
|
26269
|
+
for (let t of n) if (gz(t)) try {
|
|
26270
|
+
_ = await yz(e, t.template_id, _, t.metadata);
|
|
26251
26271
|
} catch (n) {
|
|
26252
26272
|
let i = n instanceof Error ? n.message : String(n), a = n instanceof Error ? n.stack : void 0, o = n instanceof Error ? n.name : void 0;
|
|
26253
26273
|
O(e, r, {
|
|
@@ -26272,7 +26292,7 @@ function Rz(e, n) {
|
|
|
26272
26292
|
}
|
|
26273
26293
|
//#endregion
|
|
26274
26294
|
//#region src/hooks/user-update.ts
|
|
26275
|
-
function
|
|
26295
|
+
function Hz(e, t) {
|
|
26276
26296
|
return async (n, r, i) => {
|
|
26277
26297
|
if ("linked_to" in i && i.linked_to === r) throw new k(400, { message: "Cannot link a user to itself" });
|
|
26278
26298
|
if (Object.keys(i).length === 1 && "linked_to" in i) {
|
|
@@ -26307,7 +26327,7 @@ function zz(e, t) {
|
|
|
26307
26327
|
cancel: () => {
|
|
26308
26328
|
throw new k(400, { message: "User update cancelled by pre-update hook" });
|
|
26309
26329
|
},
|
|
26310
|
-
token:
|
|
26330
|
+
token: xz(e, n)
|
|
26311
26331
|
});
|
|
26312
26332
|
} catch (t) {
|
|
26313
26333
|
throw O(e, n, {
|
|
@@ -26321,7 +26341,7 @@ function zz(e, t) {
|
|
|
26321
26341
|
previousUser: o,
|
|
26322
26342
|
updates: aR(i)
|
|
26323
26343
|
};
|
|
26324
|
-
await
|
|
26344
|
+
await Nz(e, n, "pre-user-update", {
|
|
26325
26345
|
user: iR(o),
|
|
26326
26346
|
previous_user: iR(o),
|
|
26327
26347
|
updates: c.updates,
|
|
@@ -26329,7 +26349,7 @@ function zz(e, t) {
|
|
|
26329
26349
|
tenant: { id: n },
|
|
26330
26350
|
request: s
|
|
26331
26351
|
});
|
|
26332
|
-
let l = await
|
|
26352
|
+
let l = await Rz(e, n, e.var.client_id), u = WR(e, n, "post-user-update", {
|
|
26333
26353
|
...a,
|
|
26334
26354
|
...i
|
|
26335
26355
|
}, c);
|
|
@@ -26389,13 +26409,13 @@ function zz(e, t) {
|
|
|
26389
26409
|
...i
|
|
26390
26410
|
}, c);
|
|
26391
26411
|
{
|
|
26392
|
-
let { hooks: i } = await t.hooks.list(n), a = i.filter((e) => e.trigger_id === "post-user-update" &&
|
|
26412
|
+
let { hooks: i } = await t.hooks.list(n), a = i.filter((e) => e.trigger_id === "post-user-update" && gz(e) && e.enabled === !0);
|
|
26393
26413
|
if (a.length > 0) {
|
|
26394
26414
|
let i = await t.users.get(n, r);
|
|
26395
26415
|
if (i) {
|
|
26396
26416
|
let t = i;
|
|
26397
|
-
for (let i of a) if (
|
|
26398
|
-
t = await
|
|
26417
|
+
for (let i of a) if (gz(i)) try {
|
|
26418
|
+
t = await yz(e, i.template_id, t, i.metadata);
|
|
26399
26419
|
} catch (t) {
|
|
26400
26420
|
let a = t instanceof Error ? t.message : String(t), o = t instanceof Error ? t.stack : void 0, s = t instanceof Error ? t.name : void 0;
|
|
26401
26421
|
O(e, n, {
|
|
@@ -26427,7 +26447,7 @@ function zz(e, t) {
|
|
|
26427
26447
|
user: a ? iR(a) : void 0,
|
|
26428
26448
|
updates: i,
|
|
26429
26449
|
request: s
|
|
26430
|
-
}, { token:
|
|
26450
|
+
}, { token: xz(e, n) });
|
|
26431
26451
|
} catch (t) {
|
|
26432
26452
|
O(e, n, {
|
|
26433
26453
|
type: E.ACTIONS_EXECUTION_FAILED,
|
|
@@ -26440,13 +26460,13 @@ function zz(e, t) {
|
|
|
26440
26460
|
}
|
|
26441
26461
|
//#endregion
|
|
26442
26462
|
//#region src/hooks/user-deletion.ts
|
|
26443
|
-
function
|
|
26463
|
+
function Uz(e, t) {
|
|
26444
26464
|
return async (n, r) => {
|
|
26445
|
-
let i = await
|
|
26465
|
+
let i = await Wz(e, t, n, r);
|
|
26446
26466
|
return i ? i() : !1;
|
|
26447
26467
|
};
|
|
26448
26468
|
}
|
|
26449
|
-
async function
|
|
26469
|
+
async function Wz(e, n, r, i) {
|
|
26450
26470
|
let a = await n.users.get(r, i);
|
|
26451
26471
|
if (!a) return null;
|
|
26452
26472
|
let o = {
|
|
@@ -26466,7 +26486,7 @@ async function Vz(e, n, r, i) {
|
|
|
26466
26486
|
cancel: () => {
|
|
26467
26487
|
throw new k(400, { message: "User deletion cancelled by pre-deletion hook" });
|
|
26468
26488
|
},
|
|
26469
|
-
token:
|
|
26489
|
+
token: xz(e, r)
|
|
26470
26490
|
});
|
|
26471
26491
|
} catch (n) {
|
|
26472
26492
|
throw n instanceof t ? n : (O(e, r, {
|
|
@@ -26474,7 +26494,7 @@ async function Vz(e, n, r, i) {
|
|
|
26474
26494
|
description: `Pre user deletion hook failed: ${n instanceof Error ? n.message : String(n)}`
|
|
26475
26495
|
}), new k(400, { message: "Pre user deletion hook failed" }));
|
|
26476
26496
|
}
|
|
26477
|
-
await
|
|
26497
|
+
await Nz(e, r, "pre-user-deletion", {
|
|
26478
26498
|
user: iR(a),
|
|
26479
26499
|
user_id: i,
|
|
26480
26500
|
tenant: { id: r },
|
|
@@ -26515,7 +26535,7 @@ async function Vz(e, n, r, i) {
|
|
|
26515
26535
|
user_id: i,
|
|
26516
26536
|
request: o,
|
|
26517
26537
|
tenant: { id: r }
|
|
26518
|
-
}, { token:
|
|
26538
|
+
}, { token: xz(e, r) });
|
|
26519
26539
|
} catch (t) {
|
|
26520
26540
|
let n = t instanceof Error ? t.message : String(t), o = t instanceof Error ? t.stack : void 0, s = t instanceof Error ? t.name : void 0;
|
|
26521
26541
|
O(e, r, {
|
|
@@ -26539,28 +26559,28 @@ async function Vz(e, n, r, i) {
|
|
|
26539
26559
|
}
|
|
26540
26560
|
//#endregion
|
|
26541
26561
|
//#region src/hooks/addDataHooks.ts
|
|
26542
|
-
function
|
|
26543
|
-
let n = t, r =
|
|
26562
|
+
function Gz(e, t) {
|
|
26563
|
+
let n = t, r = Vz(e, n), i = Hz(e, n);
|
|
26544
26564
|
return {
|
|
26545
26565
|
...t,
|
|
26546
26566
|
users: {
|
|
26547
26567
|
...t.users,
|
|
26548
26568
|
create: (e, t) => r(e, Au(t)),
|
|
26549
26569
|
update: (e, t, n, r) => i(e, t, Au(n), r),
|
|
26550
|
-
remove:
|
|
26570
|
+
remove: Uz(e, n)
|
|
26551
26571
|
}
|
|
26552
26572
|
};
|
|
26553
26573
|
}
|
|
26554
26574
|
//#endregion
|
|
26555
26575
|
//#region src/helpers/login-version.ts
|
|
26556
|
-
function
|
|
26576
|
+
function Kz(e) {
|
|
26557
26577
|
let t = e.client_metadata?.universal_login_version;
|
|
26558
26578
|
return t === "2" ? "/u2" : t === "1" ? "/u" : e.tenant?.flags?.universal_login_version === "2" ? "/u2" : "/u";
|
|
26559
26579
|
}
|
|
26560
26580
|
//#endregion
|
|
26561
26581
|
//#region src/hooks/formhooks.ts
|
|
26562
|
-
var
|
|
26563
|
-
function
|
|
26582
|
+
var qz = new Set(["PASSWORD", "CODE"]), Jz = "form_values";
|
|
26583
|
+
function Yz(e) {
|
|
26564
26584
|
if (!e) return {};
|
|
26565
26585
|
try {
|
|
26566
26586
|
let t = JSON.parse(e);
|
|
@@ -26569,15 +26589,15 @@ function Kz(e) {
|
|
|
26569
26589
|
return {};
|
|
26570
26590
|
}
|
|
26571
26591
|
}
|
|
26572
|
-
function
|
|
26573
|
-
let t = e[
|
|
26592
|
+
function Xz(e) {
|
|
26593
|
+
let t = e[Jz];
|
|
26574
26594
|
if (!t || typeof t != "object" || Array.isArray(t)) return {};
|
|
26575
26595
|
let n = {};
|
|
26576
26596
|
for (let [e, r] of Object.entries(t)) typeof r == "string" && (n[e] = r);
|
|
26577
26597
|
return n;
|
|
26578
26598
|
}
|
|
26579
|
-
async function
|
|
26580
|
-
let a = await e.env.data.loginSessions.get(t, n), o =
|
|
26599
|
+
async function Zz(e, t, n, r, i) {
|
|
26600
|
+
let a = await e.env.data.loginSessions.get(t, n), o = Xz(Yz(a?.state_data)), s = {
|
|
26581
26601
|
...o,
|
|
26582
26602
|
...r
|
|
26583
26603
|
};
|
|
@@ -26585,7 +26605,7 @@ async function Jz(e, t, n, r, i) {
|
|
|
26585
26605
|
let c = { ...o };
|
|
26586
26606
|
for (let e of i) {
|
|
26587
26607
|
let t = r[e.id];
|
|
26588
|
-
t !== void 0 && (
|
|
26608
|
+
t !== void 0 && (qz.has(e.type) || e.sensitive !== !0 && (c[e.id] = t));
|
|
26589
26609
|
}
|
|
26590
26610
|
if (Object.keys(c).length === Object.keys(o).length) {
|
|
26591
26611
|
let e = !1;
|
|
@@ -26597,17 +26617,17 @@ async function Jz(e, t, n, r, i) {
|
|
|
26597
26617
|
}
|
|
26598
26618
|
return await TO(e.env.data.loginSessions, t, n, {
|
|
26599
26619
|
type: j.UPDATE_CONTEXT,
|
|
26600
|
-
data: { [
|
|
26620
|
+
data: { [Jz]: c }
|
|
26601
26621
|
}, {}), s;
|
|
26602
26622
|
}
|
|
26603
|
-
function
|
|
26623
|
+
function Qz(e) {
|
|
26604
26624
|
return typeof e.form_id == "string";
|
|
26605
26625
|
}
|
|
26606
|
-
function
|
|
26626
|
+
function $z(e, t) {
|
|
26607
26627
|
let n = e.match(/^\{\{context\.user\.(.+)\}\}$/);
|
|
26608
|
-
if (n && n[1]) return
|
|
26628
|
+
if (n && n[1]) return eB(t.user, n[1]);
|
|
26609
26629
|
let r = e.match(/^\{\{user\.(.+)\}\}$/);
|
|
26610
|
-
if (r && r[1]) return
|
|
26630
|
+
if (r && r[1]) return eB(t.user, r[1]);
|
|
26611
26631
|
let i = e.match(/^\{\{(?:fields|\$form)\.(.+)\}\}$/);
|
|
26612
26632
|
if (i && i[1] && t.submittedFields) {
|
|
26613
26633
|
let e = t.submittedFields[i[1]];
|
|
@@ -26615,23 +26635,23 @@ function Xz(e, t) {
|
|
|
26615
26635
|
}
|
|
26616
26636
|
return e;
|
|
26617
26637
|
}
|
|
26618
|
-
function
|
|
26638
|
+
function eB(e, t) {
|
|
26619
26639
|
let n = t.split("."), r = e;
|
|
26620
26640
|
for (let e of n) if (r && typeof r == "object" && e in r) r = r[e];
|
|
26621
26641
|
else return;
|
|
26622
26642
|
return typeof r == "string" ? r : r == null ? void 0 : String(r);
|
|
26623
26643
|
}
|
|
26624
|
-
function
|
|
26644
|
+
function tB(e, t) {
|
|
26625
26645
|
let n = {};
|
|
26626
26646
|
for (let [r, i] of Object.entries(e)) if (typeof i == "string") {
|
|
26627
|
-
let e =
|
|
26647
|
+
let e = $z(i, t);
|
|
26628
26648
|
e !== void 0 && (n[r] = e);
|
|
26629
26649
|
} else i != null && (n[r] = String(i));
|
|
26630
26650
|
return n;
|
|
26631
26651
|
}
|
|
26632
|
-
function
|
|
26633
|
-
let n = e.operator?.toLowerCase(), r = e.field ?? "", i = r ?
|
|
26634
|
-
r && i === r && !r.startsWith("{{") && (i =
|
|
26652
|
+
function nB(e, t) {
|
|
26653
|
+
let n = e.operator?.toLowerCase(), r = e.field ?? "", i = r ? $z(r, t) : "";
|
|
26654
|
+
r && i === r && !r.startsWith("{{") && (i = eB(t.user, r));
|
|
26635
26655
|
let a = e.value || "";
|
|
26636
26656
|
switch (n) {
|
|
26637
26657
|
case "exists": return i != null && i !== "";
|
|
@@ -26649,7 +26669,7 @@ function $z(e, t) {
|
|
|
26649
26669
|
for (let n of e.operands) if (n.operator === "ENDS_WITH" && Array.isArray(n.operands) && n.operands.length >= 2) {
|
|
26650
26670
|
let e = n.operands[0], r = n.operands[1];
|
|
26651
26671
|
if (e && r) {
|
|
26652
|
-
let n =
|
|
26672
|
+
let n = $z(`{{context.user.${e}}}`, t);
|
|
26653
26673
|
if (typeof n == "string" && n.endsWith(r)) return !0;
|
|
26654
26674
|
}
|
|
26655
26675
|
}
|
|
@@ -26657,10 +26677,10 @@ function $z(e, t) {
|
|
|
26657
26677
|
return !1;
|
|
26658
26678
|
}
|
|
26659
26679
|
}
|
|
26660
|
-
function
|
|
26661
|
-
return Array.isArray(e.conditions) ? e.conditions.every((e) =>
|
|
26680
|
+
function rB(e, t) {
|
|
26681
|
+
return Array.isArray(e.conditions) ? e.conditions.every((e) => nB(e, t)) : nB(e, t);
|
|
26662
26682
|
}
|
|
26663
|
-
function
|
|
26683
|
+
function iB(e, t) {
|
|
26664
26684
|
let n = {};
|
|
26665
26685
|
for (let [r, i] of Object.entries(e)) if (r.startsWith("user_metadata.") || r.startsWith("metadata.")) {
|
|
26666
26686
|
let e = r.startsWith("user_metadata.") ? r.slice(14) : r.slice(9);
|
|
@@ -26679,7 +26699,7 @@ function tB(e, t) {
|
|
|
26679
26699
|
} else n[r] = i;
|
|
26680
26700
|
return n;
|
|
26681
26701
|
}
|
|
26682
|
-
function
|
|
26702
|
+
function aB(e) {
|
|
26683
26703
|
let t = /* @__PURE__ */ new Map();
|
|
26684
26704
|
for (let n of e) {
|
|
26685
26705
|
let e = t.get(n.user_id);
|
|
@@ -26693,7 +26713,7 @@ function nB(e) {
|
|
|
26693
26713
|
}
|
|
26694
26714
|
return Array.from(t.values());
|
|
26695
26715
|
}
|
|
26696
|
-
function
|
|
26716
|
+
function oB(e, n, r) {
|
|
26697
26717
|
switch (e) {
|
|
26698
26718
|
case "change-email": return `/u2/account/change-email?state=${encodeURIComponent(r)}`;
|
|
26699
26719
|
case "account": return `/u2/account?state=${encodeURIComponent(r)}`;
|
|
@@ -26704,7 +26724,7 @@ function rB(e, n, r) {
|
|
|
26704
26724
|
default: throw new t(400, { message: `Unknown redirect target: ${e}` });
|
|
26705
26725
|
}
|
|
26706
26726
|
}
|
|
26707
|
-
async function
|
|
26727
|
+
async function sB(e, t, n, r, i = 10) {
|
|
26708
26728
|
let a = t, o = 0, s = [];
|
|
26709
26729
|
for (; o < i;) {
|
|
26710
26730
|
if (a === "$ending") return {
|
|
@@ -26731,7 +26751,7 @@ async function iB(e, t, n, r, i = 10) {
|
|
|
26731
26751
|
}
|
|
26732
26752
|
if (t.type === "ROUTER") {
|
|
26733
26753
|
let e = t, r = null;
|
|
26734
|
-
for (let t of e.config.rules) if (
|
|
26754
|
+
for (let t of e.config.rules) if (rB(t.condition, n)) {
|
|
26735
26755
|
r = t.next_node;
|
|
26736
26756
|
break;
|
|
26737
26757
|
}
|
|
@@ -26754,7 +26774,7 @@ async function iB(e, t, n, r, i = 10) {
|
|
|
26754
26774
|
};
|
|
26755
26775
|
}
|
|
26756
26776
|
if (e.type === "AUTH0" && e.action === "UPDATE_USER" && e.params) {
|
|
26757
|
-
let t = e.params.user_id &&
|
|
26777
|
+
let t = e.params.user_id && $z(e.params.user_id, n) || n.user.user_id, r = e.params.changes ? tB(e.params.changes, n) : {};
|
|
26758
26778
|
Object.keys(r).length > 0 && s.push({
|
|
26759
26779
|
user_id: t,
|
|
26760
26780
|
changes: r
|
|
@@ -26775,15 +26795,15 @@ async function iB(e, t, n, r, i = 10) {
|
|
|
26775
26795
|
}
|
|
26776
26796
|
return null;
|
|
26777
26797
|
}
|
|
26778
|
-
async function
|
|
26798
|
+
async function cB(e, n, r, i, a) {
|
|
26779
26799
|
let o = e.env.data, s = e.var.tenant_id || e.req.header("tenant-id");
|
|
26780
26800
|
if (!s) throw new t(400, { message: "Missing tenant_id in context" });
|
|
26781
|
-
let c = a ?
|
|
26801
|
+
let c = a ? Kz(a) : "/u", l = await o.forms.get(s, n);
|
|
26782
26802
|
if (!l) throw new t(404, { message: "Form not found for post-user-login hook" });
|
|
26783
26803
|
let u = l.start?.next_node;
|
|
26784
26804
|
if (!u && l.nodes && l.nodes.length > 0 && (u = l.nodes.find((e) => e.type === "STEP")?.id), !u) throw new t(400, { message: "No start node found in form" });
|
|
26785
26805
|
if (i && l.nodes) {
|
|
26786
|
-
let t = await
|
|
26806
|
+
let t = await sB(l.nodes, u, { user: i }, async (e) => {
|
|
26787
26807
|
let t = await o.flows.get(s, e);
|
|
26788
26808
|
return t ? { actions: t.actions?.map((e) => ({
|
|
26789
26809
|
type: e.type,
|
|
@@ -26792,19 +26812,19 @@ async function aB(e, n, r, i, a) {
|
|
|
26792
26812
|
})) } : null;
|
|
26793
26813
|
});
|
|
26794
26814
|
if (t && t.userUpdates && t.userUpdates.length > 0) {
|
|
26795
|
-
let e =
|
|
26815
|
+
let e = aB(t.userUpdates);
|
|
26796
26816
|
for (let t of e) {
|
|
26797
|
-
let e =
|
|
26817
|
+
let e = iB(t.changes, i);
|
|
26798
26818
|
await o.users.update(s, t.user_id, e);
|
|
26799
26819
|
}
|
|
26800
26820
|
}
|
|
26801
26821
|
if (!t || t.type === "end") return i;
|
|
26802
26822
|
if (t.type === "redirect") {
|
|
26803
|
-
let i = t.target, a =
|
|
26823
|
+
let i = t.target, a = oB(i, t.customUrl, r.id);
|
|
26804
26824
|
if (i === "change-email" || i === "account") {
|
|
26805
26825
|
let t = `${c}/continue?state=${encodeURIComponent(r.id)}`;
|
|
26806
|
-
await
|
|
26807
|
-
} else await
|
|
26826
|
+
await tH(e, s, r, [i], t);
|
|
26827
|
+
} else await QV(e, s, r, `form:${n}`);
|
|
26808
26828
|
return new Response(null, {
|
|
26809
26829
|
status: 302,
|
|
26810
26830
|
headers: { location: a }
|
|
@@ -26812,7 +26832,7 @@ async function aB(e, n, r, i, a) {
|
|
|
26812
26832
|
}
|
|
26813
26833
|
u = t.nodeId;
|
|
26814
26834
|
}
|
|
26815
|
-
await
|
|
26835
|
+
await QV(e, s, r, `form:${n}`);
|
|
26816
26836
|
let d = `${c}/forms/${l.id}/nodes/${u}?state=${encodeURIComponent(r.id)}`;
|
|
26817
26837
|
return new Response(null, {
|
|
26818
26838
|
status: 302,
|
|
@@ -26821,19 +26841,19 @@ async function aB(e, n, r, i, a) {
|
|
|
26821
26841
|
}
|
|
26822
26842
|
//#endregion
|
|
26823
26843
|
//#region src/hooks/pagehooks.ts
|
|
26824
|
-
function
|
|
26844
|
+
function lB(e) {
|
|
26825
26845
|
return typeof e.page_id == "string" && typeof e.enabled == "boolean";
|
|
26826
26846
|
}
|
|
26827
|
-
async function
|
|
26847
|
+
async function uB(e, n, r, i, a, o) {
|
|
26828
26848
|
let s = e.env.data, c = e.var.tenant_id || e.req.header("tenant-id");
|
|
26829
26849
|
if (!c) throw new t(400, { message: "Missing tenant_id in context" });
|
|
26830
26850
|
if (a && !(await s.userPermissions.list(c, i.user_id)).some((e) => e.permission_name === a)) return i;
|
|
26831
|
-
await
|
|
26851
|
+
await QV(e, c, r, `page:${n}`);
|
|
26832
26852
|
let l = "/u", u = o;
|
|
26833
26853
|
if (!u && r.authParams.client_id) try {
|
|
26834
26854
|
u = await rR(e.env, r.authParams.client_id, c);
|
|
26835
26855
|
} catch {}
|
|
26836
|
-
u && (l =
|
|
26856
|
+
u && (l = Kz(u));
|
|
26837
26857
|
let d = `${l}/${n}?state=${encodeURIComponent(r.id)}`;
|
|
26838
26858
|
return new Response(null, {
|
|
26839
26859
|
status: 302,
|
|
@@ -26842,7 +26862,7 @@ async function sB(e, n, r, i, a, o) {
|
|
|
26842
26862
|
}
|
|
26843
26863
|
//#endregion
|
|
26844
26864
|
//#region src/hooks/helpers/post-login-account-linking.ts
|
|
26845
|
-
function
|
|
26865
|
+
function dB(e) {
|
|
26846
26866
|
let { ctx: t, data: n, tenantId: r, candidates: i, externalConnections: a } = e, o = e.requireVerifiedEmail ?? !0, s = e.ensuredUserIds ?? /* @__PURE__ */ new Set(), c = e.user, l = null, u = (e, n, i) => {
|
|
26847
26867
|
O(t, r, {
|
|
26848
26868
|
type: E.FAILED_HOOK,
|
|
@@ -26898,7 +26918,7 @@ function cB(e) {
|
|
|
26898
26918
|
getLinkedPrimaryId: () => l
|
|
26899
26919
|
};
|
|
26900
26920
|
}
|
|
26901
|
-
function
|
|
26921
|
+
function fB(e) {
|
|
26902
26922
|
let t = (e.authentication?.methods ?? []).filter((e) => e.name === "mfa" && !Number.isNaN(Date.parse(e.timestamp)));
|
|
26903
26923
|
if (t.length === 0) return;
|
|
26904
26924
|
let n = t[0].timestamp;
|
|
@@ -26910,12 +26930,12 @@ function lB(e) {
|
|
|
26910
26930
|
types: r
|
|
26911
26931
|
};
|
|
26912
26932
|
}
|
|
26913
|
-
function
|
|
26933
|
+
function pB(e, t) {
|
|
26914
26934
|
if (e.revoked_at || e.user_id !== t) return !1;
|
|
26915
26935
|
let n = Date.now();
|
|
26916
|
-
return e.expires_at && Date.parse(e.expires_at) < n || e.idle_expires_at && Date.parse(e.idle_expires_at) < n ? !1 :
|
|
26936
|
+
return e.expires_at && Date.parse(e.expires_at) < n || e.idle_expires_at && Date.parse(e.idle_expires_at) < n ? !1 : fB(e) !== void 0;
|
|
26917
26937
|
}
|
|
26918
|
-
async function
|
|
26938
|
+
async function mB(e, t, n, r) {
|
|
26919
26939
|
let i = n.authentication?.methods ?? [];
|
|
26920
26940
|
if (i.some((e) => e.name === "mfa" && e.timestamp === r.timestamp)) return;
|
|
26921
26941
|
let a = {
|
|
@@ -26927,10 +26947,10 @@ async function dB(e, t, n, r) {
|
|
|
26927
26947
|
}
|
|
26928
26948
|
//#endregion
|
|
26929
26949
|
//#region src/hooks/post-user-login.ts
|
|
26930
|
-
function
|
|
26950
|
+
function hB(e) {
|
|
26931
26951
|
return typeof e.url == "string";
|
|
26932
26952
|
}
|
|
26933
|
-
async function
|
|
26953
|
+
async function gB(e, t, n, r, i, a) {
|
|
26934
26954
|
let o = [];
|
|
26935
26955
|
try {
|
|
26936
26956
|
o = (await t.userRoles.list(n, r.user_id, void 0, "")).map((e) => e.name || e.id);
|
|
@@ -27020,7 +27040,7 @@ async function pB(e, t, n, r, i, a) {
|
|
|
27020
27040
|
session_transfer_token: e.var?.session_transfer_token
|
|
27021
27041
|
};
|
|
27022
27042
|
}
|
|
27023
|
-
function
|
|
27043
|
+
function _B(e, t, n) {
|
|
27024
27044
|
let r = typeof t == "string" && t ? t : "any";
|
|
27025
27045
|
if (r === "none") return e;
|
|
27026
27046
|
let i = typeof n == "object" && !!n && "allowRememberBrowser" in n && n.allowRememberBrowser === !0;
|
|
@@ -27029,7 +27049,7 @@ function mB(e, t, n) {
|
|
|
27029
27049
|
allow_remember_browser: e ? e.allow_remember_browser && i : i
|
|
27030
27050
|
};
|
|
27031
27051
|
}
|
|
27032
|
-
function
|
|
27052
|
+
function vB(e) {
|
|
27033
27053
|
try {
|
|
27034
27054
|
let t = JSON.parse(e.message);
|
|
27035
27055
|
if (typeof t == "object" && t) {
|
|
@@ -27039,7 +27059,7 @@ function hB(e) {
|
|
|
27039
27059
|
} catch {}
|
|
27040
27060
|
return e.message || "access_denied";
|
|
27041
27061
|
}
|
|
27042
|
-
async function
|
|
27062
|
+
async function yB(e, t, n, r) {
|
|
27043
27063
|
if (e.set("post_login_action_claims", r), !n) return;
|
|
27044
27064
|
let i = !!(r.access_token || r.id_token), a = Fm(n.state_data).action_claims;
|
|
27045
27065
|
if (!(!i && !a)) try {
|
|
@@ -27052,10 +27072,10 @@ async function gB(e, t, n, r) {
|
|
|
27052
27072
|
console.warn("Post-login action claims not stored:", e.message);
|
|
27053
27073
|
}
|
|
27054
27074
|
}
|
|
27055
|
-
async function
|
|
27075
|
+
async function bB(e, t, n, r, i) {
|
|
27056
27076
|
if (n) {
|
|
27057
27077
|
let r = await e.env.data.sessions.get(t, n);
|
|
27058
|
-
if (r &&
|
|
27078
|
+
if (r && pB(r, i.user_id)) return !0;
|
|
27059
27079
|
}
|
|
27060
27080
|
let a = await e.env.data.tenants.get(t);
|
|
27061
27081
|
if (a) {
|
|
@@ -27068,23 +27088,23 @@ async function _B(e, t, n, r, i) {
|
|
|
27068
27088
|
}
|
|
27069
27089
|
return !1;
|
|
27070
27090
|
}
|
|
27071
|
-
async function
|
|
27091
|
+
async function xB(e, t, n, r, i) {
|
|
27072
27092
|
i = await Uu(e.env.data.users, t, await e.env.data.users.get(t, i.user_id) ?? i), await TO(e.env.data.loginSessions, t, n.id, {
|
|
27073
27093
|
type: j.UPDATE_CONTEXT,
|
|
27074
27094
|
data: { mfa_required_by_action: r }
|
|
27075
27095
|
}, { user_id: i.user_id });
|
|
27076
27096
|
let a = await e.env.data.loginSessions.get(t, n.id);
|
|
27077
|
-
if (!a || a.state !== T.AUTHENTICATED || Fm(a.state_data).mfa_verified || await
|
|
27097
|
+
if (!a || a.state !== T.AUTHENTICATED || Fm(a.state_data).mfa_verified || await bB(e, t, a.session_id, r, i)) return;
|
|
27078
27098
|
let o = `/u2/continue?state=${encodeURIComponent(n.id)}`;
|
|
27079
|
-
return await
|
|
27099
|
+
return await tH(e, t, a, [], o), new Response(null, {
|
|
27080
27100
|
status: 302,
|
|
27081
27101
|
headers: { location: o }
|
|
27082
27102
|
});
|
|
27083
27103
|
}
|
|
27084
|
-
async function
|
|
27085
|
-
return
|
|
27104
|
+
async function SB(e, t, n, r, i, a) {
|
|
27105
|
+
return wB(e, t, n, r, i, a);
|
|
27086
27106
|
}
|
|
27087
|
-
async function
|
|
27107
|
+
async function CB(e, t, n, r, i, a) {
|
|
27088
27108
|
if (!e.env.hooks?.onExecutePostLogin) {
|
|
27089
27109
|
let { hooks: e } = await t.hooks.list(n);
|
|
27090
27110
|
if (!e.some((e) => e.trigger_id === "post-user-login" && e.enabled && TR(e))) return {
|
|
@@ -27094,7 +27114,7 @@ async function bB(e, t, n, r, i, a) {
|
|
|
27094
27114
|
}
|
|
27095
27115
|
let o = {}, s;
|
|
27096
27116
|
try {
|
|
27097
|
-
s = await
|
|
27117
|
+
s = await wB(e, t, n, r, i, a, o);
|
|
27098
27118
|
} catch (e) {
|
|
27099
27119
|
if (o.deniedReason !== void 0) return {
|
|
27100
27120
|
status: "access_denied",
|
|
@@ -27112,7 +27132,7 @@ async function bB(e, t, n, r, i, a) {
|
|
|
27112
27132
|
};
|
|
27113
27133
|
if (o.mfaRequest) {
|
|
27114
27134
|
let r = await Uu(t.users, n, await t.users.get(n, s.user_id) ?? s);
|
|
27115
|
-
if (!await
|
|
27135
|
+
if (!await bB(e, n, i.session_id, o.mfaRequest, r)) return {
|
|
27116
27136
|
status: "interaction_required",
|
|
27117
27137
|
description: "Multi-factor authentication required"
|
|
27118
27138
|
};
|
|
@@ -27122,7 +27142,7 @@ async function bB(e, t, n, r, i, a) {
|
|
|
27122
27142
|
user: s
|
|
27123
27143
|
};
|
|
27124
27144
|
}
|
|
27125
|
-
async function
|
|
27145
|
+
async function wB(e, n, r, i, a, o, s) {
|
|
27126
27146
|
let c = o?.authStrategy?.strategy_type ? o.authStrategy.strategy_type : i.is_social ? qo.SOCIAL : qo.DATABASE, l = o?.authStrategy?.strategy || i.connection || "", u = qc({
|
|
27127
27147
|
loginSession: a,
|
|
27128
27148
|
authConnection: o?.authConnection,
|
|
@@ -27140,7 +27160,7 @@ async function xB(e, n, r, i, a, o, s) {
|
|
|
27140
27160
|
last_ip: l,
|
|
27141
27161
|
login_count: d
|
|
27142
27162
|
})));
|
|
27143
|
-
let h = o?.client && o?.authParams && a ? await
|
|
27163
|
+
let h = o?.client && o?.authParams && a ? await gB(e, n, r, i, a, {
|
|
27144
27164
|
client: o.client,
|
|
27145
27165
|
authParams: o.authParams,
|
|
27146
27166
|
authStrategy: o.authStrategy,
|
|
@@ -27152,7 +27172,7 @@ async function xB(e, n, r, i, a, o, s) {
|
|
|
27152
27172
|
await e.env.hooks.onExecutePostLogin(h, {
|
|
27153
27173
|
prompt: { render: (e) => {} },
|
|
27154
27174
|
multifactor: { enable: (e, t) => {
|
|
27155
|
-
p =
|
|
27175
|
+
p = _B(p, e, t);
|
|
27156
27176
|
} },
|
|
27157
27177
|
redirect: {
|
|
27158
27178
|
sendUserTo: (t, n) => {
|
|
@@ -27168,7 +27188,7 @@ async function xB(e, n, r, i, a, o, s) {
|
|
|
27168
27188
|
throw Error("redirect.validateToken is not implemented");
|
|
27169
27189
|
}
|
|
27170
27190
|
},
|
|
27171
|
-
token:
|
|
27191
|
+
token: xz(e, r)
|
|
27172
27192
|
});
|
|
27173
27193
|
} catch (e) {
|
|
27174
27194
|
l = e;
|
|
@@ -27185,19 +27205,19 @@ async function xB(e, n, r, i, a, o, s) {
|
|
|
27185
27205
|
},
|
|
27186
27206
|
logs: [],
|
|
27187
27207
|
denied: !1
|
|
27188
|
-
}), l) throw s && l instanceof t && l.status >= 400 && l.status < 500 && (s.deniedReason =
|
|
27208
|
+
}), l) throw s && l instanceof t && l.status >= 400 && l.status < 500 && (s.deniedReason = vB(l)), l;
|
|
27189
27209
|
if (p && !s && await TO(n.loginSessions, r, a.id, {
|
|
27190
27210
|
type: j.UPDATE_CONTEXT,
|
|
27191
27211
|
data: { mfa_required_by_action: p }
|
|
27192
27212
|
}), o && s) return s.interactionRequired = "A post-login action requires a redirect to complete the login", i;
|
|
27193
|
-
if (o) return await
|
|
27213
|
+
if (o) return await QV(e, r, a, "onExecutePostLogin"), new Response(null, {
|
|
27194
27214
|
status: 302,
|
|
27195
27215
|
headers: { location: o }
|
|
27196
27216
|
});
|
|
27197
27217
|
}
|
|
27198
|
-
let { hooks: g } = await n.hooks.list(r), _ = g.filter((e) => e.trigger_id === "post-user-login"), v = s ? [] : _.filter((e) => e.enabled &&
|
|
27199
|
-
for (let t of v) if (
|
|
27200
|
-
i = await
|
|
27218
|
+
let { hooks: g } = await n.hooks.list(r), _ = g.filter((e) => e.trigger_id === "post-user-login"), v = s ? [] : _.filter((e) => e.enabled && gz(e));
|
|
27219
|
+
for (let t of v) if (gz(t)) try {
|
|
27220
|
+
i = await yz(e, t.template_id, i, t.metadata);
|
|
27201
27221
|
} catch (n) {
|
|
27202
27222
|
let i = n instanceof Error ? n.message : String(n);
|
|
27203
27223
|
O(e, r, {
|
|
@@ -27211,33 +27231,33 @@ async function xB(e, n, r, i, a, o, s) {
|
|
|
27211
27231
|
});
|
|
27212
27232
|
}
|
|
27213
27233
|
if (i = await Uu(n.users, r, i), a && !s) {
|
|
27214
|
-
let t = _.find((e) => e.enabled &&
|
|
27215
|
-
if (t &&
|
|
27216
|
-
let n = await
|
|
27234
|
+
let t = _.find((e) => e.enabled && Qz(e));
|
|
27235
|
+
if (t && Qz(t)) {
|
|
27236
|
+
let n = await cB(e, t.form_id, a, i, o?.client);
|
|
27217
27237
|
if (n instanceof Response) return n;
|
|
27218
27238
|
i = n;
|
|
27219
27239
|
}
|
|
27220
|
-
let n = o?.sessionReused ? void 0 : _.find((e) => e.enabled &&
|
|
27221
|
-
if (n &&
|
|
27222
|
-
let t = await
|
|
27240
|
+
let n = o?.sessionReused ? void 0 : _.find((e) => e.enabled && lB(e));
|
|
27241
|
+
if (n && lB(n)) {
|
|
27242
|
+
let t = await uB(e, n.page_id, a, i, n.permission_required, o?.client);
|
|
27223
27243
|
if (t instanceof Response) return t;
|
|
27224
27244
|
i = t;
|
|
27225
27245
|
}
|
|
27226
27246
|
}
|
|
27227
27247
|
let y = _.filter((e) => e.enabled && TR(e));
|
|
27228
27248
|
if (h && y.length > 0) {
|
|
27229
|
-
let o = y.some((e) => e.metadata?.resolve_link_candidates === !0), c = o ? await
|
|
27249
|
+
let o = y.some((e) => e.metadata?.resolve_link_candidates === !0), c = o ? await lz({
|
|
27230
27250
|
userAdapter: n.users,
|
|
27231
27251
|
connectionAdapter: n.connections,
|
|
27232
27252
|
tenantId: r,
|
|
27233
27253
|
user: i
|
|
27234
|
-
}) : [], l = o ?
|
|
27254
|
+
}) : [], l = o ? uz(c) : [], u = kz(n, r, Object.keys(e.env.STRATEGIES ?? {})), d = Az({
|
|
27235
27255
|
ctx: e,
|
|
27236
27256
|
data: n,
|
|
27237
27257
|
tenantId: r,
|
|
27238
27258
|
triggerId: "post-user-login",
|
|
27239
27259
|
externalConnections: u
|
|
27240
|
-
}), g =
|
|
27260
|
+
}), g = dB({
|
|
27241
27261
|
ctx: e,
|
|
27242
27262
|
data: n,
|
|
27243
27263
|
tenantId: r,
|
|
@@ -27253,7 +27273,7 @@ async function xB(e, n, r, i, a, o, s) {
|
|
|
27253
27273
|
...g.api,
|
|
27254
27274
|
...d.api,
|
|
27255
27275
|
multifactor: { enable: (e, t) => {
|
|
27256
|
-
p =
|
|
27276
|
+
p = _B(p, e, t);
|
|
27257
27277
|
} },
|
|
27258
27278
|
accessToken: { setCustomClaim: S(_) },
|
|
27259
27279
|
idToken: { setCustomClaim: S(v) },
|
|
@@ -27267,7 +27287,7 @@ async function xB(e, n, r, i, a, o, s) {
|
|
|
27267
27287
|
prompt: { render: x("prompt.render") }
|
|
27268
27288
|
}, te = async (t, n) => {
|
|
27269
27289
|
if (m = t, s && (s.deniedReason = t), a) try {
|
|
27270
|
-
await
|
|
27290
|
+
await ZV(e, r, a, `post_login_denied: ${t}`);
|
|
27271
27291
|
} catch (e) {
|
|
27272
27292
|
console.warn("Failed to mark denied login session:", e);
|
|
27273
27293
|
}
|
|
@@ -27284,7 +27304,7 @@ async function xB(e, n, r, i, a, o, s) {
|
|
|
27284
27304
|
try {
|
|
27285
27305
|
c = await FR(e, n, a, s, "post-user-login", ee), !c && o && (c = NR(a.code_id));
|
|
27286
27306
|
} catch (e) {
|
|
27287
|
-
e instanceof t && (f.push(MR(a.code_id, e, !0)), await te(
|
|
27307
|
+
e instanceof t && (f.push(MR(a.code_id, e, !0)), await te(vB(e), e)), c = MR(a.code_id, e);
|
|
27288
27308
|
}
|
|
27289
27309
|
if (c) {
|
|
27290
27310
|
if (f.push(c), b.length > 0 && !c.result.error) {
|
|
@@ -27309,20 +27329,20 @@ async function xB(e, n, r, i, a, o, s) {
|
|
|
27309
27329
|
let e = await n.users.get(r, re);
|
|
27310
27330
|
e && (i = e);
|
|
27311
27331
|
}
|
|
27312
|
-
await
|
|
27332
|
+
await yB(e, r, a, {
|
|
27313
27333
|
user_id: i.user_id,
|
|
27314
27334
|
...Object.keys(_).length ? { access_token: _ } : {},
|
|
27315
27335
|
...Object.keys(v).length ? { id_token: v } : {}
|
|
27316
27336
|
});
|
|
27317
27337
|
}
|
|
27318
|
-
if (await bR(e, s ? [] : _.filter((e) => e.enabled &&
|
|
27338
|
+
if (await bR(e, s ? [] : _.filter((e) => e.enabled && hB(e)), {
|
|
27319
27339
|
tenant_id: r,
|
|
27320
27340
|
user: i,
|
|
27321
27341
|
trigger_id: "post-user-login",
|
|
27322
27342
|
request: { url: a?.authorization_url || ul(e.req.url) }
|
|
27323
27343
|
}), p && s) s.mfaRequest = p;
|
|
27324
27344
|
else if (p && a) {
|
|
27325
|
-
let t = await
|
|
27345
|
+
let t = await xB(e, r, a, p, i);
|
|
27326
27346
|
if (t) return t;
|
|
27327
27347
|
}
|
|
27328
27348
|
return i;
|
|
@@ -27358,7 +27378,7 @@ async function xB(e, n, r, i, a, o, s) {
|
|
|
27358
27378
|
}
|
|
27359
27379
|
//#endregion
|
|
27360
27380
|
//#region src/utils/authIframe.ts
|
|
27361
|
-
function
|
|
27381
|
+
function TB(e, t, n, r) {
|
|
27362
27382
|
let i = new Headers(r);
|
|
27363
27383
|
i.set("Server-Timing", "cf-nel=0; no-cloudflare-insights=1");
|
|
27364
27384
|
let a = `<!DOCTYPE html>
|
|
@@ -27418,18 +27438,18 @@ function SB(e, t, n, r) {
|
|
|
27418
27438
|
}
|
|
27419
27439
|
//#endregion
|
|
27420
27440
|
//#region src/utils/form-post.ts
|
|
27421
|
-
var
|
|
27441
|
+
var EB = {
|
|
27422
27442
|
"&": "&",
|
|
27423
27443
|
"<": "<",
|
|
27424
27444
|
">": ">",
|
|
27425
27445
|
"\"": """,
|
|
27426
27446
|
"'": "'"
|
|
27427
27447
|
};
|
|
27428
|
-
function
|
|
27429
|
-
return e.replace(/[&<>"']/g, (e) =>
|
|
27448
|
+
function DB(e) {
|
|
27449
|
+
return e.replace(/[&<>"']/g, (e) => EB[e] ?? e);
|
|
27430
27450
|
}
|
|
27431
|
-
function
|
|
27432
|
-
let r = Object.entries(t).map(([e, t]) => `<input type="hidden" name="${
|
|
27451
|
+
function OB(e, t, n) {
|
|
27452
|
+
let r = Object.entries(t).map(([e, t]) => `<input type="hidden" name="${DB(e)}" value="${DB(t)}" />`).join("\n "), i = `<!DOCTYPE html>
|
|
27433
27453
|
<html>
|
|
27434
27454
|
<head><title>Submit This Form</title></head>
|
|
27435
27455
|
<body onload="document.forms[0].submit()">
|
|
@@ -27437,7 +27457,7 @@ function TB(e, t, n) {
|
|
|
27437
27457
|
<p>JavaScript is disabled. Click the button to continue.</p>
|
|
27438
27458
|
<button type="submit" form="formpost">Continue</button>
|
|
27439
27459
|
</noscript>
|
|
27440
|
-
<form id="formpost" method="post" action="${
|
|
27460
|
+
<form id="formpost" method="post" action="${DB(e)}">
|
|
27441
27461
|
${r}
|
|
27442
27462
|
</form>
|
|
27443
27463
|
</body>
|
|
@@ -27449,12 +27469,12 @@ function TB(e, t, n) {
|
|
|
27449
27469
|
}
|
|
27450
27470
|
//#endregion
|
|
27451
27471
|
//#region src/utils/auth-header.ts
|
|
27452
|
-
function
|
|
27472
|
+
function kB(e) {
|
|
27453
27473
|
if (!e) return;
|
|
27454
27474
|
let [t, n] = e.split(" ");
|
|
27455
27475
|
if (!(!t || t.toLowerCase() !== "bearer")) return n?.trim() || void 0;
|
|
27456
27476
|
}
|
|
27457
|
-
function
|
|
27477
|
+
function AB(e) {
|
|
27458
27478
|
if (!e) return {};
|
|
27459
27479
|
let [t, n] = e.split(" ");
|
|
27460
27480
|
if (t?.toLowerCase() !== "basic" || !n) return {};
|
|
@@ -27470,29 +27490,29 @@ function DB(e) {
|
|
|
27470
27490
|
}
|
|
27471
27491
|
//#endregion
|
|
27472
27492
|
//#region src/middlewares/authentication.ts
|
|
27473
|
-
var
|
|
27474
|
-
function
|
|
27493
|
+
var jB = "urn:authhero:management";
|
|
27494
|
+
function MB(e) {
|
|
27475
27495
|
return e === "/tenants" ? !0 : !e.startsWith("/tenants/") || /^\/tenants\/[^/]+\/(operations|config-sync)(\/|$)/.test(e) ? !1 : e !== "/tenants/settings" && !e.startsWith("/tenants/settings/");
|
|
27476
27496
|
}
|
|
27477
|
-
function
|
|
27497
|
+
function NB(e) {
|
|
27478
27498
|
return e.replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g, "{$1}");
|
|
27479
27499
|
}
|
|
27480
|
-
function
|
|
27500
|
+
function PB(e) {
|
|
27481
27501
|
let t = e.split(":");
|
|
27482
27502
|
if (t.length !== 2 || !t[0] || !t[1]) return [e];
|
|
27483
27503
|
let n = `${t[1]}:${t[0]}`;
|
|
27484
27504
|
return n === e ? [e] : [e, n];
|
|
27485
27505
|
}
|
|
27486
|
-
function
|
|
27506
|
+
function FB(e, n = {}) {
|
|
27487
27507
|
let i = n.requireManagementAudience ?? !1, a = n.relaxManagementAudience ?? !1, o = n.additionalManagementAudiences, s = n.additionalIssuers;
|
|
27488
27508
|
return async (n, c) => {
|
|
27489
27509
|
let l = n.req.method === "HEAD" ? "GET" : n.req.method, u = n.req.matchedRoutes.find((e) => e.method.toUpperCase() === l && e.path !== "/*");
|
|
27490
27510
|
if (!u) return await c();
|
|
27491
|
-
let d =
|
|
27511
|
+
let d = NB(u.path), f = d.startsWith("/api/v2") ? d.slice(7) || "/" : d, p = e.openAPIRegistry.definitions.find((e) => "route" in e && e.route.path === f && e.route.method.toUpperCase() === l.toUpperCase());
|
|
27492
27512
|
if (p && "route" in p) {
|
|
27493
27513
|
let e = p.route.security?.[0]?.Bearer;
|
|
27494
27514
|
if (e === void 0) return await c();
|
|
27495
|
-
let l =
|
|
27515
|
+
let l = kB(n.req.header("authorization"));
|
|
27496
27516
|
if (!l) throw Il.missingAuthentication();
|
|
27497
27517
|
try {
|
|
27498
27518
|
let c;
|
|
@@ -27502,7 +27522,7 @@ function MB(e, n = {}) {
|
|
|
27502
27522
|
}
|
|
27503
27523
|
let u = await rO(n, l, { additionalIssuers: c });
|
|
27504
27524
|
if (n.set("user_id", u.sub), n.set("user", u), u.azp && (n.set("client_id", u.azp), n.set("client_id_from_token", !0)), u.org_name && n.set("org_name", u.org_name), u.org_id && n.set("organization_id", u.org_id), !n.var.tenant_id && u.tenant_id && n.set("tenant_id", u.tenant_id), i) {
|
|
27505
|
-
let e = u.aud, r = Array.isArray(e) ? e : e ? [e] : [], i = typeof u.tenant_id == "string" ? u.tenant_id : void 0, s = o ? await o({ tenant_id: i }) : [], c = new Set([
|
|
27525
|
+
let e = u.aud, r = Array.isArray(e) ? e : e ? [e] : [], i = typeof u.tenant_id == "string" ? u.tenant_id : void 0, s = o ? await o({ tenant_id: i }) : [], c = new Set([jB, ...s]);
|
|
27506
27526
|
if (!r.some((e) => c.has(e))) if (a) console.warn(`[authhero] management API accepted token without management audience (relaxManagementAudience=true): sub=${u.sub ?? "unknown"} aud=${JSON.stringify(e)}`);
|
|
27507
27527
|
else throw new k(403, { message: "Invalid audience" });
|
|
27508
27528
|
let l = typeof u.tenant_id == "string" ? u.tenant_id : void 0, d = n.var.tenant_id;
|
|
@@ -27523,13 +27543,13 @@ function MB(e, n = {}) {
|
|
|
27523
27543
|
message: "Failed to look up organization",
|
|
27524
27544
|
cause: e
|
|
27525
27545
|
});
|
|
27526
|
-
}))?.name, r = !!e && e.toLowerCase() === d.toLowerCase(), i = d === p &&
|
|
27546
|
+
}))?.name, r = !!e && e.toLowerCase() === d.toLowerCase(), i = d === p && MB(f);
|
|
27527
27547
|
if (i && e && !n.var.org_name && n.set("org_name", e), !r && (!i || !e)) throw new k(403, { message: e ? `This token is for another tenant's organization ("${e}"), not "${d}"` : "An organization token must belong to a tenant's organization" });
|
|
27528
27548
|
}
|
|
27529
27549
|
}
|
|
27530
27550
|
let d = Array.isArray(u.permissions) ? u.permissions : [], p = typeof u.scope == "string" ? u.scope.split(" ") : Array.isArray(u.scope) ? u.scope : [];
|
|
27531
27551
|
if (e.length) {
|
|
27532
|
-
let t = e.flatMap(
|
|
27552
|
+
let t = e.flatMap(PB);
|
|
27533
27553
|
if (!(t.some((e) => d.includes(e)) || t.some((e) => p.includes(e)))) throw Il.insufficientScope(e);
|
|
27534
27554
|
}
|
|
27535
27555
|
} catch (e) {
|
|
@@ -27541,14 +27561,14 @@ function MB(e, n = {}) {
|
|
|
27541
27561
|
}
|
|
27542
27562
|
//#endregion
|
|
27543
27563
|
//#region src/helpers/management-audience.ts
|
|
27544
|
-
async function
|
|
27564
|
+
async function IB(e, t, n) {
|
|
27545
27565
|
if (n === "urn:authhero:management") return !0;
|
|
27546
27566
|
let r = e.env.additionalManagementAudiences;
|
|
27547
27567
|
return r ? (await r({ tenant_id: t })).includes(n) : !1;
|
|
27548
27568
|
}
|
|
27549
27569
|
//#endregion
|
|
27550
27570
|
//#region src/helpers/scopes-permissions.ts
|
|
27551
|
-
var
|
|
27571
|
+
var LB = [
|
|
27552
27572
|
"openid",
|
|
27553
27573
|
"profile",
|
|
27554
27574
|
"email",
|
|
@@ -27556,7 +27576,7 @@ var PB = [
|
|
|
27556
27576
|
"phone",
|
|
27557
27577
|
"offline_access"
|
|
27558
27578
|
];
|
|
27559
|
-
async function
|
|
27579
|
+
async function RB(e, t, n, r) {
|
|
27560
27580
|
let i = [];
|
|
27561
27581
|
if (!(await e.env.data.tenants.get(t))?.flags?.inherit_global_permissions_in_organizations) return [];
|
|
27562
27582
|
let a = await e.env.data.userRoles.list(t, n, void 0, ""), o = await Promise.all(a.map((n) => e.env.data.rolePermissions.list(t, n.id, { per_page: 1e3 })));
|
|
@@ -27565,8 +27585,8 @@ async function FB(e, t, n, r) {
|
|
|
27565
27585
|
});
|
|
27566
27586
|
return [...new Set(i)];
|
|
27567
27587
|
}
|
|
27568
|
-
var
|
|
27569
|
-
async function
|
|
27588
|
+
var zB = "admin:organizations", BB = "access:all_organizations";
|
|
27589
|
+
async function VB(e, t, n, r) {
|
|
27570
27590
|
let i = /* @__PURE__ */ new Set(), a = (e) => {
|
|
27571
27591
|
for (let t of e) t.resource_server_identifier === "urn:authhero:management" && r.includes(t.permission_name) && i.add(t.permission_name);
|
|
27572
27592
|
};
|
|
@@ -27575,26 +27595,26 @@ async function RB(e, t, n, r) {
|
|
|
27575
27595
|
for (let n of o) if (a(await e.env.data.rolePermissions.list(t, n.id, { per_page: 1e3 })), i.size === r.length) break;
|
|
27576
27596
|
return i;
|
|
27577
27597
|
}
|
|
27578
|
-
async function
|
|
27579
|
-
return (await
|
|
27598
|
+
async function HB(e, t, n, r) {
|
|
27599
|
+
return (await VB(e, t, n, [r])).has(r);
|
|
27580
27600
|
}
|
|
27581
|
-
async function
|
|
27582
|
-
let i = (r === void 0 ? await e.env.data.tenants.get(t) : r)?.flags?.inherit_global_permissions_in_organizations === !0, a = await
|
|
27601
|
+
async function UB(e, t, n, r) {
|
|
27602
|
+
let i = (r === void 0 ? await e.env.data.tenants.get(t) : r)?.flags?.inherit_global_permissions_in_organizations === !0, a = await VB(e, t, n, i ? [BB, zB] : [BB]);
|
|
27583
27603
|
return a.has("access:all_organizations") || i && a.has("admin:organizations");
|
|
27584
27604
|
}
|
|
27585
|
-
async function
|
|
27586
|
-
return await
|
|
27605
|
+
async function WB(e, t, n, r, i) {
|
|
27606
|
+
return await UB(e, t, n, i) ? !0 : (await e.env.data.userOrganizations.list(t, {
|
|
27587
27607
|
q: `user_id:${D(n)}`,
|
|
27588
27608
|
per_page: 1e3
|
|
27589
27609
|
})).userOrganizations.some((e) => e.organization_id === r);
|
|
27590
27610
|
}
|
|
27591
|
-
function
|
|
27611
|
+
function GB(e) {
|
|
27592
27612
|
let t = e.granted.filter((t) => !e.definedScopes.includes(t));
|
|
27593
27613
|
if (t.length === 0) return;
|
|
27594
27614
|
let n = e.userId ? `, user_id=${e.userId}` : "";
|
|
27595
27615
|
console.warn(`[scopes-permissions] Dropped scope(s) not defined on the resource server: ${t.join(", ")} (source=${e.source}, tenant_id=${e.tenantId}, client_id=${e.clientId}, audience=${e.audience}${n})`);
|
|
27596
27616
|
}
|
|
27597
|
-
async function
|
|
27617
|
+
async function KB(e, t) {
|
|
27598
27618
|
let { tenantId: n, audience: r, scopes: i } = t;
|
|
27599
27619
|
if (i.length === 0) return [];
|
|
27600
27620
|
let { resource_servers: a } = await e.env.data.resourceServers.list(n), o = a.find((e) => e.identifier === r);
|
|
@@ -27602,8 +27622,8 @@ async function UB(e, t) {
|
|
|
27602
27622
|
let s = (o.scopes || []).map((e) => e.value);
|
|
27603
27623
|
return i.filter((e) => !s.includes(e));
|
|
27604
27624
|
}
|
|
27605
|
-
async function
|
|
27606
|
-
let { tenantId: n, clientId: r, audience: i, requestedScopes: a } = t, o = a.filter((e) =>
|
|
27625
|
+
async function qB(e, t) {
|
|
27626
|
+
let { tenantId: n, clientId: r, audience: i, requestedScopes: a } = t, o = a.filter((e) => LB.includes(e)), s = a.filter((e) => !LB.includes(e)), c = (await e.env.data.resourceServers.list(n)).resource_servers.filter((e) => e.identifier === i);
|
|
27607
27627
|
if (c.length === 0) return {
|
|
27608
27628
|
scopes: o,
|
|
27609
27629
|
permissions: [],
|
|
@@ -27633,7 +27653,7 @@ async function WB(e, t) {
|
|
|
27633
27653
|
});
|
|
27634
27654
|
}
|
|
27635
27655
|
let h = p.filter((e) => m.includes(e));
|
|
27636
|
-
|
|
27656
|
+
GB({
|
|
27637
27657
|
source: "client_grant",
|
|
27638
27658
|
tenantId: n,
|
|
27639
27659
|
clientId: r,
|
|
@@ -27661,21 +27681,21 @@ async function WB(e, t) {
|
|
|
27661
27681
|
..._
|
|
27662
27682
|
};
|
|
27663
27683
|
}
|
|
27664
|
-
async function
|
|
27665
|
-
if (t.grantType === Gi.ClientCredential) return await
|
|
27684
|
+
async function JB(e, t) {
|
|
27685
|
+
if (t.grantType === Gi.ClientCredential) return await qB(e, {
|
|
27666
27686
|
tenantId: t.tenantId,
|
|
27667
27687
|
clientId: t.clientId,
|
|
27668
27688
|
audience: t.audience,
|
|
27669
27689
|
requestedScopes: t.requestedScopes
|
|
27670
27690
|
});
|
|
27671
27691
|
let { tenantId: n, clientId: r, userId: i, audience: a, requestedScopes: o, organizationId: s } = t, c = await e.env.data.tenants.get(n), l = c?.flags?.restrict_undefined_scopes === !0;
|
|
27672
|
-
if (s && !await
|
|
27692
|
+
if (s && !await WB(e, n, i, s, c)) throw new k(403, {
|
|
27673
27693
|
error: "access_denied",
|
|
27674
27694
|
error_description: "User is not a member of the specified organization"
|
|
27675
27695
|
});
|
|
27676
|
-
let u = o.filter((e) =>
|
|
27696
|
+
let u = o.filter((e) => LB.includes(e)), d = (await e.env.data.resourceServers.list(n)).resource_servers.filter((e) => e.identifier === a)[0];
|
|
27677
27697
|
if (!d) {
|
|
27678
|
-
if (o.filter((e) => e && !
|
|
27698
|
+
if (o.filter((e) => e && !LB.includes(e)).length > 0) throw new k(403, {
|
|
27679
27699
|
error: "access_denied",
|
|
27680
27700
|
error_description: `Service not found: ${a}`
|
|
27681
27701
|
});
|
|
@@ -27686,12 +27706,12 @@ async function GB(e, t) {
|
|
|
27686
27706
|
token_lifetime_for_web: 7200
|
|
27687
27707
|
};
|
|
27688
27708
|
}
|
|
27689
|
-
let f = (d.scopes || []).map((e) => e.value), p = await
|
|
27709
|
+
let f = (d.scopes || []).map((e) => e.value), p = await IB(e, n, a), m = d.options?.enforce_policies === !0 || p, h = d.options?.token_dialect || "access_token", g = {
|
|
27690
27710
|
token_lifetime: d.token_lifetime,
|
|
27691
27711
|
token_lifetime_for_web: d.token_lifetime_for_web
|
|
27692
27712
|
};
|
|
27693
27713
|
if (!m) {
|
|
27694
|
-
let e = l ? o.filter((e) => f.includes(e) ||
|
|
27714
|
+
let e = l ? o.filter((e) => f.includes(e) || LB.includes(e)) : o;
|
|
27695
27715
|
return {
|
|
27696
27716
|
scopes: [...new Set(e)],
|
|
27697
27717
|
permissions: [],
|
|
@@ -27702,7 +27722,7 @@ async function GB(e, t) {
|
|
|
27702
27722
|
e.env.data.userPermissions.list(n, i, void 0, s),
|
|
27703
27723
|
e.env.data.userRoles.list(n, i, void 0, ""),
|
|
27704
27724
|
s ? e.env.data.userRoles.list(n, i, void 0, s) : Promise.resolve([])
|
|
27705
|
-
]), b = [...v, ...y], x = s ? await
|
|
27725
|
+
]), b = [...v, ...y], x = s ? await RB(e, n, i, a) : [], S = await Promise.all(b.map((t) => e.env.data.rolePermissions.list(n, t.id, { per_page: 1e3 }))), ee = [];
|
|
27706
27726
|
for (let e of S) e.forEach((e) => {
|
|
27707
27727
|
e.resource_server_identifier === a && ee.push(e.permission_name);
|
|
27708
27728
|
});
|
|
@@ -27715,7 +27735,7 @@ async function GB(e, t) {
|
|
|
27715
27735
|
te.add(e);
|
|
27716
27736
|
});
|
|
27717
27737
|
let ne = Array.from(te), re = ne.filter((e) => f.includes(e));
|
|
27718
|
-
|
|
27738
|
+
GB({
|
|
27719
27739
|
source: "user_permissions",
|
|
27720
27740
|
tenantId: n,
|
|
27721
27741
|
clientId: r,
|
|
@@ -27724,7 +27744,7 @@ async function GB(e, t) {
|
|
|
27724
27744
|
definedScopes: f,
|
|
27725
27745
|
userId: i
|
|
27726
27746
|
});
|
|
27727
|
-
let ie = l ? [] : o.filter((e) => !f.includes(e) && !
|
|
27747
|
+
let ie = l ? [] : o.filter((e) => !f.includes(e) && !LB.includes(e) && (!p || te.has(e)));
|
|
27728
27748
|
if (h === "access_token_authz") return {
|
|
27729
27749
|
scopes: [...new Set([...u, ...ie])],
|
|
27730
27750
|
permissions: re,
|
|
@@ -27743,73 +27763,73 @@ async function GB(e, t) {
|
|
|
27743
27763
|
}
|
|
27744
27764
|
//#endregion
|
|
27745
27765
|
//#region src/helpers/consent.ts
|
|
27746
|
-
var
|
|
27766
|
+
var YB = new Set([
|
|
27747
27767
|
"openid",
|
|
27748
27768
|
"profile",
|
|
27749
27769
|
"email"
|
|
27750
27770
|
]);
|
|
27751
|
-
function
|
|
27771
|
+
function XB(e, t) {
|
|
27752
27772
|
let n = new Set(t), r = [];
|
|
27753
|
-
for (let t of e) t && (
|
|
27773
|
+
for (let t of e) t && (YB.has(t) || n.has(t) || r.push(t));
|
|
27754
27774
|
return Array.from(new Set(r));
|
|
27755
27775
|
}
|
|
27756
|
-
async function
|
|
27757
|
-
if (!e.env.data.grants) return
|
|
27776
|
+
async function ZB(e, t) {
|
|
27777
|
+
if (!e.env.data.grants) return XB(t.requestedScopes, []);
|
|
27758
27778
|
let n = await e.env.data.grants.get(t.tenantId, t.userId, t.clientId);
|
|
27759
|
-
return
|
|
27779
|
+
return XB(t.requestedScopes, n?.scope ?? []);
|
|
27760
27780
|
}
|
|
27761
27781
|
//#endregion
|
|
27762
27782
|
//#region src/utils/safe-compare.ts
|
|
27763
|
-
function
|
|
27783
|
+
function QB(e, t) {
|
|
27764
27784
|
if (!e || !t || e.length !== t.length) return !1;
|
|
27765
27785
|
let n = 0;
|
|
27766
27786
|
for (let r = 0; r < e.length; r++) n |= e.charCodeAt(r) ^ t.charCodeAt(r);
|
|
27767
27787
|
return n === 0;
|
|
27768
27788
|
}
|
|
27769
|
-
async function
|
|
27789
|
+
async function $B(e) {
|
|
27770
27790
|
return Ls(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(e)));
|
|
27771
27791
|
}
|
|
27772
|
-
function
|
|
27792
|
+
function eV(e) {
|
|
27773
27793
|
return e.replace(/[\s-]/g, "").toUpperCase();
|
|
27774
27794
|
}
|
|
27775
|
-
function
|
|
27795
|
+
function tV(e) {
|
|
27776
27796
|
if (!e.deviceCodes) throw new k(503, {
|
|
27777
27797
|
error: "temporarily_unavailable",
|
|
27778
27798
|
error_description: "Device authorization storage is not configured"
|
|
27779
27799
|
});
|
|
27780
27800
|
return e.deviceCodes;
|
|
27781
27801
|
}
|
|
27782
|
-
function
|
|
27802
|
+
function nV(e) {
|
|
27783
27803
|
if (!e.grant_types?.some((e) => e === Gi.DeviceCode || e === "device_code")) throw new k(400, {
|
|
27784
27804
|
error: "unauthorized_client",
|
|
27785
27805
|
error_description: "Device authorization is not enabled for this client"
|
|
27786
27806
|
});
|
|
27787
27807
|
}
|
|
27788
|
-
function
|
|
27808
|
+
function rV(e, t, n, r = !1) {
|
|
27789
27809
|
let i = t.token_endpoint_auth_method ?? (t.app_type === "native" || t.app_type === "spa" ? "none" : "client_secret_post");
|
|
27790
|
-
if (!e.var.client_authenticated_via_assertion && !(i === "none" && n === void 0) && !((i === "client_secret_basic" && r || i === "client_secret_post" && !r) && n &&
|
|
27810
|
+
if (!e.var.client_authenticated_via_assertion && !(i === "none" && n === void 0) && !((i === "client_secret_basic" && r || i === "client_secret_post" && !r) && n && QB(t.client_secret, n))) throw new k(401, {
|
|
27791
27811
|
error: "invalid_client",
|
|
27792
27812
|
error_description: "Client authentication failed"
|
|
27793
27813
|
});
|
|
27794
27814
|
}
|
|
27795
|
-
async function
|
|
27796
|
-
let a = 300 * 1e3, o = Math.floor(Date.now() / a), s = `${n}:${await
|
|
27797
|
-
if (await
|
|
27815
|
+
async function iV(e, t, n, r, i = e.var.ip || "unknown") {
|
|
27816
|
+
let a = 300 * 1e3, o = Math.floor(Date.now() / a), s = `${n}:${await $B(i)}:${o}`;
|
|
27817
|
+
if (await tV(e.env.data).incrementAttempts(t, s, new Date((o + 1) * a).toISOString()) > r) throw new k(429, {
|
|
27798
27818
|
error: "slow_down",
|
|
27799
27819
|
error_description: "Too many device authorization attempts. Try again later."
|
|
27800
27820
|
});
|
|
27801
27821
|
}
|
|
27802
|
-
function
|
|
27822
|
+
function aV(e) {
|
|
27803
27823
|
return Fm(e.state_data).deviceFlow;
|
|
27804
27824
|
}
|
|
27805
|
-
function
|
|
27825
|
+
function oV(e) {
|
|
27806
27826
|
return !!Fm(e).deviceFlow?.deviceCodeHash;
|
|
27807
27827
|
}
|
|
27808
|
-
function
|
|
27828
|
+
function sV(e) {
|
|
27809
27829
|
return `__Host-authhero_device_${e}`;
|
|
27810
27830
|
}
|
|
27811
|
-
function
|
|
27812
|
-
return (0, Cd.serialize)(
|
|
27831
|
+
function cV(e) {
|
|
27832
|
+
return (0, Cd.serialize)(sV(e.id), e.csrf_token, {
|
|
27813
27833
|
httpOnly: !0,
|
|
27814
27834
|
secure: !0,
|
|
27815
27835
|
sameSite: "lax",
|
|
@@ -27817,16 +27837,16 @@ function aV(e) {
|
|
|
27817
27837
|
maxAge: 600
|
|
27818
27838
|
});
|
|
27819
27839
|
}
|
|
27820
|
-
function
|
|
27821
|
-
let n = (0, Cd.parse)(e.req.header("cookie") || "")[
|
|
27822
|
-
if (!n || !
|
|
27840
|
+
function lV(e, t) {
|
|
27841
|
+
let n = (0, Cd.parse)(e.req.header("cookie") || "")[sV(t.id)];
|
|
27842
|
+
if (!n || !QB(t.csrf_token, n)) throw new k(403, {
|
|
27823
27843
|
error: "access_denied",
|
|
27824
27844
|
error_description: "Start device activation again in this browser"
|
|
27825
27845
|
});
|
|
27826
27846
|
}
|
|
27827
27847
|
//#endregion
|
|
27828
27848
|
//#region src/helpers/dcr/connect-state.ts
|
|
27829
|
-
function
|
|
27849
|
+
function uV(e) {
|
|
27830
27850
|
if (!e) return !1;
|
|
27831
27851
|
try {
|
|
27832
27852
|
return !!JSON.parse(e)?.connect;
|
|
@@ -27836,7 +27856,7 @@ function sV(e) {
|
|
|
27836
27856
|
}
|
|
27837
27857
|
//#endregion
|
|
27838
27858
|
//#region src/helpers/scope-claims.ts
|
|
27839
|
-
function
|
|
27859
|
+
function dV(e, t) {
|
|
27840
27860
|
switch (t) {
|
|
27841
27861
|
case "email": return e.email || void 0;
|
|
27842
27862
|
case "email_verified": return e.email_verified === void 0 ? void 0 : e.email_verified;
|
|
@@ -27864,7 +27884,7 @@ function cV(e, t) {
|
|
|
27864
27884
|
default: return;
|
|
27865
27885
|
}
|
|
27866
27886
|
}
|
|
27867
|
-
var
|
|
27887
|
+
var fV = {
|
|
27868
27888
|
email: ["email", "email_verified"],
|
|
27869
27889
|
profile: [
|
|
27870
27890
|
"name",
|
|
@@ -27885,28 +27905,28 @@ var lV = {
|
|
|
27885
27905
|
address: ["address"],
|
|
27886
27906
|
phone: ["phone_number", "phone_number_verified"]
|
|
27887
27907
|
};
|
|
27888
|
-
function
|
|
27908
|
+
function pV(e, t) {
|
|
27889
27909
|
let n = {};
|
|
27890
27910
|
for (let r of t) {
|
|
27891
|
-
let t =
|
|
27911
|
+
let t = fV[r];
|
|
27892
27912
|
if (t) for (let r of t) {
|
|
27893
|
-
let t =
|
|
27913
|
+
let t = dV(e, r);
|
|
27894
27914
|
t !== void 0 && (n[r] = t);
|
|
27895
27915
|
}
|
|
27896
27916
|
}
|
|
27897
27917
|
return n;
|
|
27898
27918
|
}
|
|
27899
|
-
function
|
|
27919
|
+
function mV(e, t) {
|
|
27900
27920
|
let n = {};
|
|
27901
27921
|
for (let r of t) {
|
|
27902
|
-
let t =
|
|
27922
|
+
let t = dV(e, r);
|
|
27903
27923
|
t !== void 0 && (n[r] = t);
|
|
27904
27924
|
}
|
|
27905
27925
|
return n;
|
|
27906
27926
|
}
|
|
27907
27927
|
//#endregion
|
|
27908
27928
|
//#region src/helpers/avatar.ts
|
|
27909
|
-
var
|
|
27929
|
+
var hV = [
|
|
27910
27930
|
"1F77B4",
|
|
27911
27931
|
"FF7F0E",
|
|
27912
27932
|
"2CA02C",
|
|
@@ -27918,45 +27938,45 @@ var fV = [
|
|
|
27918
27938
|
"BCBD22",
|
|
27919
27939
|
"7F7F7F"
|
|
27920
27940
|
];
|
|
27921
|
-
function
|
|
27941
|
+
function gV(e) {
|
|
27922
27942
|
let t = 0;
|
|
27923
27943
|
for (let n = 0; n < e.length; n++) t = (t << 5) - t + e.charCodeAt(n), t |= 0;
|
|
27924
27944
|
return Math.abs(t);
|
|
27925
27945
|
}
|
|
27926
|
-
function
|
|
27946
|
+
function _V(e) {
|
|
27927
27947
|
return e.email || e.name || e.user_id || "?";
|
|
27928
27948
|
}
|
|
27929
|
-
function
|
|
27930
|
-
return
|
|
27949
|
+
function vV(e) {
|
|
27950
|
+
return hV[gV(e.length > 0 ? e : "?") % hV.length] ?? "7F7F7F";
|
|
27931
27951
|
}
|
|
27932
|
-
function
|
|
27952
|
+
function yV(e) {
|
|
27933
27953
|
return e.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])/g, "").replace(/(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g, "");
|
|
27934
27954
|
}
|
|
27935
|
-
function
|
|
27936
|
-
let t =
|
|
27955
|
+
function bV(e) {
|
|
27956
|
+
let t = yV(e.name?.trim() || `${e.given_name ?? ""} ${e.family_name ?? ""}`.trim() || e.nickname?.trim() || e.email?.trim() || e.username?.trim() || "").split(/\s+/).filter(Boolean), n = t[0];
|
|
27937
27957
|
if (!n) return "?";
|
|
27938
27958
|
if (t.length === 1) return [...n].slice(0, 2).join("").toUpperCase() || "?";
|
|
27939
27959
|
let r = t[t.length - 1] ?? n;
|
|
27940
27960
|
return `${[...n][0] ?? ""}${[...r][0] ?? ""}`.toUpperCase() || "?";
|
|
27941
27961
|
}
|
|
27942
|
-
function
|
|
27962
|
+
function xV(e, t) {
|
|
27943
27963
|
return `${e.endsWith("/") ? e : `${e}/`}${t}`;
|
|
27944
27964
|
}
|
|
27945
|
-
function
|
|
27946
|
-
let n =
|
|
27947
|
-
return
|
|
27965
|
+
function SV(e, t) {
|
|
27966
|
+
let n = bV(t), r = vV(_V(t));
|
|
27967
|
+
return xV(e, `avatars/${encodeURIComponent(n)}.svg?bg=${r}`);
|
|
27948
27968
|
}
|
|
27949
|
-
function
|
|
27969
|
+
function CV(e, t) {
|
|
27950
27970
|
return e.picture ? e : {
|
|
27951
27971
|
...e,
|
|
27952
|
-
picture:
|
|
27972
|
+
picture: SV(t, e)
|
|
27953
27973
|
};
|
|
27954
27974
|
}
|
|
27955
|
-
function
|
|
27975
|
+
function wV(e) {
|
|
27956
27976
|
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
27957
27977
|
}
|
|
27958
|
-
function
|
|
27959
|
-
let n = /^[0-9a-fA-F]{6}$/.test(t) ? `#${t}` : "#7F7F7F", r =
|
|
27978
|
+
function TV(e, t) {
|
|
27979
|
+
let n = /^[0-9a-fA-F]{6}$/.test(t) ? `#${t}` : "#7F7F7F", r = wV([...yV(e)].slice(0, 2).join("").toUpperCase()) || "?";
|
|
27960
27980
|
return [
|
|
27961
27981
|
"<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"120\" height=\"120\" viewBox=\"0 0 120 120\" role=\"img\">",
|
|
27962
27982
|
`<rect width="120" height="120" fill="${n}"/>`,
|
|
@@ -27966,32 +27986,32 @@ function SV(e, t) {
|
|
|
27966
27986
|
}
|
|
27967
27987
|
//#endregion
|
|
27968
27988
|
//#region src/helpers/session-usage.ts
|
|
27969
|
-
var
|
|
27970
|
-
function
|
|
27989
|
+
var EV = 3600 * 1e3;
|
|
27990
|
+
function DV(e, t = Date.now()) {
|
|
27971
27991
|
let n = e.used_at ?? e.created_at, r = n ? new Date(n).getTime() : NaN;
|
|
27972
|
-
return Number.isFinite(r) ? t - r >=
|
|
27992
|
+
return Number.isFinite(r) ? t - r >= EV : !0;
|
|
27973
27993
|
}
|
|
27974
|
-
function
|
|
27994
|
+
function OV(e, t, n, r) {
|
|
27975
27995
|
let i = Date.now(), a = () => e.env.data.sessions.update(t, n, { used_at: new Date(i).toISOString() });
|
|
27976
27996
|
if (r) {
|
|
27977
|
-
if (!
|
|
27997
|
+
if (!DV(r, i)) return;
|
|
27978
27998
|
Wc(e, a().catch(() => {}));
|
|
27979
27999
|
return;
|
|
27980
28000
|
}
|
|
27981
28001
|
Wc(e, (async () => {
|
|
27982
28002
|
let r = await e.env.data.sessions.get(t, n);
|
|
27983
|
-
!r || r.revoked_at ||
|
|
28003
|
+
!r || r.revoked_at || DV(r, i) && await a();
|
|
27984
28004
|
})().catch(() => {}));
|
|
27985
28005
|
}
|
|
27986
28006
|
//#endregion
|
|
27987
28007
|
//#region src/utils/url.ts
|
|
27988
|
-
function
|
|
28008
|
+
function kV(e, t) {
|
|
27989
28009
|
Object.keys(t).forEach((n) => {
|
|
27990
28010
|
let r = t[n];
|
|
27991
28011
|
r != null && r.length && e.searchParams.set(n, r);
|
|
27992
28012
|
});
|
|
27993
28013
|
}
|
|
27994
|
-
function
|
|
28014
|
+
function AV(e) {
|
|
27995
28015
|
try {
|
|
27996
28016
|
let t = typeof e == "string" ? new URL(e) : e, n = `${t.protocol}//${t.host}${t.pathname}`;
|
|
27997
28017
|
if (t.search) {
|
|
@@ -28015,51 +28035,51 @@ function DV(e) {
|
|
|
28015
28035
|
}
|
|
28016
28036
|
//#endregion
|
|
28017
28037
|
//#region src/helpers/refresh-token-lifetime.ts
|
|
28018
|
-
var
|
|
28019
|
-
function
|
|
28038
|
+
var jV = 3600;
|
|
28039
|
+
function MV(e) {
|
|
28020
28040
|
return !e || e <= 0 ? { kind: "unset" } : {
|
|
28021
28041
|
kind: "seconds",
|
|
28022
|
-
seconds: e *
|
|
28042
|
+
seconds: e * jV
|
|
28023
28043
|
};
|
|
28024
28044
|
}
|
|
28025
|
-
function
|
|
28045
|
+
function NV(e) {
|
|
28026
28046
|
if (!(e === void 0 || e <= 0)) return {
|
|
28027
28047
|
kind: "seconds",
|
|
28028
28048
|
seconds: e
|
|
28029
28049
|
};
|
|
28030
28050
|
}
|
|
28031
|
-
function
|
|
28051
|
+
function PV(e) {
|
|
28032
28052
|
let t = e.refresh_token;
|
|
28033
|
-
return t?.expiration_type === "non-expiring" || t?.infinite_token_lifetime ? { kind: "infinite" } :
|
|
28053
|
+
return t?.expiration_type === "non-expiring" || t?.infinite_token_lifetime ? { kind: "infinite" } : NV(t?.token_lifetime) ?? MV(e.tenant.session_lifetime);
|
|
28034
28054
|
}
|
|
28035
|
-
function
|
|
28055
|
+
function FV(e) {
|
|
28036
28056
|
let t = e.refresh_token;
|
|
28037
|
-
return t?.expiration_type === "non-expiring" || t?.infinite_idle_token_lifetime ? { kind: "infinite" } :
|
|
28057
|
+
return t?.expiration_type === "non-expiring" || t?.infinite_idle_token_lifetime ? { kind: "infinite" } : NV(t?.idle_token_lifetime) ?? MV(e.tenant.idle_session_lifetime);
|
|
28038
28058
|
}
|
|
28039
|
-
function
|
|
28059
|
+
function IV(e, t = Date.now()) {
|
|
28040
28060
|
if (e.kind === "seconds") return new Date(t + e.seconds * 1e3).toISOString();
|
|
28041
28061
|
}
|
|
28042
|
-
function
|
|
28062
|
+
function LV(e, t = Date.now()) {
|
|
28043
28063
|
return {
|
|
28044
|
-
expires_at:
|
|
28045
|
-
idle_expires_at:
|
|
28064
|
+
expires_at: IV(PV(e), t),
|
|
28065
|
+
idle_expires_at: IV(FV(e), t)
|
|
28046
28066
|
};
|
|
28047
28067
|
}
|
|
28048
|
-
function
|
|
28049
|
-
let r =
|
|
28050
|
-
if (r.kind !== "infinite") return r.kind === "unset" || !t ? t :
|
|
28068
|
+
function RV(e, t, n = Date.now()) {
|
|
28069
|
+
let r = FV(e);
|
|
28070
|
+
if (r.kind !== "infinite") return r.kind === "unset" || !t ? t : IV(r, n);
|
|
28051
28071
|
}
|
|
28052
|
-
function
|
|
28072
|
+
function zV(e, t, n = Date.now()) {
|
|
28053
28073
|
let r = {};
|
|
28054
|
-
if (t.expires_at &&
|
|
28055
|
-
let t =
|
|
28056
|
-
t.kind === "infinite" ? r.idle_expires_at = null : t.kind === "seconds" && (r.idle_expires_at =
|
|
28074
|
+
if (t.expires_at && PV(e).kind === "infinite" && (r.expires_at = null), t.idle_expires_at) {
|
|
28075
|
+
let t = FV(e);
|
|
28076
|
+
t.kind === "infinite" ? r.idle_expires_at = null : t.kind === "seconds" && (r.idle_expires_at = IV(t, n));
|
|
28057
28077
|
}
|
|
28058
28078
|
return r;
|
|
28059
28079
|
}
|
|
28060
28080
|
//#endregion
|
|
28061
28081
|
//#region src/authentication-flows/common.ts
|
|
28062
|
-
function
|
|
28082
|
+
function BV(e) {
|
|
28063
28083
|
switch (e) {
|
|
28064
28084
|
case Gi.DeviceCode: return E.FAILED_EXCHANGE_DEVICE_CODE_FOR_ACCESS_TOKEN;
|
|
28065
28085
|
case Gi.AuthorizationCode: return E.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN;
|
|
@@ -28072,7 +28092,7 @@ function LV(e) {
|
|
|
28072
28092
|
default: return E.FAILED_EXCHANGE_CUSTOM_TOKEN;
|
|
28073
28093
|
}
|
|
28074
28094
|
}
|
|
28075
|
-
function
|
|
28095
|
+
function VV(e, t, n, r, i = "onExecuteCredentialsExchange") {
|
|
28076
28096
|
return {
|
|
28077
28097
|
accessToken: { setCustomClaim: (n, r) => {
|
|
28078
28098
|
uO(t, n, r, {
|
|
@@ -28091,19 +28111,19 @@ function RV(e, t, n, r, i = "onExecuteCredentialsExchange") {
|
|
|
28091
28111
|
access: { deny: (t, n) => {
|
|
28092
28112
|
let i = n ? `${t} - ${n}` : t;
|
|
28093
28113
|
throw O(e, e.var.tenant_id || "", {
|
|
28094
|
-
type:
|
|
28114
|
+
type: BV(r),
|
|
28095
28115
|
description: `Access denied by credentials-exchange hook: ${i}`
|
|
28096
28116
|
}), new k(400, { message: `Access denied: ${i}` });
|
|
28097
28117
|
} },
|
|
28098
28118
|
token: { createServiceToken: async (t) => (await gO(e, e.var.tenant_id, t.scope, t.expiresInSeconds, t.customClaims)).access_token }
|
|
28099
28119
|
};
|
|
28100
28120
|
}
|
|
28101
|
-
function
|
|
28121
|
+
function HV(e) {
|
|
28102
28122
|
if (!e?.state_data) return;
|
|
28103
28123
|
let t = Fm(e.state_data);
|
|
28104
28124
|
return t.mfa_verified && t.mfa_method ? ["mfa"] : void 0;
|
|
28105
28125
|
}
|
|
28106
|
-
async function
|
|
28126
|
+
async function UV(e, n) {
|
|
28107
28127
|
let { authParams: r, user: i, client: a, session_id: o, organization: s, permissions: c, impersonatingUser: l, actClient: u, grantType: d } = n;
|
|
28108
28128
|
if (i?.blocked) throw new k(403, {
|
|
28109
28129
|
error: "access_denied",
|
|
@@ -28119,7 +28139,7 @@ async function BV(e, n) {
|
|
|
28119
28139
|
sub: u.client_id,
|
|
28120
28140
|
client_id: u.client_id
|
|
28121
28141
|
};
|
|
28122
|
-
})(), p = n.amr ?? (i && n.loginSession?.user_id === i.user_id ?
|
|
28142
|
+
})(), p = n.amr ?? (i && n.loginSession?.user_id === i.user_id ? HV(n.loginSession) : void 0), m = n.auth_time, h = r.prompt?.split(" ") ?? [], g = r.max_age !== void 0 || h.includes("login") || r.claims?.id_token?.auth_time?.essential === !0;
|
|
28123
28143
|
if (m === void 0 && g) {
|
|
28124
28144
|
if (n.loginSession?.authenticated_at) m = Math.floor(new Date(n.loginSession.authenticated_at).getTime() / 1e3);
|
|
28125
28145
|
else if (o && e.var.tenant_id) {
|
|
@@ -28149,7 +28169,7 @@ async function BV(e, n) {
|
|
|
28149
28169
|
}, re = r.scope?.split(" ") || [], ie = re.includes("openid");
|
|
28150
28170
|
if (!p && i && ie && o && e.var.tenant_id) {
|
|
28151
28171
|
let t = await e.env.data.sessions.get(e.var.tenant_id, o);
|
|
28152
|
-
t &&
|
|
28172
|
+
t && pB(t, i.user_id) && (p = ["mfa"]);
|
|
28153
28173
|
}
|
|
28154
28174
|
let ae = (r.response_type ?? "").trim() === At.ID_TOKEN, oe = a.auth0_conformant !== !1 || ae, se = {
|
|
28155
28175
|
aud: r.client_id,
|
|
@@ -28166,9 +28186,9 @@ async function BV(e, n) {
|
|
|
28166
28186
|
org_name: s?.name.toLowerCase()
|
|
28167
28187
|
}, le = i && ie ? {
|
|
28168
28188
|
...se,
|
|
28169
|
-
...oe ?
|
|
28170
|
-
...r.claims?.id_token ?
|
|
28171
|
-
...ae && r.claims?.userinfo ?
|
|
28189
|
+
...oe ? pV(CV(i, x), re) : {},
|
|
28190
|
+
...r.claims?.id_token ? mV(CV(i, x), Object.keys(r.claims.id_token)) : {},
|
|
28191
|
+
...ae && r.claims?.userinfo ? mV(CV(i, x), Object.keys(r.claims.userinfo)) : {},
|
|
28172
28192
|
...ce
|
|
28173
28193
|
} : void 0, ue = qc({
|
|
28174
28194
|
loginSession: n.loginSession,
|
|
@@ -28209,18 +28229,18 @@ async function BV(e, n) {
|
|
|
28209
28229
|
name: ue,
|
|
28210
28230
|
strategy: i?.provider || "auth0"
|
|
28211
28231
|
} : void 0)
|
|
28212
|
-
},
|
|
28232
|
+
}, VV(e, ne, le, d));
|
|
28213
28233
|
{
|
|
28214
|
-
let { hooks: n } = await e.env.data.hooks.list(e.var.tenant_id), o = n.filter((e) => e.trigger_id === "credentials-exchange" && e.enabled &&
|
|
28234
|
+
let { hooks: n } = await e.env.data.hooks.list(e.var.tenant_id), o = n.filter((e) => e.trigger_id === "credentials-exchange" && e.enabled && gz(e));
|
|
28215
28235
|
if (i) {
|
|
28216
|
-
for (let n of o) if (
|
|
28217
|
-
await
|
|
28236
|
+
for (let n of o) if (gz(n)) try {
|
|
28237
|
+
await bz(e, n.template_id, i, VV(e, ne, le, d, `template-hook:${n.template_id}`));
|
|
28218
28238
|
} catch (e) {
|
|
28219
28239
|
if (e instanceof t) throw e;
|
|
28220
28240
|
console.warn(`[credentials-exchange] Failed to execute template hook: ${n.template_id}`, e);
|
|
28221
28241
|
}
|
|
28222
28242
|
}
|
|
28223
|
-
let c =
|
|
28243
|
+
let c = VV(e, ne, le, d, "credentials-exchange-code-hook"), l = await zR(e, n, {
|
|
28224
28244
|
ctx: e,
|
|
28225
28245
|
client: a,
|
|
28226
28246
|
user: i,
|
|
@@ -28259,7 +28279,7 @@ async function BV(e, n) {
|
|
|
28259
28279
|
expires_in: fe
|
|
28260
28280
|
};
|
|
28261
28281
|
}
|
|
28262
|
-
async function
|
|
28282
|
+
async function WV(e, t) {
|
|
28263
28283
|
return {
|
|
28264
28284
|
code: (await e.env.data.codes.create(t.client.tenant.id, {
|
|
28265
28285
|
code_id: Xl(32),
|
|
@@ -28276,14 +28296,14 @@ async function VV(e, t) {
|
|
|
28276
28296
|
state: t.authParams.state
|
|
28277
28297
|
};
|
|
28278
28298
|
}
|
|
28279
|
-
function
|
|
28299
|
+
function GV(e) {
|
|
28280
28300
|
if (e) return new Date(Date.now() + e * 60 * 60 * 1e3).toISOString();
|
|
28281
28301
|
}
|
|
28282
|
-
function
|
|
28302
|
+
function KV(e, t) {
|
|
28283
28303
|
return t ? e && Date.parse(e) <= Date.parse(t) ? e : t : e;
|
|
28284
28304
|
}
|
|
28285
|
-
async function
|
|
28286
|
-
let { client: n, scope: r, login_id: i } = t, a = wc(e.env, e.var.custom_domain), o = t.audience ?? n.tenant.default_audience ?? `${a}userinfo`, { expires_at: s, idle_expires_at: c } =
|
|
28305
|
+
async function qV(e, t) {
|
|
28306
|
+
let { client: n, scope: r, login_id: i } = t, a = wc(e.env, e.var.custom_domain), o = t.audience ?? n.tenant.default_audience ?? `${a}userinfo`, { expires_at: s, idle_expires_at: c } = LV(n), l = PO(), { lookup: u, secret: d } = ZO(), f = await QO(d), p = n.refresh_token?.rotation_type === "rotating";
|
|
28287
28307
|
return {
|
|
28288
28308
|
row: await e.env.data.refreshTokens.create(n.tenant.id, {
|
|
28289
28309
|
id: l,
|
|
@@ -28293,8 +28313,8 @@ async function WV(e, t) {
|
|
|
28293
28313
|
auth_connection: t.auth_connection,
|
|
28294
28314
|
auth_strategy: t.auth_strategy,
|
|
28295
28315
|
client_id: n.client_id,
|
|
28296
|
-
idle_expires_at: c ?
|
|
28297
|
-
expires_at:
|
|
28316
|
+
idle_expires_at: c ? KV(c, t.max_expires_at) : void 0,
|
|
28317
|
+
expires_at: KV(s, t.max_expires_at),
|
|
28298
28318
|
session_transfer: t.session_transfer,
|
|
28299
28319
|
user_id: t.user.user_id,
|
|
28300
28320
|
device: {
|
|
@@ -28317,8 +28337,8 @@ async function WV(e, t) {
|
|
|
28317
28337
|
wireToken: $O(u, d)
|
|
28318
28338
|
};
|
|
28319
28339
|
}
|
|
28320
|
-
async function
|
|
28321
|
-
let i =
|
|
28340
|
+
async function JV(e, { user: t, client: n, loginSession: r }) {
|
|
28341
|
+
let i = GV(n.tenant.idle_session_lifetime), a = GV(n.tenant.session_lifetime);
|
|
28322
28342
|
return await e.env.data.sessions.create(n.tenant.id, {
|
|
28323
28343
|
id: PO(),
|
|
28324
28344
|
user_id: t.user_id,
|
|
@@ -28336,7 +28356,7 @@ async function GV(e, { user: t, client: n, loginSession: r }) {
|
|
|
28336
28356
|
clients: [n.client_id]
|
|
28337
28357
|
});
|
|
28338
28358
|
}
|
|
28339
|
-
async function
|
|
28359
|
+
async function YV(e, { user: n, client: r, loginSession: i, existingSessionId: a, authConnection: o, authStrategy: s }) {
|
|
28340
28360
|
let c = await e.env.data.loginSessions.get(r.tenant.id, i.id);
|
|
28341
28361
|
if (!c) throw new t(400, { message: `Login session ${i.id} not found` });
|
|
28342
28362
|
let l = c.state || T.PENDING;
|
|
@@ -28356,18 +28376,18 @@ async function KV(e, { user: n, client: r, loginSession: i, existingSessionId: a
|
|
|
28356
28376
|
if (a) {
|
|
28357
28377
|
let t = await e.env.data.sessions.get(r.tenant.id, a);
|
|
28358
28378
|
if (!t || t.revoked_at) {
|
|
28359
|
-
let t = await
|
|
28379
|
+
let t = await JV(e, {
|
|
28360
28380
|
user: n,
|
|
28361
28381
|
client: r,
|
|
28362
28382
|
loginSession: i
|
|
28363
28383
|
});
|
|
28364
28384
|
u = t.id, d = t.authenticated_at;
|
|
28365
|
-
} else u = a, d = t.authenticated_at, t.clients.includes(r.client_id) ?
|
|
28385
|
+
} else u = a, d = t.authenticated_at, t.clients.includes(r.client_id) ? OV(e, r.tenant.id, a, t) : await e.env.data.sessions.update(r.tenant.id, a, {
|
|
28366
28386
|
clients: [...t.clients, r.client_id],
|
|
28367
|
-
...
|
|
28387
|
+
...DV(t) && { used_at: (/* @__PURE__ */ new Date()).toISOString() }
|
|
28368
28388
|
});
|
|
28369
28389
|
} else {
|
|
28370
|
-
let t = await
|
|
28390
|
+
let t = await JV(e, {
|
|
28371
28391
|
user: n,
|
|
28372
28392
|
client: r,
|
|
28373
28393
|
loginSession: i
|
|
@@ -28391,9 +28411,9 @@ async function KV(e, { user: n, client: r, loginSession: i, existingSessionId: a
|
|
|
28391
28411
|
...l === T.EXPIRED ? { expires_at: new Date(Date.now() + ud * 1e3).toISOString() } : {}
|
|
28392
28412
|
}), u;
|
|
28393
28413
|
}
|
|
28394
|
-
async function
|
|
28414
|
+
async function XV(e, t) {
|
|
28395
28415
|
let { user: n, client: r, loginSession: i, authStrategy: a, authConnection: o } = t;
|
|
28396
|
-
await
|
|
28416
|
+
await YV(e, {
|
|
28397
28417
|
user: n,
|
|
28398
28418
|
client: r,
|
|
28399
28419
|
loginSession: i,
|
|
@@ -28412,7 +28432,7 @@ async function qV(e, t) {
|
|
|
28412
28432
|
headers: u
|
|
28413
28433
|
});
|
|
28414
28434
|
}
|
|
28415
|
-
async function
|
|
28435
|
+
async function ZV(e, t, n, r) {
|
|
28416
28436
|
let i = await e.env.data.loginSessions.get(t, n.id);
|
|
28417
28437
|
if (!i) {
|
|
28418
28438
|
console.warn(`Login session ${n.id} not found when trying to mark as failed`);
|
|
@@ -28427,7 +28447,7 @@ async function JV(e, t, n, r) {
|
|
|
28427
28447
|
failure_reason: s.failureReason
|
|
28428
28448
|
});
|
|
28429
28449
|
}
|
|
28430
|
-
async function
|
|
28450
|
+
async function QV(e, t, n, r) {
|
|
28431
28451
|
let i = await e.env.data.loginSessions.get(t, n.id);
|
|
28432
28452
|
if (!i) {
|
|
28433
28453
|
console.warn(`Login session ${n.id} not found when trying to start hook`);
|
|
@@ -28442,7 +28462,7 @@ async function YV(e, t, n, r) {
|
|
|
28442
28462
|
data: { hookId: s.hookId }
|
|
28443
28463
|
}, { state: o });
|
|
28444
28464
|
}
|
|
28445
|
-
async function
|
|
28465
|
+
async function $V(e, t, n) {
|
|
28446
28466
|
let r = await e.env.data.loginSessions.get(t, n.id);
|
|
28447
28467
|
if (!r) {
|
|
28448
28468
|
console.warn(`Login session ${n.id} not found when trying to complete hook`);
|
|
@@ -28457,7 +28477,7 @@ async function XV(e, t, n) {
|
|
|
28457
28477
|
}
|
|
28458
28478
|
}, { state: a });
|
|
28459
28479
|
}
|
|
28460
|
-
async function
|
|
28480
|
+
async function eH(e, t, n, r, i) {
|
|
28461
28481
|
let a = i ?? await e.env.data.loginSessions.get(t, n.id);
|
|
28462
28482
|
if (!a) {
|
|
28463
28483
|
console.warn(`Login session ${n.id} not found when trying to mark as completed`);
|
|
@@ -28469,7 +28489,7 @@ async function ZV(e, t, n, r, i) {
|
|
|
28469
28489
|
...r ? { auth_connection: r } : {}
|
|
28470
28490
|
});
|
|
28471
28491
|
}
|
|
28472
|
-
async function
|
|
28492
|
+
async function tH(e, t, n, r, i) {
|
|
28473
28493
|
let a = await e.env.data.loginSessions.get(t, n.id);
|
|
28474
28494
|
if (!a) {
|
|
28475
28495
|
console.warn(`Login session ${n.id} not found when trying to start continuation`);
|
|
@@ -28479,7 +28499,7 @@ async function QV(e, t, n, r, i) {
|
|
|
28479
28499
|
type: j.START_CONTINUATION,
|
|
28480
28500
|
scope: r
|
|
28481
28501
|
});
|
|
28482
|
-
s === o ? console.warn(`Failed to start continuation for login session ${n.id}: cannot transition from ${o} to AWAITING_CONTINUATION. Scope: ${JSON.stringify(r)}, Return URL: ${
|
|
28502
|
+
s === o ? console.warn(`Failed to start continuation for login session ${n.id}: cannot transition from ${o} to AWAITING_CONTINUATION. Scope: ${JSON.stringify(r)}, Return URL: ${AV(i)}`) : await TO(e.env.data.loginSessions, t, n.id, {
|
|
28483
28503
|
type: j.UPDATE_CONTEXT,
|
|
28484
28504
|
data: {
|
|
28485
28505
|
continuationScope: r,
|
|
@@ -28487,7 +28507,7 @@ async function QV(e, t, n, r, i) {
|
|
|
28487
28507
|
}
|
|
28488
28508
|
}, { state: s });
|
|
28489
28509
|
}
|
|
28490
|
-
async function
|
|
28510
|
+
async function nH(e, t, n) {
|
|
28491
28511
|
let r = await e.env.data.loginSessions.get(t, n.id);
|
|
28492
28512
|
if (!r) {
|
|
28493
28513
|
console.warn(`Login session ${n.id} not found when trying to complete continuation`);
|
|
@@ -28502,7 +28522,7 @@ async function $V(e, t, n) {
|
|
|
28502
28522
|
}
|
|
28503
28523
|
}, { state: o }), i;
|
|
28504
28524
|
}
|
|
28505
|
-
function
|
|
28525
|
+
function rH(e) {
|
|
28506
28526
|
if (!e.state_data) return null;
|
|
28507
28527
|
try {
|
|
28508
28528
|
return JSON.parse(e.state_data).continuationScope || null;
|
|
@@ -28510,12 +28530,12 @@ function eH(e) {
|
|
|
28510
28530
|
return null;
|
|
28511
28531
|
}
|
|
28512
28532
|
}
|
|
28513
|
-
function
|
|
28533
|
+
function iH(e, t) {
|
|
28514
28534
|
if (e.state !== T.AWAITING_CONTINUATION || !(Date.parse(e.expires_at) > Date.now())) return !1;
|
|
28515
|
-
let n =
|
|
28535
|
+
let n = rH(e);
|
|
28516
28536
|
return n ? n.includes(t) : !1;
|
|
28517
28537
|
}
|
|
28518
|
-
async function
|
|
28538
|
+
async function aH(e, n) {
|
|
28519
28539
|
let { authParams: r, client: i, ticketAuth: a } = n, { user: o } = n, s = r.response_type || At.CODE, c = r.response_mode || jt.QUERY;
|
|
28520
28540
|
if (a) {
|
|
28521
28541
|
if (!n.loginSession) throw new k(500, { message: "Login session not found for ticket auth." });
|
|
@@ -28525,7 +28545,7 @@ async function nH(e, n) {
|
|
|
28525
28545
|
}, await e.env.data.users.update(i.tenant.id, o.user_id, { app_metadata: {
|
|
28526
28546
|
...o.app_metadata || {},
|
|
28527
28547
|
strategy: n.authStrategy.strategy
|
|
28528
|
-
} })), await
|
|
28548
|
+
} })), await SB(e, e.env.data, i.tenant.id, o, n.loginSession, {
|
|
28529
28549
|
client: i,
|
|
28530
28550
|
authParams: r,
|
|
28531
28551
|
authStrategy: n.authStrategy,
|
|
@@ -28562,7 +28582,7 @@ async function nH(e, n) {
|
|
|
28562
28582
|
error_description: `Login session failed: ${d.failure_reason || "unknown reason"}`
|
|
28563
28583
|
});
|
|
28564
28584
|
if (f === T.PENDING || f === T.EXPIRED) {
|
|
28565
|
-
u = await
|
|
28585
|
+
u = await YV(e, {
|
|
28566
28586
|
user: o,
|
|
28567
28587
|
client: i,
|
|
28568
28588
|
loginSession: n.loginSession,
|
|
@@ -28597,7 +28617,7 @@ async function nH(e, n) {
|
|
|
28597
28617
|
}
|
|
28598
28618
|
if (t === T.AUTHENTICATED && a.mfa_verified === !0 && u) try {
|
|
28599
28619
|
let t = await e.env.data.sessions.get(i.tenant.id, u), n = typeof a.mfa_verified_at == "string" ? a.mfa_verified_at : void 0;
|
|
28600
|
-
t && !t.revoked_at && t.user_id === o.user_id && (n || !
|
|
28620
|
+
t && !t.revoked_at && t.user_id === o.user_id && (n || !fB(t)) && await mB(e.env.data.sessions, i.tenant.id, t, {
|
|
28601
28621
|
type: typeof a.mfa_method == "string" ? a.mfa_method : void 0,
|
|
28602
28622
|
timestamp: n ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
28603
28623
|
});
|
|
@@ -28605,7 +28625,7 @@ async function nH(e, n) {
|
|
|
28605
28625
|
console.error("Failed to record MFA completion on session", e);
|
|
28606
28626
|
}
|
|
28607
28627
|
if (t === T.AUTHENTICATED && !a.mfa_verified) {
|
|
28608
|
-
let { checkMfaRequired: t, sendMfaOtp: r } = await import("./mfa-
|
|
28628
|
+
let { checkMfaRequired: t, sendMfaOtp: r } = await import("./mfa-D56D6aKD.mjs").then((e) => e.i), { isBrowserRememberedForMfa: s } = await import("./authhero.mjs").then((e) => e.t), c = await t(e, i.tenant.id, o.user_id, { force: !!a.mfa_required_by_action }), l = c.required && u ? await e.env.data.sessions.get(i.tenant.id, u).then((e) => e ? pB(e, o.user_id) : !1) : !1, f = c.required && c.enrolled && !l ? await s(e, {
|
|
28609
28629
|
tenant: i.tenant,
|
|
28610
28630
|
userId: o.user_id,
|
|
28611
28631
|
actionRequest: Fm(d.state_data).mfa_required_by_action
|
|
@@ -28629,7 +28649,7 @@ async function nH(e, n) {
|
|
|
28629
28649
|
headers: { location: `/u2/passkey/challenge?state=${encodeURIComponent(n.loginSession.id)}` }
|
|
28630
28650
|
});
|
|
28631
28651
|
if (!c.enrollment.phone_number) throw Error("MFA enrollment is missing phone_number");
|
|
28632
|
-
let { MfaSmsRateLimitError: a } = await Promise.resolve().then(() =>
|
|
28652
|
+
let { MfaSmsRateLimitError: a } = await Promise.resolve().then(() => sH);
|
|
28633
28653
|
try {
|
|
28634
28654
|
await r(e, i, n.loginSession, c.enrollment.phone_number);
|
|
28635
28655
|
} catch (e) {
|
|
@@ -28657,7 +28677,7 @@ async function nH(e, n) {
|
|
|
28657
28677
|
}
|
|
28658
28678
|
}
|
|
28659
28679
|
}
|
|
28660
|
-
if (a.mfa_required_by_action && !a.mfa_verified && !(u && await e.env.data.sessions.get(i.tenant.id, u).then((e) => e ?
|
|
28680
|
+
if (a.mfa_required_by_action && !a.mfa_verified && !(u && await e.env.data.sessions.get(i.tenant.id, u).then((e) => e ? pB(e, o.user_id) : !1)) && !await import("./authhero.mjs").then((e) => e.t).then(({ isBrowserRememberedForMfa: t }) => t(e, {
|
|
28661
28681
|
tenant: i.tenant,
|
|
28662
28682
|
userId: o.user_id,
|
|
28663
28683
|
actionRequest: Fm(d.state_data).mfa_required_by_action
|
|
@@ -28665,9 +28685,9 @@ async function nH(e, n) {
|
|
|
28665
28685
|
error: "access_denied",
|
|
28666
28686
|
error_description: "Multi-factor authentication is required to complete this login"
|
|
28667
28687
|
});
|
|
28668
|
-
if (u &&
|
|
28669
|
-
if (!
|
|
28670
|
-
let t = await
|
|
28688
|
+
if (u && oV(d.state_data)) {
|
|
28689
|
+
if (!aV(d)?.ready && !m) {
|
|
28690
|
+
let t = await SB(e, e.env.data, i.tenant.id, o, d, {
|
|
28671
28691
|
client: i,
|
|
28672
28692
|
authParams: {
|
|
28673
28693
|
...r,
|
|
@@ -28681,7 +28701,7 @@ async function nH(e, n) {
|
|
|
28681
28701
|
await TO(e.env.data.loginSessions, i.tenant.id, d.id, {
|
|
28682
28702
|
type: j.UPDATE_CONTEXT,
|
|
28683
28703
|
data: { deviceFlow: {
|
|
28684
|
-
...
|
|
28704
|
+
...aV(d),
|
|
28685
28705
|
ready: !0
|
|
28686
28706
|
} }
|
|
28687
28707
|
});
|
|
@@ -28691,7 +28711,7 @@ async function nH(e, n) {
|
|
|
28691
28711
|
headers: t
|
|
28692
28712
|
});
|
|
28693
28713
|
}
|
|
28694
|
-
if (u &&
|
|
28714
|
+
if (u && uV(d.state_data)) {
|
|
28695
28715
|
let t = new Headers();
|
|
28696
28716
|
return Rd(i.tenant.id, u, e.var.host || "").forEach((e) => t.append("set-cookie", e)), t.set("location", `/u2/connect/start?state=${encodeURIComponent(n.loginSession.id)}`), new Response(null, {
|
|
28697
28717
|
status: 302,
|
|
@@ -28707,7 +28727,7 @@ async function nH(e, n) {
|
|
|
28707
28727
|
});
|
|
28708
28728
|
if (t === T.AUTHENTICATED) {
|
|
28709
28729
|
let t = d.authParams.scope?.split(" ").filter(Boolean) ?? [];
|
|
28710
|
-
if ((await
|
|
28730
|
+
if ((await ZB(e, {
|
|
28711
28731
|
tenantId: i.tenant.id,
|
|
28712
28732
|
userId: o.user_id,
|
|
28713
28733
|
clientId: i.client_id,
|
|
@@ -28728,7 +28748,7 @@ async function nH(e, n) {
|
|
|
28728
28748
|
} catch {}
|
|
28729
28749
|
if (t === T.AUTHENTICATED && !r.passkey_nudge_completed) {
|
|
28730
28750
|
let { checkPasskeyNudgeRequired: t } = await import("./passkey-enrollment-Ba_8I87G.mjs");
|
|
28731
|
-
if ((await t(e, i.tenant.id, o.user_id, d.auth_connection)).show) return await
|
|
28751
|
+
if ((await t(e, i.tenant.id, o.user_id, d.auth_connection)).show) return await tH(e, i.tenant.id, d, ["passkey-enrollment"], `/u2/continue?state=${encodeURIComponent(n.loginSession.id)}`), new Response(null, {
|
|
28732
28752
|
status: 302,
|
|
28733
28753
|
headers: { location: `/u2/passkey/enrollment-nudge?state=${encodeURIComponent(n.loginSession.id)}` }
|
|
28734
28754
|
});
|
|
@@ -28737,7 +28757,7 @@ async function nH(e, n) {
|
|
|
28737
28757
|
let h = s.split(" ").includes("code");
|
|
28738
28758
|
if (!l && r.scope?.split(" ").includes("offline_access") && s !== At.TOKEN && !h && !n.impersonatingUser) {
|
|
28739
28759
|
let t = JO(i, u ? await e.env.data.sessions.get(i.tenant.id, u) : null);
|
|
28740
|
-
t.allowed && (l = (await
|
|
28760
|
+
t.allowed && (l = (await qV(e, {
|
|
28741
28761
|
user: o,
|
|
28742
28762
|
client: i,
|
|
28743
28763
|
login_id: n.loginSession?.id || "",
|
|
@@ -28755,7 +28775,7 @@ async function nH(e, n) {
|
|
|
28755
28775
|
if (!u) throw new t(500, { message: "Session ID not available for SAML response" });
|
|
28756
28776
|
let a = o;
|
|
28757
28777
|
if (n.loginSession && !m) {
|
|
28758
|
-
let t = await
|
|
28778
|
+
let t = await SB(e, e.env.data, i.tenant.id, o, n.loginSession, {
|
|
28759
28779
|
client: i,
|
|
28760
28780
|
authParams: r,
|
|
28761
28781
|
authStrategy: n.authStrategy,
|
|
@@ -28767,7 +28787,7 @@ async function nH(e, n) {
|
|
|
28767
28787
|
}
|
|
28768
28788
|
return NL(e, n.client, n.authParams, a, u, n.loginSession?.id);
|
|
28769
28789
|
}
|
|
28770
|
-
let g = await
|
|
28790
|
+
let g = await oH(e, {
|
|
28771
28791
|
authParams: r,
|
|
28772
28792
|
user: o,
|
|
28773
28793
|
client: i,
|
|
@@ -28794,9 +28814,9 @@ async function nH(e, n) {
|
|
|
28794
28814
|
let ne = ("state" in g && typeof g.state == "string" ? g.state : void 0) ?? r.state;
|
|
28795
28815
|
if (ne && (S.state = ne), (x || b) && r.scope && (S.scope = r.scope), c === jt.WEB_MESSAGE) {
|
|
28796
28816
|
let t = new URL(r.redirect_uri);
|
|
28797
|
-
return
|
|
28817
|
+
return TB(e, `${t.protocol}//${t.host}`, JSON.stringify(S), _);
|
|
28798
28818
|
}
|
|
28799
|
-
if (c === jt.FORM_POST) return
|
|
28819
|
+
if (c === jt.FORM_POST) return OB(r.redirect_uri, S, _);
|
|
28800
28820
|
let re = b || x, ie = new URL(r.redirect_uri);
|
|
28801
28821
|
if (re) ie.hash = new URLSearchParams(S).toString();
|
|
28802
28822
|
else for (let [e, t] of Object.entries(S)) ie.searchParams.set(e, t);
|
|
@@ -28805,16 +28825,16 @@ async function nH(e, n) {
|
|
|
28805
28825
|
headers: _
|
|
28806
28826
|
});
|
|
28807
28827
|
}
|
|
28808
|
-
async function
|
|
28828
|
+
async function oH(e, n) {
|
|
28809
28829
|
let { user: r } = n, i = n.responseType || At.TOKEN;
|
|
28810
|
-
if (r && n.organization && !await
|
|
28830
|
+
if (r && n.organization && !await WB(e, n.client.tenant.id, r.user_id, n.organization.id)) throw new k(403, {
|
|
28811
28831
|
error: "access_denied",
|
|
28812
28832
|
error_description: "User is not a member of the specified organization"
|
|
28813
28833
|
});
|
|
28814
28834
|
let a = n.authParams.scope || "", o = [], s, c = wc(e.env, e.var.custom_domain), l = n.authParams.audience ?? n.client.tenant.default_audience ?? `${c}userinfo`;
|
|
28815
28835
|
if (l) try {
|
|
28816
28836
|
let t;
|
|
28817
|
-
if (n.grantType === Gi.ClientCredential || !r && !n.user) t = await
|
|
28837
|
+
if (n.grantType === Gi.ClientCredential || !r && !n.user) t = await JB(e, {
|
|
28818
28838
|
grantType: Gi.ClientCredential,
|
|
28819
28839
|
tenantId: n.client.tenant.id,
|
|
28820
28840
|
clientId: n.client.client_id,
|
|
@@ -28828,7 +28848,7 @@ async function rH(e, n) {
|
|
|
28828
28848
|
error: "invalid_request",
|
|
28829
28849
|
error_description: "User ID is required for user-based grants"
|
|
28830
28850
|
});
|
|
28831
|
-
t = await
|
|
28851
|
+
t = await JB(e, {
|
|
28832
28852
|
grantType: n.grantType,
|
|
28833
28853
|
tenantId: n.client.tenant.id,
|
|
28834
28854
|
userId: i,
|
|
@@ -28854,7 +28874,7 @@ async function rH(e, n) {
|
|
|
28854
28874
|
...r.app_metadata || {},
|
|
28855
28875
|
strategy: n.authStrategy.strategy
|
|
28856
28876
|
} }));
|
|
28857
|
-
let t = await
|
|
28877
|
+
let t = await SB(e, e.env.data, n.client.tenant.id, r, n.loginSession, {
|
|
28858
28878
|
client: n.client,
|
|
28859
28879
|
authParams: u,
|
|
28860
28880
|
authStrategy: n.authStrategy,
|
|
@@ -28871,21 +28891,21 @@ async function rH(e, n) {
|
|
|
28871
28891
|
}), f = i.split(" "), p = f.includes("code"), m = f.includes("id_token") || f.includes("token"), h = p && m;
|
|
28872
28892
|
if (i === At.CODE) {
|
|
28873
28893
|
if (!r || !n.loginSession) throw new k(500, { message: "User and loginSession is required for code flow" });
|
|
28874
|
-
let t = await
|
|
28894
|
+
let t = await WV(e, {
|
|
28875
28895
|
user: r,
|
|
28876
28896
|
client: n.client,
|
|
28877
28897
|
authParams: u,
|
|
28878
28898
|
login_id: n.loginSession.id
|
|
28879
28899
|
});
|
|
28880
|
-
return await
|
|
28900
|
+
return await eH(e, n.client.tenant.id, n.loginSession, d, n.loginSessionIsCurrent ? n.loginSession : void 0), t;
|
|
28881
28901
|
} else if (h) {
|
|
28882
28902
|
if (!r || !n.loginSession) throw new k(500, { message: "User and loginSession is required for hybrid flow" });
|
|
28883
|
-
let t = await
|
|
28903
|
+
let t = await WV(e, {
|
|
28884
28904
|
user: r,
|
|
28885
28905
|
client: n.client,
|
|
28886
28906
|
authParams: u,
|
|
28887
28907
|
login_id: n.loginSession.id
|
|
28888
|
-
}), i = await
|
|
28908
|
+
}), i = await UV(e, {
|
|
28889
28909
|
...n,
|
|
28890
28910
|
user: r,
|
|
28891
28911
|
authParams: u,
|
|
@@ -28893,68 +28913,68 @@ async function rH(e, n) {
|
|
|
28893
28913
|
token_lifetime: s,
|
|
28894
28914
|
code: t.code
|
|
28895
28915
|
});
|
|
28896
|
-
return await
|
|
28916
|
+
return await eH(e, n.client.tenant.id, n.loginSession, d, n.loginSessionIsCurrent ? n.loginSession : void 0), {
|
|
28897
28917
|
...i,
|
|
28898
28918
|
code: t.code,
|
|
28899
28919
|
state: t.state
|
|
28900
28920
|
};
|
|
28901
28921
|
} else {
|
|
28902
|
-
let t = await
|
|
28922
|
+
let t = await UV(e, {
|
|
28903
28923
|
...n,
|
|
28904
28924
|
user: r,
|
|
28905
28925
|
authParams: u,
|
|
28906
28926
|
permissions: o,
|
|
28907
28927
|
token_lifetime: s
|
|
28908
28928
|
});
|
|
28909
|
-
return n.loginSession && await
|
|
28929
|
+
return n.loginSession && await eH(e, n.client.tenant.id, n.loginSession, d, n.loginSessionIsCurrent ? n.loginSession : void 0), t;
|
|
28910
28930
|
}
|
|
28911
28931
|
}
|
|
28912
28932
|
//#endregion
|
|
28913
28933
|
//#region src/authentication-flows/mfa-attempts.ts
|
|
28914
|
-
var
|
|
28915
|
-
MFA_LOCKOUT_REASON: () =>
|
|
28934
|
+
var sH = /* @__PURE__ */ p({
|
|
28935
|
+
MFA_LOCKOUT_REASON: () => cH,
|
|
28916
28936
|
MFA_MAX_FAILED_ATTEMPTS: () => 5,
|
|
28917
28937
|
MFA_MAX_SMS_SENDS: () => 5,
|
|
28918
|
-
MfaSmsRateLimitError: () =>
|
|
28919
|
-
checkMfaAttemptAllowed: () =>
|
|
28920
|
-
enforceMfaSmsSendLimit: () =>
|
|
28921
|
-
isMfaLockedOut: () =>
|
|
28922
|
-
recordMfaFailure: () =>
|
|
28923
|
-
resetMfaFailures: () =>
|
|
28924
|
-
}),
|
|
28938
|
+
MfaSmsRateLimitError: () => lH,
|
|
28939
|
+
checkMfaAttemptAllowed: () => mH,
|
|
28940
|
+
enforceMfaSmsSendLimit: () => _H,
|
|
28941
|
+
isMfaLockedOut: () => fH,
|
|
28942
|
+
recordMfaFailure: () => hH,
|
|
28943
|
+
resetMfaFailures: () => gH
|
|
28944
|
+
}), cH = "too_many_mfa_failures", lH = class extends Error {
|
|
28925
28945
|
constructor() {
|
|
28926
28946
|
super("Too many MFA SMS messages sent"), this.name = "MfaSmsRateLimitError";
|
|
28927
28947
|
}
|
|
28928
28948
|
};
|
|
28929
|
-
function
|
|
28949
|
+
function uH(e) {
|
|
28930
28950
|
return typeof e == "object" && !!e && "allowed" in e && typeof e.allowed == "boolean";
|
|
28931
28951
|
}
|
|
28932
|
-
async function
|
|
28952
|
+
async function dH(e, t) {
|
|
28933
28953
|
let n = e.env.data.rateLimit;
|
|
28934
28954
|
if (!n) return !0;
|
|
28935
28955
|
try {
|
|
28936
28956
|
let e = await n.consume("brute-force", t);
|
|
28937
|
-
return
|
|
28957
|
+
return uH(e) ? e.allowed : !0;
|
|
28938
28958
|
} catch (e) {
|
|
28939
28959
|
return console.error("MFA rate limit consume failed:", e), !0;
|
|
28940
28960
|
}
|
|
28941
28961
|
}
|
|
28942
|
-
function
|
|
28962
|
+
function fH(e) {
|
|
28943
28963
|
return e.state === T.FAILED && e.failure_reason === "too_many_mfa_failures" ? !0 : (Fm(e.state_data).mfa_failed_attempts ?? 0) >= 5;
|
|
28944
28964
|
}
|
|
28945
|
-
async function
|
|
28965
|
+
async function pH(e, t, n, r, i) {
|
|
28946
28966
|
O(e, t, {
|
|
28947
28967
|
type: E.TOO_MANY_MFA_FAILURES,
|
|
28948
28968
|
description: i,
|
|
28949
28969
|
userId: r
|
|
28950
|
-
}), await
|
|
28970
|
+
}), await ZV(e, t, n, cH);
|
|
28951
28971
|
}
|
|
28952
|
-
async function
|
|
28953
|
-
return
|
|
28972
|
+
async function mH(e, t, n, r) {
|
|
28973
|
+
return fH(n) ? !1 : await dH(e, `mfa:${t}:${r}`) ? !0 : (await pH(e, t, n, r, "MFA verification rate limit exceeded"), !1);
|
|
28954
28974
|
}
|
|
28955
|
-
async function
|
|
28975
|
+
async function hH(e, t, n, r) {
|
|
28956
28976
|
let i = await e.env.data.loginSessions.get(t, n);
|
|
28957
|
-
if (!i ||
|
|
28977
|
+
if (!i || fH(i)) return { lockedOut: !0 };
|
|
28958
28978
|
let a = (Fm(i.state_data).mfa_failed_attempts ?? 0) + 1;
|
|
28959
28979
|
try {
|
|
28960
28980
|
await TO(e.env.data.loginSessions, t, n, {
|
|
@@ -28965,27 +28985,27 @@ async function fH(e, t, n, r) {
|
|
|
28965
28985
|
if (e instanceof bO) return { lockedOut: !0 };
|
|
28966
28986
|
throw e;
|
|
28967
28987
|
}
|
|
28968
|
-
return a < 5 ? { lockedOut: !1 } : (await
|
|
28988
|
+
return a < 5 ? { lockedOut: !1 } : (await pH(e, t, i, r, `Too many failed MFA attempts (${a})`), { lockedOut: !0 });
|
|
28969
28989
|
}
|
|
28970
|
-
async function
|
|
28990
|
+
async function gH(e, t, n) {
|
|
28971
28991
|
await TO(e.env.data.loginSessions, t, n, {
|
|
28972
28992
|
type: j.UPDATE_CONTEXT,
|
|
28973
28993
|
data: { mfa_failed_attempts: void 0 }
|
|
28974
28994
|
});
|
|
28975
28995
|
}
|
|
28976
|
-
async function
|
|
28996
|
+
async function _H(e, t, n, r, i) {
|
|
28977
28997
|
let a = await e.env.data.loginSessions.get(t, n);
|
|
28978
28998
|
if (a && (xO(a) || new Date(a.expires_at).getTime() < Date.now())) throw new bO(n);
|
|
28979
28999
|
let o = Fm(a?.state_data).mfa_sms_sent ?? 0, s = i ?? a?.user_id ?? r, c = () => (O(e, t, {
|
|
28980
29000
|
type: E.ERROR_SENDING_MFA_SMS,
|
|
28981
29001
|
description: "MFA SMS send limit reached",
|
|
28982
29002
|
userId: i ?? a?.user_id
|
|
28983
|
-
}), new
|
|
28984
|
-
if (o >= 5 || !await
|
|
29003
|
+
}), new lH());
|
|
29004
|
+
if (o >= 5 || !await dH(e, `mfa-sms:${t}:${s}`)) throw c();
|
|
28985
29005
|
if (!a) return;
|
|
28986
29006
|
let { status: l } = await EO(e.env.data.loginSessions, t, n, "mfa_sms_sent", 5);
|
|
28987
29007
|
if (l === "finalized") throw new bO(n);
|
|
28988
29008
|
if (l === "limit_reached" || l === "contended") throw c();
|
|
28989
29009
|
}
|
|
28990
29010
|
//#endregion
|
|
28991
|
-
export {
|
|
29011
|
+
export { AB as $, Fe as $a, Ur as $c, ss as $d, Mc as $i, ct as $l, nD as $n, E as $o, qu as $r, ko as $s, HI as $t, yt as $u, lV as A, co as Aa, tt as Ac, Xo as Ad, Fl as Ai, jt as Al, eO as An, xa as Ao, Rm as Ar, Ti as As, lR as At, bt as Au, QB as B, ps as Ba, Ct as Bc, ic as Bd, ul as Bi, w as Bl, ED as Bn, Qn as Bo, Rd as Br, Qi as Bs, zL as Bt, Ga as Bu, OV as C, Eo as Ca, Fo as Cc, wr as Cd, h as Cf, tu as Ci, it as Cl, TO as Cn, Gt as Co, R as Cr, Sc as Cs, yR as Ct, Ys as Cu, mV as D, Ds as Da, Si as Dc, Ya as Dd, Yl as Di, Bi as Dl, _O as Dn, Na as Do, j as Dr, La as Ds, mR as Dt, Ui as Du, CV as E, cr as Ea, Is as Ec, Ze as Ed, $l as Ei, C as El, hO as En, Ye as Eo, P as Er, nt as Es, gR as Et, he as Eu, $B as F, qr as Fa, _e as Fc, ro as Fd, Pl as Fi, zr as Fl, HD as Fn, yi as Fo, Id as Fr, Ts as Fs, rR as Ft, Ho as Fu, KB as G, Ee as Ga, Go as Gc, Rn as Gd, Wc as Gi, xt as Gl, jD as Gn, vo as Go, vd as Gr, Ot as Gs, kL as Gt, Ks as Gu, ZB as H, hc as Ha, Wa as Hc, lo as Hd, Zc as Hi, es as Hl, TD as Hn, si as Ho, gd as Hr, cs as Hs, TL as Ht, Pi as Hu, oV as I, kt as Ia, Ki as Ic, ve as Id, k as Ii, nc as Il, UD as In, hi as Io, Hd as Ir, ci as Is, qL as It, Tr as Iu, IB as J, Xr as Ja, ao as Jc, Mt as Jd, Vc as Ji, oe as Jl, sD as Jn, qn as Jo, sd as Jr, ta as Js, $ as Jt, Qa as Ju, WB as K, na as Ka, Or as Kc, us as Kd, Lc as Ki, b as Kl, mD as Kn, Me as Ko, cd as Kr, uo as Ks, BI as Kt, dt as Ku, iV as L, po as La, ns as Lc, qi as Ld, O as Li, St as Ll, RD as Ln, Co as Lo, Pd as Lr, Jt as Ls, KL as Lt, Hs as Lu, rV as M, $i as Ma, Rs as Mc, Xs as Md, Nl as Mi, ge as Ml, rO as Mn, ka as Mo, Ld as Mr, wo as Ms, cR as Mt, Va as Mu, cV as N, Ln as Na, wi as Nc, gt as Nd, Ml as Ni, Gi as Nl, qD as Nn, hr as No, Gd as Nr, Re as Ns, oR as Nt, ie as Nu, pV as O, ui as Oa, ms as Oc, fe as Od, Xl as Oi, Qs as Ol, uO as On, Fs as Oo, zm as Or, xr as Os, hR as Ot, $o as Ou, aV as P, ls as Pa, no as Pc, qt as Pd, Gl as Pi, ts as Pl, GD as Pn, Ns as Po, Od as Pr, _a as Ps, iR as Pt, ki as Pu, kB as Q, xo as Qa, os as Qc, Fn as Qd, jc as Qi, Ws as Ql, iD as Qn, Bt as Qo, Ju as Qr, pa as Qs, ZI as Qt, $s as Qu, eV as R, De as Ra, Br as Rc, rs as Rd, Qc as Ri, At as Rl, zD as Rn, Le as Ro, zd as Rr, so as Rs, BL as Rt, ot as Ru, kV as S, Xi as Sa, ja as Sc, Vo as Sd, g as Sf, lu as Si, Vs as Sl, EO as Sn, oi as So, z as Sr, ii as Ss, RR as St, jr as Su, TV as T, Sa as Ta, Pa as Tc, at as Td, Ql as Ti, Za as Tl, gO as Tn, Po as To, F as Tr, Ro as Ts, _R as Tt, $a as Tu, BB as U, Ft as Ua, se as Uc, we as Ud, qc as Ui, Rr as Ul, OD as Un, Kt as Uo, yd as Ur, Kr as Us, AL as Ut, Ko as Uu, XB as V, Zr as Va, x as Vc, wt as Vd, Xc as Vi, Wi as Vl, wD as Vn, ws as Vo, Fd as Vr, In as Vs, HL as Vt, ce as Vu, JB as W, fo as Wa, Ni as Wc, ea as Wd, Gc as Wi, tc as Wl, kD as Wn, Mr as Wo, hd as Wr, cc as Ws, LI as Wt, kr as Wu, FB as X, Pt as Xa, Yi as Xc, xe as Xd, Bc as Xi, Wo as Xl, aD as Xn, ni as Xo, Sd as Xr, Yr as Xs, cL as Xt, Hi as Xu, jB as Y, fc as Ya, be as Yc, oo as Yd, zc as Yi, Mi as Yl, oD as Yn, ys as Yo, xd as Yr, ds as Ys, zI as Yt, me as Yu, PB as Z, di as Za, Pn as Zc, Zi as Zd, Uc as Zi, Dr as Zl, rD as Zn, bc as Zo, ad as Zr, dc as Zs, JI as Zt, Ir as Zu, iH as _, sa as _a, Io as _c, qs as _d, li as _f, Su as _i, za as _l, JO as _n, pi as _o, xv as _r, bo as _s, hz as _t, Ge as _u, sH as a, wc as aa, Do as ac, Ha as ad, Ji as af, Yu as ai, Ii as al, UI as an, ba as ao, OS as ar, ri as as, iB as at, ti as au, zV as b, ei as ba, Ls as bc, re as bd, d as bf, pu as bi, Bo as bl, DO as bn, ha as bo, B as br, Yn as bs, PR as bt, Li as bu, YV as c, zo as ca, Os as cc, Er as cd, Hr as cf, Uu as ci, Js as cl, ZO as cn, Da as co, Wx as cr, mo as cs, sB as ct, or as cu, UV as d, Sr as da, ya as dc, ee as dd, Vi as df, ku as di, Xa as dl, ek as dn, Oo as do, Mx as dr, Un as ds, Gz as dt, oa as du, Ac as ea, Ue as ec, Oa as ed, Wr as ef, Mu as ei, oc as el, sL as en, ma as eo, IT as er, yo as es, OB as et, _o as eu, WV as f, Bs as fa, Ao as fc, Ka as fd, To as ff, Au as fi, pe as fl, GO as fn, He as fo, Wy as fr, hs as fs, Wz as ft, Wn as fu, XV as g, Ae as ga, is as gc, Ar as gd, Es as gf, Cu as gi, _t as gl, UO as gn, Qt as go, Zv as gr, Gr as gs, xz as gt, Lt as gu, ZV as h, go as ha, js as hc, qo as hd, ar as hf, wu as hi, Zs as hl, qO as hn, mi as ho, Qv as hr, It as hs, jz as ht, _c as hu, fH as i, Dc as ia, aa as ic, y as id, ye as if, zu as ii, ue as il, XI as in, Wt as io, XE as ir, bs as is, Zz as it, vs as iu, nV as j, Ce as ja, Ia as jc, Nr as jd, Hl as ji, to as jl, $D as jn, Mo as jo, Pm as jr, Ai as js, sR as jt, v as ju, uV as k, Xt as ka, Lo as kc, Ri as kd, jl as ki, vt as kl, nO as kn, xi as ko, Fm as kr, zs as ks, fR as kt, Lr as ku, nH as l, rt as la, fi as lc, Us as ld, ac as lf, Ru as li, mt as ll, QO as ln, Ms as lo, Tx as lr, Oe as ls, $z as lt, ho as lu, qV as m, sr as ma, Ea as mc, Fi as md, va as mf, Tu as mi, Pr as ml, HO as mn, ks as mo, Cy as mr, gc as ms, Fz as mt, $r as mu, mH as n, Oc as na, As as nc, Ma as nd, Dt as nf, Bu as ni, te as nl, CL as nn, Ss as no, HT as nr, da as ns, CB as nt, ca as nu, hH as o, Ec as oa, Ve as oc, ae as od, Nn as of, Fu as oi, Jo as ol, lL as on, jo as oo, Jx as or, xc as os, oB as ot, yc as ou, aH as p, Ei as pa, We as pc, le as pd, ze as pf, Eu as pi, zi as pl, WO as pn, wa as po, wy as pr, Qr as ps, zz as pt, gs as pu, HB as q, fs as qa, lt as qc, Jr as qd, Rc as qi, Ua as ql, vD as qn, la as qo, ud as qr, Te as qs, RI as qt, ut as qu, _H as r, kc as ra, gi as rc, bi as rd, io as rf, id as ri, qa as rl, QI as rn, Cc as ro, NE as rr, Jn as rs, pB as rt, Kn as ru, gH as s, Tc as sa, Ca as sc, ji as sd, as as sf, ju as si, T as sl, $O as sn, Ke as so, Kx as sr, Vt as ss, aB as st, zt as su, lH as t, Pc as ta, Ta as tc, No as td, sc as tf, Nu as ti, Et as tl, EL as tn, Xn as to, KT as tr, Ne as ts, TB as tt, je as tu, $V as u, Ra as ua, Zt as uc, st as ud, Tt as uf, Ou as ui, Qe as ul, tk as un, ua as uo, jx as ur, ia as us, Kz as ut, ke as uu, tH as v, Gn as va, $e as vc, ft as vd, Yt as vf, su as vi, ne as vl, PO as vn, So as vo, bv as vr, Pe as vs, YR as vt, Ja as vu, SV as w, Be as wa, Xe as wc, D as wd, eu as wi, et as wl, yO as wn, Aa as wo, I as wr, Ut as ws, vR as wt, ht as wu, RV as x, Rt as xa, Ci as xc, Oi as xd, p as xf, mu as xi, Cr as xl, xO as xn, Zn as xo, W_ as xr, xs, TR as xt, Yo as xu, PV as y, _s as ya, Fa as yc, Ba as yd, f as yf, gu as yi, Di as yl, bO as yn, Ie as yo, H as yr, fa as ys, HR as yt, de as yu, tV as z, ra as za, rc as zc, Vr as zd, il as zi, eo as zl, VD as zn, ga as zo, Wd as zr, Se as zs, VL as zt, S as zu };
|