@passflow/core 0.2.0 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +268 -277
- package/dist/index.mjs.map +1 -1
- package/dist/lib/api/axios-client.d.ts.map +1 -1
- package/dist/lib/api/two-factor.d.ts.map +1 -1
- package/dist/lib/m2m/client.d.ts.map +1 -1
- package/dist/lib/services/auth-service.d.ts +1 -1
- package/dist/lib/services/auth-service.d.ts.map +1 -1
- package/dist/lib/services/two-factor-service.d.ts.map +1 -1
- package/dist/{tsconfig.tsbuildinfo → tsconfig.build.tsbuildinfo} +1 -1
- package/package.json +4 -5
- package/dist/tests/storage/fake-storage.d.ts +0 -7
- package/dist/tests/storage/fake-storage.d.ts.map +0 -1
- package/dist/tests/storage/storage-manager.test.d.ts +0 -2
- package/dist/tests/storage/storage-manager.test.d.ts.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import D from "axios";
|
|
2
2
|
import { v4 as H } from "uuid";
|
|
3
3
|
import { startRegistration as K, startAuthentication as j } from "@simplewebauthn/browser";
|
|
4
|
-
const z = "0.
|
|
4
|
+
const z = "0.2.8", X = {
|
|
5
5
|
version: z
|
|
6
|
-
}, C = "X-Passflow-Clientid", _ = "Authorization", W = "X-Passflow-DeviceId", J = "X-Passflow-DeviceType", Z = X.version, Ne = ["id", "offline", "openid"], Q = ["id", "offline", "tenant", "email", "oidc", "openid", "access:tenant:all"], G = "https://auth.passflow.cloud", Ke = "default", ee = 500, te = 600, se = 100, re = 6e4, V = 30, ie = 3,
|
|
6
|
+
}, C = "X-Passflow-Clientid", _ = "Authorization", W = "X-Passflow-DeviceId", J = "X-Passflow-DeviceType", Z = X.version, Ne = ["id", "offline", "openid"], Q = ["id", "offline", "tenant", "email", "oidc", "openid", "access:tenant:all"], G = "https://auth.passflow.cloud", Ke = "default", ee = 500, te = 600, se = 100, re = 6e4, V = 30, ie = 3, ne = 30, oe = 200, ae = (i) => {
|
|
7
7
|
const e = [];
|
|
8
8
|
let t;
|
|
9
9
|
for (t in i) {
|
|
@@ -11,10 +11,10 @@ const z = "0.1.47", X = {
|
|
|
11
11
|
if (s === void 0)
|
|
12
12
|
continue;
|
|
13
13
|
const r = { tenant: { id: s.tenant_id, name: s.tenant_name } };
|
|
14
|
-
r.groups = s.groups ? Object.keys(s.groups).map((
|
|
15
|
-
const
|
|
16
|
-
return { group: { id:
|
|
17
|
-
}) : [], r.tenantRoles = r.groups?.find((
|
|
14
|
+
r.groups = s.groups ? Object.keys(s.groups).map((n) => {
|
|
15
|
+
const o = s.groups[n] || [];
|
|
16
|
+
return { group: { id: n, name: s.group_names?.[n] ?? "unknown" }, roles: o };
|
|
17
|
+
}) : [], r.tenantRoles = r.groups?.find((n) => n.group.id === s.root_group_id), e.push(r);
|
|
18
18
|
}
|
|
19
19
|
return { raw: i, tenants: e };
|
|
20
20
|
};
|
|
@@ -39,7 +39,7 @@ class he {
|
|
|
39
39
|
const t = this.storageManager.getToken(e);
|
|
40
40
|
if (!t) return !0;
|
|
41
41
|
const s = y(t);
|
|
42
|
-
return s ?
|
|
42
|
+
return s ? m(s) : !0;
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
45
|
* Parse token from storage by type.
|
|
@@ -54,19 +54,19 @@ class he {
|
|
|
54
54
|
return y(t);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
function
|
|
57
|
+
function m(i, e = V) {
|
|
58
58
|
return Math.floor(Date.now() / 1e3) + e > i.exp;
|
|
59
59
|
}
|
|
60
60
|
function y(i) {
|
|
61
61
|
const e = i.split(".")[1];
|
|
62
62
|
if (!e) throw new Error("Invalid token string");
|
|
63
|
-
const t = e.replace(/-/g, "+").replace(/_/g, "/"), s = t + "=".repeat((4 - t.length % 4) % 4), r = ce(s),
|
|
63
|
+
const t = e.replace(/-/g, "+").replace(/_/g, "/"), s = t + "=".repeat((4 - t.length % 4) % 4), r = ce(s), n = decodeURIComponent(
|
|
64
64
|
r.split("").map((d) => "%" + ("00" + d.charCodeAt(0).toString(16)).slice(-2)).join("")
|
|
65
|
-
),
|
|
66
|
-
return
|
|
65
|
+
), o = JSON.parse(n);
|
|
66
|
+
return o.membership = o.passflow_tm && o.type !== "invite" ? ae(o.passflow_tm) : void 0, o;
|
|
67
67
|
}
|
|
68
68
|
var k = /* @__PURE__ */ ((i) => (i.id_token = "id_token", i.access_token = "access", i.refresh_token = "refresh", i.invite_token = "invite", i.reset_token = "reset", i.web_cookie = "web-cookie", i.management = "management", i.signin = "signin", i.actor = "actor", i.two_factor = "2fa", i))(k || {}), v = /* @__PURE__ */ ((i) => (i.JsonBody = "json_body", i.Cookie = "cookie", i.Mobile = "mobile", i.BFF = "bff", i))(v || {}), q = /* @__PURE__ */ ((i) => (i.Unknown = "unknown", i.Valid = "valid", i.Invalid = "invalid", i))(q || {});
|
|
69
|
-
class
|
|
69
|
+
class Y {
|
|
70
70
|
constructor(e) {
|
|
71
71
|
this.storageManager = e, this.mode = "json_body", this.sessionState = "unknown", this.isInitializedFlag = !1, this.STORAGE_PREFIX = "passflow_", this.DELIVERY_MODE_KEY = `${this.STORAGE_PREFIX}delivery_mode`, this.SESSION_STATE_KEY = `${this.STORAGE_PREFIX}session_state`, this.loadPersistedMode(), this.loadPersistedSessionState();
|
|
72
72
|
}
|
|
@@ -227,8 +227,8 @@ class $ {
|
|
|
227
227
|
* In JSON mode: save all tokens (existing behavior)
|
|
228
228
|
*/
|
|
229
229
|
saveTokens(e, t) {
|
|
230
|
-
const { id_token: s, access_token: r, refresh_token:
|
|
231
|
-
t === v.Cookie || t === v.BFF ? s && this.storage.setItem(this.ID_TOKEN_KEY, s) : (s && this.storage.setItem(this.getKeyForTokenType(k.id_token), s), r && this.storage.setItem(this.getKeyForTokenType(k.access_token), r),
|
|
230
|
+
const { id_token: s, access_token: r, refresh_token: n, scopes: o } = e;
|
|
231
|
+
t === v.Cookie || t === v.BFF ? s && this.storage.setItem(this.ID_TOKEN_KEY, s) : (s && this.storage.setItem(this.getKeyForTokenType(k.id_token), s), r && this.storage.setItem(this.getKeyForTokenType(k.access_token), r), n && this.storage.setItem(this.getKeyForTokenType(k.refresh_token), n), o && this.storage.setItem(this.scopes, o.join(",")));
|
|
232
232
|
}
|
|
233
233
|
getToken(e) {
|
|
234
234
|
const t = this.getKeyForTokenType(e);
|
|
@@ -386,7 +386,7 @@ class $ {
|
|
|
386
386
|
return `${this.keyStoragePrefix}${e}`;
|
|
387
387
|
}
|
|
388
388
|
}
|
|
389
|
-
class
|
|
389
|
+
class B {
|
|
390
390
|
constructor(e) {
|
|
391
391
|
this.storageManager = e ?? new $();
|
|
392
392
|
}
|
|
@@ -423,12 +423,12 @@ class T {
|
|
|
423
423
|
Accept: "application/json",
|
|
424
424
|
"Content-Type": "application/json"
|
|
425
425
|
}, this.nonAccessTokenEndpoints = ["/auth/", "/settings", "/settings/"], this.protectedEndpoints = ["logout", "refresh"];
|
|
426
|
-
const { url: r, appId:
|
|
426
|
+
const { url: r, appId: n, keyStoragePrefix: o } = e;
|
|
427
427
|
this.url = r || G, this.storageManager = t ?? new $({
|
|
428
|
-
prefix:
|
|
429
|
-
}), this.deviceService = s ?? new
|
|
428
|
+
prefix: o ?? ""
|
|
429
|
+
}), this.deviceService = s ?? new B(this.storageManager), this.tokenService = new he(this.storageManager), this.tokenDeliveryManager = new Y(this.storageManager), n && (this.appId = n, this.defaultHeaders = {
|
|
430
430
|
...this.defaultHeaders,
|
|
431
|
-
[C]:
|
|
431
|
+
[C]: n
|
|
432
432
|
});
|
|
433
433
|
const d = this.deviceService.getDeviceId();
|
|
434
434
|
this.defaultHeaders = {
|
|
@@ -456,7 +456,7 @@ class T {
|
|
|
456
456
|
const g = this.storageManager.getTokens();
|
|
457
457
|
if (g?.access_token) {
|
|
458
458
|
const p = y(g.access_token);
|
|
459
|
-
if (
|
|
459
|
+
if (m(p, V) && g.refresh_token)
|
|
460
460
|
try {
|
|
461
461
|
if (this.refreshPromise) {
|
|
462
462
|
const f = await this.refreshPromise;
|
|
@@ -495,7 +495,7 @@ class T {
|
|
|
495
495
|
try {
|
|
496
496
|
document.cookie = "passflow_test=1; SameSite=Lax";
|
|
497
497
|
const e = document.cookie.indexOf("passflow_test=1") !== -1;
|
|
498
|
-
document.cookie = "passflow_test=; expires=Thu, 01 Jan 1970 00:00:00 UTC", !e && this.tokenDeliveryManager.isCookieMode()
|
|
498
|
+
document.cookie = "passflow_test=; expires=Thu, 01 Jan 1970 00:00:00 UTC", !e && this.tokenDeliveryManager.isCookieMode();
|
|
499
499
|
} catch {
|
|
500
500
|
}
|
|
501
501
|
}
|
|
@@ -535,21 +535,21 @@ class T {
|
|
|
535
535
|
const s = t.method?.toUpperCase();
|
|
536
536
|
if (!["GET", "HEAD", "OPTIONS"].includes(s || ""))
|
|
537
537
|
return Promise.reject(e);
|
|
538
|
-
const
|
|
539
|
-
if (
|
|
538
|
+
const n = t._retryCount || 0;
|
|
539
|
+
if (n >= le)
|
|
540
540
|
return Promise.reject(e);
|
|
541
|
-
let
|
|
541
|
+
let o = ge * Math.pow(2, n);
|
|
542
542
|
const d = e.response?.headers?.["retry-after"];
|
|
543
543
|
if (d) {
|
|
544
544
|
const c = Number.parseInt(d, 10);
|
|
545
545
|
if (!Number.isNaN(c))
|
|
546
|
-
|
|
546
|
+
o = c * 1e3;
|
|
547
547
|
else {
|
|
548
548
|
const g = new Date(d);
|
|
549
|
-
Number.isNaN(g.getTime()) || (
|
|
549
|
+
Number.isNaN(g.getTime()) || (o = Math.max(0, g.getTime() - Date.now()));
|
|
550
550
|
}
|
|
551
551
|
}
|
|
552
|
-
return await new Promise((c) => setTimeout(c,
|
|
552
|
+
return await new Promise((c) => setTimeout(c, o)), t._retryCount = n + 1, this.instance.request(t);
|
|
553
553
|
}
|
|
554
554
|
// eslint-disable-next-line complexity
|
|
555
555
|
// biome-ignore lint/suspicious/useAwait: <explanation>
|
|
@@ -658,7 +658,7 @@ class fe {
|
|
|
658
658
|
);
|
|
659
659
|
}
|
|
660
660
|
passwordlessSignIn(e, t, s) {
|
|
661
|
-
const { create_tenant: r } = e,
|
|
661
|
+
const { create_tenant: r } = e, n = {
|
|
662
662
|
...e,
|
|
663
663
|
create_tenant: r ?? !1,
|
|
664
664
|
device: t,
|
|
@@ -666,7 +666,7 @@ class fe {
|
|
|
666
666
|
};
|
|
667
667
|
return this.axiosClient.post(
|
|
668
668
|
h.passwordless,
|
|
669
|
-
|
|
669
|
+
n
|
|
670
670
|
);
|
|
671
671
|
}
|
|
672
672
|
passwordlessSignInComplete(e) {
|
|
@@ -676,8 +676,8 @@ class fe {
|
|
|
676
676
|
);
|
|
677
677
|
}
|
|
678
678
|
logOut(e, t, s = !1) {
|
|
679
|
-
const r = s ? void 0 : { refresh_token: t, device: e },
|
|
680
|
-
return this.axiosClient.post(
|
|
679
|
+
const r = s ? void 0 : { refresh_token: t, device: e }, n = s ? w.logout : h.logout;
|
|
680
|
+
return this.axiosClient.post(n, r);
|
|
681
681
|
}
|
|
682
682
|
validateSession() {
|
|
683
683
|
return this.axiosClient.get(h.validateSession);
|
|
@@ -701,52 +701,52 @@ class fe {
|
|
|
701
701
|
});
|
|
702
702
|
}
|
|
703
703
|
passkeyRegisterStart(e, t, s, r = !1) {
|
|
704
|
-
const { create_tenant:
|
|
704
|
+
const { create_tenant: n } = e, o = {
|
|
705
705
|
...e,
|
|
706
|
-
create_tenant:
|
|
706
|
+
create_tenant: n ?? !1,
|
|
707
707
|
device: t,
|
|
708
708
|
os: s
|
|
709
709
|
}, d = r ? w.passkeyRegisterStart : h.passkeyRegisterStart;
|
|
710
|
-
return this.axiosClient.post(d,
|
|
710
|
+
return this.axiosClient.post(d, o);
|
|
711
711
|
}
|
|
712
712
|
passkeyRegisterComplete(e, t, s, r = !1) {
|
|
713
|
-
const
|
|
713
|
+
const n = {
|
|
714
714
|
challenge_id: s,
|
|
715
715
|
device: t,
|
|
716
716
|
passkey_data: e
|
|
717
|
-
},
|
|
718
|
-
return this.axiosClient.post(
|
|
717
|
+
}, o = r ? w.passkeyRegisterComplete : h.passkeyRegisterComplete;
|
|
718
|
+
return this.axiosClient.post(o, n);
|
|
719
719
|
}
|
|
720
720
|
passkeyAuthenticateStart(e, t, s, r = !1) {
|
|
721
|
-
const
|
|
721
|
+
const n = {
|
|
722
722
|
...e,
|
|
723
723
|
user_id: e.user_id ?? "",
|
|
724
724
|
device: t,
|
|
725
725
|
os: s
|
|
726
|
-
},
|
|
726
|
+
}, o = r ? w.passkeyAuthenticateStart : h.passkeyAuthenticateStart;
|
|
727
727
|
return this.axiosClient.post(
|
|
728
|
-
|
|
729
|
-
|
|
728
|
+
o,
|
|
729
|
+
n
|
|
730
730
|
);
|
|
731
731
|
}
|
|
732
732
|
passkeyAuthenticateComplete(e, t, s, r = !1) {
|
|
733
|
-
const
|
|
733
|
+
const n = {
|
|
734
734
|
challenge_id: s,
|
|
735
735
|
device: t,
|
|
736
736
|
passkey_data: e
|
|
737
|
-
},
|
|
738
|
-
return this.axiosClient.post(
|
|
737
|
+
}, o = r ? w.passkeyAuthenticateComplete : h.passkeyAuthenticateComplete;
|
|
738
|
+
return this.axiosClient.post(o, n);
|
|
739
739
|
}
|
|
740
|
-
passkeyValidate(e, t, s, r = !1,
|
|
741
|
-
const
|
|
740
|
+
passkeyValidate(e, t, s, r = !1, n) {
|
|
741
|
+
const o = {
|
|
742
742
|
otp: e,
|
|
743
743
|
device: t,
|
|
744
744
|
challenge_id: s
|
|
745
745
|
};
|
|
746
746
|
let d = h.passkeyValidate;
|
|
747
|
-
!
|
|
748
|
-
const c =
|
|
749
|
-
return this.axiosClient.post(d,
|
|
747
|
+
!n && r && (d = w.passkeyValidate);
|
|
748
|
+
const c = n ? { [C]: n } : {};
|
|
749
|
+
return this.axiosClient.post(d, o, { headers: c });
|
|
750
750
|
}
|
|
751
751
|
}
|
|
752
752
|
class ke {
|
|
@@ -918,8 +918,8 @@ class ve {
|
|
|
918
918
|
* @param name New group name
|
|
919
919
|
*/
|
|
920
920
|
updateGroup(e, t, s) {
|
|
921
|
-
const r = `${h.tenantPath}/${e}/group/${t}`,
|
|
922
|
-
return this.axiosClient.put(r,
|
|
921
|
+
const r = `${h.tenantPath}/${e}/group/${t}`, n = { name: s };
|
|
922
|
+
return this.axiosClient.put(r, n);
|
|
923
923
|
}
|
|
924
924
|
/**
|
|
925
925
|
* Delete a group
|
|
@@ -938,8 +938,8 @@ class ve {
|
|
|
938
938
|
* @param role Role to assign
|
|
939
939
|
*/
|
|
940
940
|
addUserToGroup(e, t, s, r) {
|
|
941
|
-
const
|
|
942
|
-
return this.axiosClient.post(
|
|
941
|
+
const n = `${h.tenantPath}/${e}/group/${t}/add`, o = { user_id: s, role: r };
|
|
942
|
+
return this.axiosClient.post(n, o);
|
|
943
943
|
}
|
|
944
944
|
/**
|
|
945
945
|
* Remove user roles from a group
|
|
@@ -949,8 +949,8 @@ class ve {
|
|
|
949
949
|
* @param roles Roles to remove
|
|
950
950
|
*/
|
|
951
951
|
removeUserRolesFromGroup(e, t, s, r) {
|
|
952
|
-
const
|
|
953
|
-
return this.axiosClient.post(
|
|
952
|
+
const n = `${h.tenantPath}/${e}/group/${t}/remove_roles`, o = { user_id: s, roles: r };
|
|
953
|
+
return this.axiosClient.post(n, o);
|
|
954
954
|
}
|
|
955
955
|
/**
|
|
956
956
|
* Change user roles in a group
|
|
@@ -960,8 +960,8 @@ class ve {
|
|
|
960
960
|
* @param roles New roles to assign
|
|
961
961
|
*/
|
|
962
962
|
changeUserRoles(e, t, s, r) {
|
|
963
|
-
const
|
|
964
|
-
return this.axiosClient.post(
|
|
963
|
+
const n = `${h.tenantPath}/${e}/group/${t}/change`, o = { user_id: s, roles: r };
|
|
964
|
+
return this.axiosClient.post(n, o);
|
|
965
965
|
}
|
|
966
966
|
/**
|
|
967
967
|
* Delete a user from a group
|
|
@@ -998,8 +998,8 @@ class ve {
|
|
|
998
998
|
* @param name New role name
|
|
999
999
|
*/
|
|
1000
1000
|
updateRole(e, t, s) {
|
|
1001
|
-
const r = `${h.tenantPath}/${e}/role/${t}`,
|
|
1002
|
-
return this.axiosClient.put(r,
|
|
1001
|
+
const r = `${h.tenantPath}/${e}/role/${t}`, n = { name: s };
|
|
1002
|
+
return this.axiosClient.put(r, n);
|
|
1003
1003
|
}
|
|
1004
1004
|
/**
|
|
1005
1005
|
* Delete a role
|
|
@@ -1029,8 +1029,8 @@ class ve {
|
|
|
1029
1029
|
* @param skip Number of invitations to skip
|
|
1030
1030
|
*/
|
|
1031
1031
|
getGroupInvitations(e, t, s, r) {
|
|
1032
|
-
const
|
|
1033
|
-
return this.axiosClient.get(
|
|
1032
|
+
const n = `${h.tenantPath}/${e}/group/${t}/invitations`;
|
|
1033
|
+
return this.axiosClient.get(n, {
|
|
1034
1034
|
params: { limit: s, skip: r }
|
|
1035
1035
|
});
|
|
1036
1036
|
}
|
|
@@ -1067,7 +1067,7 @@ class ve {
|
|
|
1067
1067
|
return this.axiosClient.delete(r);
|
|
1068
1068
|
}
|
|
1069
1069
|
}
|
|
1070
|
-
class
|
|
1070
|
+
class me {
|
|
1071
1071
|
constructor(e, t, s) {
|
|
1072
1072
|
this.axiosClient = new T(e, t, s);
|
|
1073
1073
|
}
|
|
@@ -1172,21 +1172,24 @@ class Se {
|
|
|
1172
1172
|
transformRequest: [
|
|
1173
1173
|
(s, r) => (r && delete r.Authorization, s)
|
|
1174
1174
|
]
|
|
1175
|
-
}).then((s) =>
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1175
|
+
}).then((s) => {
|
|
1176
|
+
const r = s;
|
|
1177
|
+
return {
|
|
1178
|
+
success: !0,
|
|
1179
|
+
sessionToken: r.session_token,
|
|
1180
|
+
userId: r.user_id,
|
|
1181
|
+
expiresIn: r.expires_in,
|
|
1182
|
+
appId: r.app_id
|
|
1183
|
+
};
|
|
1184
|
+
}).catch((s) => {
|
|
1182
1185
|
if (s.response) {
|
|
1183
|
-
const r = s.response.status,
|
|
1186
|
+
const r = s.response.status, n = s.response.data || {}, o = s.response.headers?.["retry-after"] ? parseInt(s.response.headers["retry-after"], 10) : void 0;
|
|
1184
1187
|
return {
|
|
1185
1188
|
success: !1,
|
|
1186
1189
|
error: {
|
|
1187
|
-
code:
|
|
1188
|
-
message:
|
|
1189
|
-
retryAfter:
|
|
1190
|
+
code: n.error || this.mapStatusToErrorCode(r),
|
|
1191
|
+
message: n.message || this.getDefaultErrorMessage(r),
|
|
1192
|
+
retryAfter: o
|
|
1190
1193
|
}
|
|
1191
1194
|
};
|
|
1192
1195
|
}
|
|
@@ -1234,7 +1237,7 @@ class Se {
|
|
|
1234
1237
|
}
|
|
1235
1238
|
}
|
|
1236
1239
|
}
|
|
1237
|
-
class
|
|
1240
|
+
class Se {
|
|
1238
1241
|
constructor(e, t, s) {
|
|
1239
1242
|
this.axiosClient = new T(e, t, s);
|
|
1240
1243
|
}
|
|
@@ -1260,16 +1263,16 @@ class me {
|
|
|
1260
1263
|
deviceId: t,
|
|
1261
1264
|
os: s,
|
|
1262
1265
|
passkeyDisplayName: r,
|
|
1263
|
-
passkeyUsername:
|
|
1266
|
+
passkeyUsername: n
|
|
1264
1267
|
}) {
|
|
1265
|
-
const
|
|
1268
|
+
const o = {
|
|
1266
1269
|
passkey_display_name: r,
|
|
1267
|
-
passkey_username:
|
|
1270
|
+
passkey_username: n,
|
|
1268
1271
|
relying_party_id: e,
|
|
1269
1272
|
deviceId: t,
|
|
1270
1273
|
os: s
|
|
1271
1274
|
};
|
|
1272
|
-
return this.axiosClient.post(h.addUserPasskey,
|
|
1275
|
+
return this.axiosClient.post(h.addUserPasskey, o);
|
|
1273
1276
|
}
|
|
1274
1277
|
addUserPasskeyComplete(e, t, s) {
|
|
1275
1278
|
return this.axiosClient.post(h.completeAddUserPasskey, {
|
|
@@ -1320,7 +1323,7 @@ class we {
|
|
|
1320
1323
|
});
|
|
1321
1324
|
}
|
|
1322
1325
|
}
|
|
1323
|
-
function
|
|
1326
|
+
function M(i) {
|
|
1324
1327
|
if (!i || typeof i != "string") return !1;
|
|
1325
1328
|
const e = i.split(".");
|
|
1326
1329
|
if (e.length !== 3) return !1;
|
|
@@ -1328,9 +1331,9 @@ function F(i) {
|
|
|
1328
1331
|
return e.every((s) => t.test(s) && s.length > 0);
|
|
1329
1332
|
}
|
|
1330
1333
|
function Te(i) {
|
|
1331
|
-
return i.replace(/<[^>]*>/g, "").substring(0,
|
|
1334
|
+
return i.replace(/<[^>]*>/g, "").substring(0, oe);
|
|
1332
1335
|
}
|
|
1333
|
-
function
|
|
1336
|
+
function F(i) {
|
|
1334
1337
|
if (!i || typeof i != "string") return !1;
|
|
1335
1338
|
const e = i.trim();
|
|
1336
1339
|
return e.length === 0 ? !1 : /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e);
|
|
@@ -1343,7 +1346,7 @@ function x(i) {
|
|
|
1343
1346
|
function Ee(i) {
|
|
1344
1347
|
if (!i || typeof i != "string") return !1;
|
|
1345
1348
|
const e = i.trim();
|
|
1346
|
-
return e.length < ie || e.length >
|
|
1349
|
+
return e.length < ie || e.length > ne ? !1 : /^[a-zA-Z0-9_-]+$/.test(e);
|
|
1347
1350
|
}
|
|
1348
1351
|
function R(i, e = 6) {
|
|
1349
1352
|
return !i || typeof i != "string" ? !1 : (e === 8 ? /^\d{8}$/ : /^\d{6}$/).test(i);
|
|
@@ -1354,8 +1357,8 @@ function _e(i) {
|
|
|
1354
1357
|
return /^[A-Z0-9-]{4,16}$/.test(e) ? e : null;
|
|
1355
1358
|
}
|
|
1356
1359
|
class Ie {
|
|
1357
|
-
constructor(e, t, s, r,
|
|
1358
|
-
this.authApi = e, this.deviceService = t, this.storageManager = s, this.subscribeStore = r, this.tokenCacheService =
|
|
1360
|
+
constructor(e, t, s, r, n, o, d, c, g, p, f, b) {
|
|
1361
|
+
this.authApi = e, this.deviceService = t, this.storageManager = s, this.subscribeStore = r, this.tokenCacheService = n, this.scopes = o, this.createTenantForNewUser = d, this.origin = c, this.url = g, this.sessionCallbacks = p, this.appId = f, this.tokenExchangeConfig = b, this.tokenDeliveryManager = new Y(s), b?.enabled && this.tokenDeliveryManager.setMode(v.BFF), this.initializeSession();
|
|
1359
1362
|
}
|
|
1360
1363
|
/**
|
|
1361
1364
|
* Initialize session state on page load for cookie/BFF mode
|
|
@@ -1401,61 +1404,52 @@ class Ie {
|
|
|
1401
1404
|
* Forward tokens to BFF server for httpOnly cookie storage
|
|
1402
1405
|
*/
|
|
1403
1406
|
async forwardTokensToBFF(e) {
|
|
1404
|
-
if (!this.tokenExchangeConfig?.callbackUrl)
|
|
1405
|
-
console.warn("[Passflow SDK] BFF mode enabled but callbackUrl not configured");
|
|
1407
|
+
if (!this.tokenExchangeConfig?.callbackUrl)
|
|
1406
1408
|
return;
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
});
|
|
1424
|
-
if (!t.ok) {
|
|
1425
|
-
const s = await t.text();
|
|
1426
|
-
throw console.error("[Passflow SDK] Failed to forward tokens to BFF:", s), new Error(`BFF token storage failed: ${t.status}`);
|
|
1427
|
-
}
|
|
1428
|
-
console.log("[Passflow SDK] Tokens forwarded to BFF successfully");
|
|
1429
|
-
} catch (t) {
|
|
1430
|
-
throw console.error("[Passflow SDK] Error forwarding tokens to BFF:", t), t;
|
|
1431
|
-
}
|
|
1409
|
+
const t = await fetch(this.tokenExchangeConfig.callbackUrl, {
|
|
1410
|
+
method: "POST",
|
|
1411
|
+
credentials: "include",
|
|
1412
|
+
// Include/set httpOnly cookies
|
|
1413
|
+
headers: {
|
|
1414
|
+
"Content-Type": "application/json"
|
|
1415
|
+
},
|
|
1416
|
+
body: JSON.stringify({
|
|
1417
|
+
access_token: e.access_token,
|
|
1418
|
+
refresh_token: e.refresh_token,
|
|
1419
|
+
id_token: e.id_token,
|
|
1420
|
+
// expires_in is returned by the server but not typed in the SDK
|
|
1421
|
+
expires_in: e.expires_in
|
|
1422
|
+
})
|
|
1423
|
+
});
|
|
1424
|
+
if (!t.ok)
|
|
1425
|
+
throw new Error(`BFF token storage failed: ${t.status}`);
|
|
1432
1426
|
}
|
|
1433
1427
|
async signIn(e) {
|
|
1434
|
-
if ("email" in e && e.email && !
|
|
1435
|
-
const r = new Error("Invalid email format"),
|
|
1428
|
+
if ("email" in e && e.email && !F(e.email)) {
|
|
1429
|
+
const r = new Error("Invalid email format"), n = {
|
|
1436
1430
|
message: "Invalid email format",
|
|
1437
1431
|
originalError: r,
|
|
1438
1432
|
code: "VALIDATION_ERROR"
|
|
1439
1433
|
};
|
|
1440
|
-
throw this.subscribeStore.notify(a.Error,
|
|
1434
|
+
throw this.subscribeStore.notify(a.Error, n), r;
|
|
1441
1435
|
}
|
|
1442
1436
|
if ("username" in e && e.username && !Ee(e.username)) {
|
|
1443
1437
|
const r = new Error(
|
|
1444
1438
|
"Invalid username format. Username must be 3-30 characters and contain only letters, numbers, underscores, and hyphens"
|
|
1445
|
-
),
|
|
1439
|
+
), n = {
|
|
1446
1440
|
message: "Invalid username format. Username must be 3-30 characters and contain only letters, numbers, underscores, and hyphens",
|
|
1447
1441
|
originalError: r,
|
|
1448
1442
|
code: "VALIDATION_ERROR"
|
|
1449
1443
|
};
|
|
1450
|
-
throw this.subscribeStore.notify(a.Error,
|
|
1444
|
+
throw this.subscribeStore.notify(a.Error, n), r;
|
|
1451
1445
|
}
|
|
1452
1446
|
if ("phone" in e && e.phone && !x(e.phone)) {
|
|
1453
|
-
const r = new Error("Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)"),
|
|
1447
|
+
const r = new Error("Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)"), n = {
|
|
1454
1448
|
message: "Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)",
|
|
1455
1449
|
originalError: r,
|
|
1456
1450
|
code: "VALIDATION_ERROR"
|
|
1457
1451
|
};
|
|
1458
|
-
throw this.subscribeStore.notify(a.Error,
|
|
1452
|
+
throw this.subscribeStore.notify(a.Error, n), r;
|
|
1459
1453
|
}
|
|
1460
1454
|
this.subscribeStore.notify(a.SignInStart, { email: e.email });
|
|
1461
1455
|
const t = this.deviceService.getDeviceId(), s = I.web;
|
|
@@ -1471,16 +1465,16 @@ class Ie {
|
|
|
1471
1465
|
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
1472
1466
|
}), await this.submitSessionCheck(), r);
|
|
1473
1467
|
} catch (r) {
|
|
1474
|
-
const
|
|
1468
|
+
const n = {
|
|
1475
1469
|
message: r instanceof Error ? r.message : "Sign in failed",
|
|
1476
1470
|
originalError: r,
|
|
1477
1471
|
code: r instanceof u ? r.id : void 0
|
|
1478
1472
|
};
|
|
1479
|
-
throw this.subscribeStore.notify(a.Error,
|
|
1473
|
+
throw this.subscribeStore.notify(a.Error, n), r;
|
|
1480
1474
|
}
|
|
1481
1475
|
}
|
|
1482
1476
|
async signUp(e) {
|
|
1483
|
-
if (e.user.email && !
|
|
1477
|
+
if (e.user.email && !F(e.user.email)) {
|
|
1484
1478
|
const t = new Error("Invalid email format"), s = {
|
|
1485
1479
|
message: "Invalid email format",
|
|
1486
1480
|
originalError: t,
|
|
@@ -1513,33 +1507,33 @@ class Ie {
|
|
|
1513
1507
|
}
|
|
1514
1508
|
}
|
|
1515
1509
|
async passwordlessSignIn(e) {
|
|
1516
|
-
if (e.email && !
|
|
1517
|
-
const r = new Error("Invalid email format"),
|
|
1510
|
+
if (e.email && !F(e.email)) {
|
|
1511
|
+
const r = new Error("Invalid email format"), n = {
|
|
1518
1512
|
message: "Invalid email format",
|
|
1519
1513
|
originalError: r,
|
|
1520
1514
|
code: "VALIDATION_ERROR"
|
|
1521
1515
|
};
|
|
1522
|
-
throw this.subscribeStore.notify(a.Error,
|
|
1516
|
+
throw this.subscribeStore.notify(a.Error, n), r;
|
|
1523
1517
|
}
|
|
1524
1518
|
if (e.phone && !x(e.phone)) {
|
|
1525
|
-
const r = new Error("Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)"),
|
|
1519
|
+
const r = new Error("Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)"), n = {
|
|
1526
1520
|
message: "Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)",
|
|
1527
1521
|
originalError: r,
|
|
1528
1522
|
code: "VALIDATION_ERROR"
|
|
1529
1523
|
};
|
|
1530
|
-
throw this.subscribeStore.notify(a.Error,
|
|
1524
|
+
throw this.subscribeStore.notify(a.Error, n), r;
|
|
1531
1525
|
}
|
|
1532
1526
|
this.subscribeStore.notify(a.SignInStart, { email: e.email }), e.scopes = e.scopes ?? this.scopes;
|
|
1533
1527
|
const t = this.deviceService.getDeviceId(), s = I.web;
|
|
1534
1528
|
try {
|
|
1535
1529
|
return await this.authApi.passwordlessSignIn(e, t, s);
|
|
1536
1530
|
} catch (r) {
|
|
1537
|
-
const
|
|
1531
|
+
const n = {
|
|
1538
1532
|
message: r instanceof Error ? r.message : "Failed to send passwordless sign-in link",
|
|
1539
1533
|
originalError: r,
|
|
1540
1534
|
code: r instanceof u ? r.id : void 0
|
|
1541
1535
|
};
|
|
1542
|
-
throw this.subscribeStore.notify(a.Error,
|
|
1536
|
+
throw this.subscribeStore.notify(a.Error, n), r;
|
|
1543
1537
|
}
|
|
1544
1538
|
}
|
|
1545
1539
|
async passwordlessSignInComplete(e) {
|
|
@@ -1562,22 +1556,19 @@ class Ie {
|
|
|
1562
1556
|
async logOut() {
|
|
1563
1557
|
if (this.tokenDeliveryManager.isBFFMode() && this.tokenExchangeConfig?.logoutUrl)
|
|
1564
1558
|
try {
|
|
1565
|
-
|
|
1559
|
+
(await fetch(this.tokenExchangeConfig.logoutUrl, {
|
|
1566
1560
|
method: "POST",
|
|
1567
1561
|
credentials: "include"
|
|
1568
1562
|
// Include httpOnly cookies
|
|
1569
|
-
});
|
|
1570
|
-
|
|
1571
|
-
} catch (e) {
|
|
1572
|
-
console.warn("[Passflow SDK] BFF logout error:", e);
|
|
1563
|
+
})).ok;
|
|
1564
|
+
} catch {
|
|
1573
1565
|
}
|
|
1574
1566
|
else {
|
|
1575
1567
|
const e = this.storageManager.getToken(k.refresh_token), t = this.storageManager.getDeviceId();
|
|
1576
1568
|
try {
|
|
1577
1569
|
if ((await this.authApi.logOut(t, e, !this.appId)).status !== "ok")
|
|
1578
1570
|
throw new Error("Logout failed");
|
|
1579
|
-
} catch
|
|
1580
|
-
console.warn("[Passflow SDK] Logout API failed, clearing local state anyway:", s);
|
|
1571
|
+
} catch {
|
|
1581
1572
|
}
|
|
1582
1573
|
}
|
|
1583
1574
|
this.storageManager.deleteTokens(), this.storageManager.clearIdToken(), this.storageManager.clearCsrfToken(), this.tokenDeliveryManager.reset(), this.subscribeStore.notify(a.SignOut, {});
|
|
@@ -1671,20 +1662,20 @@ class Ie {
|
|
|
1671
1662
|
}
|
|
1672
1663
|
async resetPassword(e, t) {
|
|
1673
1664
|
this.subscribeStore.notify(a.SignInStart, {});
|
|
1674
|
-
const r = new URLSearchParams(window.location.search).get("token") ?? void 0,
|
|
1665
|
+
const r = new URLSearchParams(window.location.search).get("token") ?? void 0, n = t ?? this.scopes;
|
|
1675
1666
|
try {
|
|
1676
|
-
const
|
|
1677
|
-
return await this.processAuthResponse(
|
|
1678
|
-
tokens:
|
|
1667
|
+
const o = await this.authApi.resetPassword(e, n, r);
|
|
1668
|
+
return await this.processAuthResponse(o, n), this.subscribeStore.notify(a.SignIn, {
|
|
1669
|
+
tokens: o,
|
|
1679
1670
|
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
1680
|
-
}), await this.submitSessionCheck(),
|
|
1681
|
-
} catch (
|
|
1671
|
+
}), await this.submitSessionCheck(), o;
|
|
1672
|
+
} catch (o) {
|
|
1682
1673
|
const d = {
|
|
1683
|
-
message:
|
|
1684
|
-
originalError:
|
|
1685
|
-
code:
|
|
1674
|
+
message: o instanceof Error ? o.message : "Password reset failed",
|
|
1675
|
+
originalError: o,
|
|
1676
|
+
code: o instanceof u ? o.id : void 0
|
|
1686
1677
|
};
|
|
1687
|
-
throw this.subscribeStore.notify(a.Error, d),
|
|
1678
|
+
throw this.subscribeStore.notify(a.Error, d), o;
|
|
1688
1679
|
}
|
|
1689
1680
|
}
|
|
1690
1681
|
async passkeyRegister(e) {
|
|
@@ -1692,12 +1683,12 @@ class Ie {
|
|
|
1692
1683
|
const t = this.deviceService.getDeviceId(), s = I.web;
|
|
1693
1684
|
e.scopes = e.scopes ?? this.scopes, e.create_tenant = this.createTenantForNewUser;
|
|
1694
1685
|
try {
|
|
1695
|
-
const { challenge_id: r, publicKey:
|
|
1696
|
-
|
|
1697
|
-
const
|
|
1698
|
-
optionsJSON:
|
|
1686
|
+
const { challenge_id: r, publicKey: n } = await this.authApi.passkeyRegisterStart(e, t, s, !this.appId);
|
|
1687
|
+
n.user.id = btoa(n.user.id);
|
|
1688
|
+
const o = await K({
|
|
1689
|
+
optionsJSON: n
|
|
1699
1690
|
}), d = await this.authApi.passkeyRegisterComplete(
|
|
1700
|
-
|
|
1691
|
+
o,
|
|
1701
1692
|
t,
|
|
1702
1693
|
r,
|
|
1703
1694
|
!this.appId
|
|
@@ -1707,12 +1698,12 @@ class Ie {
|
|
|
1707
1698
|
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
1708
1699
|
}), await this.submitSessionCheck(), d;
|
|
1709
1700
|
} catch (r) {
|
|
1710
|
-
const
|
|
1701
|
+
const n = {
|
|
1711
1702
|
message: r instanceof Error ? r.message : "Passkey registration failed",
|
|
1712
1703
|
originalError: r,
|
|
1713
1704
|
code: r instanceof u ? r.id : void 0
|
|
1714
1705
|
};
|
|
1715
|
-
throw this.subscribeStore.notify(a.Error,
|
|
1706
|
+
throw this.subscribeStore.notify(a.Error, n), r;
|
|
1716
1707
|
}
|
|
1717
1708
|
}
|
|
1718
1709
|
async passkeyAuthenticate(e) {
|
|
@@ -1720,10 +1711,10 @@ class Ie {
|
|
|
1720
1711
|
const t = this.deviceService.getDeviceId(), s = I.web;
|
|
1721
1712
|
e.scopes = e.scopes ?? this.scopes;
|
|
1722
1713
|
try {
|
|
1723
|
-
const { challenge_id: r, publicKey:
|
|
1724
|
-
optionsJSON:
|
|
1714
|
+
const { challenge_id: r, publicKey: n } = await this.authApi.passkeyAuthenticateStart(e, t, s, !this.appId), o = await j({
|
|
1715
|
+
optionsJSON: n
|
|
1725
1716
|
}), d = await this.authApi.passkeyAuthenticateComplete(
|
|
1726
|
-
|
|
1717
|
+
o,
|
|
1727
1718
|
t,
|
|
1728
1719
|
r,
|
|
1729
1720
|
!this.appId
|
|
@@ -1733,12 +1724,12 @@ class Ie {
|
|
|
1733
1724
|
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
1734
1725
|
}), await this.submitSessionCheck()), d;
|
|
1735
1726
|
} catch (r) {
|
|
1736
|
-
const
|
|
1727
|
+
const n = {
|
|
1737
1728
|
message: r instanceof Error ? r.message : "Passkey authentication failed",
|
|
1738
1729
|
originalError: r,
|
|
1739
1730
|
code: r instanceof u ? r.id : void 0
|
|
1740
1731
|
};
|
|
1741
|
-
throw this.subscribeStore.notify(a.Error,
|
|
1732
|
+
throw this.subscribeStore.notify(a.Error, n), r;
|
|
1742
1733
|
}
|
|
1743
1734
|
}
|
|
1744
1735
|
createFederatedAuthUrl(e) {
|
|
@@ -1751,18 +1742,18 @@ class Ie {
|
|
|
1751
1742
|
...e.invite_token ? { invite_token: e.invite_token } : {},
|
|
1752
1743
|
...e.create_tenant ? { create_tenant: e.create_tenant.toString() } : {},
|
|
1753
1744
|
...e.device ? { device: e.device } : {}
|
|
1754
|
-
},
|
|
1755
|
-
return
|
|
1745
|
+
}, n = new URL(t, this.url), o = new URLSearchParams(r);
|
|
1746
|
+
return n.search = o.toString(), n.toString();
|
|
1756
1747
|
}
|
|
1757
1748
|
federatedAuthWithPopup(e) {
|
|
1758
1749
|
this.subscribeStore.notify(a.SignInStart, { provider: e.provider });
|
|
1759
|
-
const t = e.scopes ?? this.scopes, s = this.deviceService.getDeviceId(), r = this.createFederatedAuthUrl({ ...e, scopes: t, device: s }),
|
|
1760
|
-
if (!
|
|
1750
|
+
const t = e.scopes ?? this.scopes, s = this.deviceService.getDeviceId(), r = this.createFederatedAuthUrl({ ...e, scopes: t, device: s }), n = window.open(r, "_blank", `width=${ee},height=${te}`);
|
|
1751
|
+
if (!n) {
|
|
1761
1752
|
this.federatedAuthWithRedirect(e);
|
|
1762
1753
|
return;
|
|
1763
1754
|
}
|
|
1764
|
-
const
|
|
1765
|
-
if (
|
|
1755
|
+
const o = Date.now(), d = setInterval(() => {
|
|
1756
|
+
if (n.closed) {
|
|
1766
1757
|
clearInterval(d);
|
|
1767
1758
|
const c = {
|
|
1768
1759
|
message: "Authentication popup was closed",
|
|
@@ -1771,8 +1762,8 @@ class Ie {
|
|
|
1771
1762
|
this.subscribeStore.notify(a.Error, c);
|
|
1772
1763
|
return;
|
|
1773
1764
|
}
|
|
1774
|
-
if (Date.now() -
|
|
1775
|
-
clearInterval(d),
|
|
1765
|
+
if (Date.now() - o > re) {
|
|
1766
|
+
clearInterval(d), n.close();
|
|
1776
1767
|
const c = {
|
|
1777
1768
|
message: "Authentication popup timed out",
|
|
1778
1769
|
code: "POPUP_TIMEOUT"
|
|
@@ -1781,8 +1772,8 @@ class Ie {
|
|
|
1781
1772
|
return;
|
|
1782
1773
|
}
|
|
1783
1774
|
try {
|
|
1784
|
-
if (
|
|
1785
|
-
const c = new URLSearchParams(
|
|
1775
|
+
if (n.location.href.startsWith(this.origin)) {
|
|
1776
|
+
const c = new URLSearchParams(n.location.search), g = c.get("access_token") || "", p = c.get("refresh_token") || "", f = c.get("id_token") || "", b = {
|
|
1786
1777
|
access_token: g,
|
|
1787
1778
|
refresh_token: p || void 0,
|
|
1788
1779
|
id_token: f || void 0,
|
|
@@ -1793,7 +1784,7 @@ class Ie {
|
|
|
1793
1784
|
tokens: b,
|
|
1794
1785
|
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
1795
1786
|
}), window.location.href = `${this.origin}`;
|
|
1796
|
-
}), clearInterval(d),
|
|
1787
|
+
}), clearInterval(d), n.close();
|
|
1797
1788
|
}
|
|
1798
1789
|
} catch {
|
|
1799
1790
|
}
|
|
@@ -1807,14 +1798,14 @@ class Ie {
|
|
|
1807
1798
|
// Helper methods for authentication UI redirect
|
|
1808
1799
|
authRedirectUrl(e = {}) {
|
|
1809
1800
|
try {
|
|
1810
|
-
const { url: t, redirectUrl: s, scopes: r, appId:
|
|
1811
|
-
|
|
1801
|
+
const { url: t, redirectUrl: s, scopes: r, appId: n } = e ?? {}, o = new URL(t ?? this.url);
|
|
1802
|
+
o.pathname = (o.pathname.endsWith("/") ? o.pathname : o.pathname + "/") + "web";
|
|
1812
1803
|
const d = r ?? this.scopes, c = {
|
|
1813
|
-
appId:
|
|
1804
|
+
appId: n ?? this.appId ?? "",
|
|
1814
1805
|
redirectto: s ?? window.location.href,
|
|
1815
1806
|
scopes: d.join(",")
|
|
1816
1807
|
}, g = new URLSearchParams(c);
|
|
1817
|
-
return
|
|
1808
|
+
return o.search = g.toString(), o.toString();
|
|
1818
1809
|
} catch (t) {
|
|
1819
1810
|
const s = {
|
|
1820
1811
|
message: t instanceof Error ? t.message : "Failed to create auth redirect URL",
|
|
@@ -1844,7 +1835,7 @@ class Ie {
|
|
|
1844
1835
|
const t = !!e?.id_token || !!this.storageManager.getIdToken(), s = this.tokenDeliveryManager.isSessionValid(), r = this.tokenDeliveryManager.isSessionUnknown();
|
|
1845
1836
|
return t && (s || r);
|
|
1846
1837
|
}
|
|
1847
|
-
return !e || !e.access_token ? !1 : !
|
|
1838
|
+
return !e || !e.access_token ? !1 : !m(e.access_token) || e.refresh_token !== void 0 && !m(e.refresh_token);
|
|
1848
1839
|
} catch (t) {
|
|
1849
1840
|
const s = {
|
|
1850
1841
|
message: t instanceof Error ? t.message : "Failed to check authentication status",
|
|
@@ -1861,11 +1852,11 @@ class Ie {
|
|
|
1861
1852
|
try {
|
|
1862
1853
|
t = await this.getTokens(e), s = this.tokenCacheService.getParsedTokens();
|
|
1863
1854
|
} catch (r) {
|
|
1864
|
-
const
|
|
1855
|
+
const n = {
|
|
1865
1856
|
message: r instanceof Error || r instanceof u ? r.message : "Session check failed",
|
|
1866
1857
|
originalError: r
|
|
1867
1858
|
};
|
|
1868
|
-
this.subscribeStore.notify(a.Error,
|
|
1859
|
+
this.subscribeStore.notify(a.Error, n), t = void 0;
|
|
1869
1860
|
}
|
|
1870
1861
|
return t && this.sessionCallbacks.createSession && await this.sessionCallbacks.createSession({ tokens: t, parsedTokens: s }), !t && this.sessionCallbacks.expiredSession && await this.sessionCallbacks.expiredSession(), t;
|
|
1871
1862
|
}
|
|
@@ -1883,7 +1874,7 @@ class Ie {
|
|
|
1883
1874
|
const t = this.storageManager.getTokens();
|
|
1884
1875
|
if (!t || !t.access_token) return;
|
|
1885
1876
|
const s = y(t.access_token);
|
|
1886
|
-
return
|
|
1877
|
+
return m(s) ? e ? await this.refreshToken() : void 0 : t;
|
|
1887
1878
|
} catch (t) {
|
|
1888
1879
|
const s = {
|
|
1889
1880
|
message: t instanceof Error ? t.message : "Failed to get tokens",
|
|
@@ -1961,32 +1952,32 @@ class Re {
|
|
|
1961
1952
|
this.data = this.normalize(e);
|
|
1962
1953
|
}
|
|
1963
1954
|
normalize(e) {
|
|
1964
|
-
const t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(),
|
|
1965
|
-
return e.groups?.forEach((
|
|
1966
|
-
s.set(
|
|
1967
|
-
id:
|
|
1968
|
-
name:
|
|
1969
|
-
default:
|
|
1970
|
-
updated_at:
|
|
1971
|
-
created_at:
|
|
1955
|
+
const t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), n = [];
|
|
1956
|
+
return e.groups?.forEach((o) => {
|
|
1957
|
+
s.set(o.id, {
|
|
1958
|
+
id: o.id,
|
|
1959
|
+
name: o.name,
|
|
1960
|
+
default: o.default ?? !1,
|
|
1961
|
+
updated_at: o.updated_at,
|
|
1962
|
+
created_at: o.created_at
|
|
1972
1963
|
});
|
|
1973
|
-
}), e.roles?.forEach((
|
|
1974
|
-
r.set(
|
|
1975
|
-
id:
|
|
1976
|
-
tenant_id:
|
|
1977
|
-
name:
|
|
1964
|
+
}), e.roles?.forEach((o) => {
|
|
1965
|
+
r.set(o.id, {
|
|
1966
|
+
id: o.id,
|
|
1967
|
+
tenant_id: o.tenant_id,
|
|
1968
|
+
name: o.name
|
|
1978
1969
|
});
|
|
1979
|
-
}), e.users_in_groups?.forEach((
|
|
1980
|
-
const d =
|
|
1970
|
+
}), e.users_in_groups?.forEach((o) => {
|
|
1971
|
+
const d = o.user;
|
|
1981
1972
|
d && !t.has(d.id) && t.set(d.id, {
|
|
1982
1973
|
id: d.id,
|
|
1983
1974
|
name: d.name ?? null,
|
|
1984
1975
|
email: d.email ?? null,
|
|
1985
1976
|
phone: d.phone ?? null
|
|
1986
|
-
}), d &&
|
|
1977
|
+
}), d && o.group_id && s.has(o.group_id) && n.push({
|
|
1987
1978
|
userId: d.id,
|
|
1988
|
-
groupId:
|
|
1989
|
-
roleIds:
|
|
1979
|
+
groupId: o.group_id,
|
|
1980
|
+
roleIds: o.roles?.map((c) => c.id) ?? []
|
|
1990
1981
|
});
|
|
1991
1982
|
}), {
|
|
1992
1983
|
tenant_id: e.tenant_id,
|
|
@@ -1994,7 +1985,7 @@ class Re {
|
|
|
1994
1985
|
users: Array.from(t.values()),
|
|
1995
1986
|
groups: Array.from(s.values()),
|
|
1996
1987
|
roles: Array.from(r.values()),
|
|
1997
|
-
memberships:
|
|
1988
|
+
memberships: n,
|
|
1998
1989
|
usersById: t,
|
|
1999
1990
|
groupsById: s,
|
|
2000
1991
|
rolesById: r
|
|
@@ -2204,9 +2195,9 @@ class Pe {
|
|
|
2204
2195
|
async addUserToGroup(e, t, s, r) {
|
|
2205
2196
|
try {
|
|
2206
2197
|
return await this.tenantApi.addUserToGroup(e, t, s, r);
|
|
2207
|
-
} catch (
|
|
2198
|
+
} catch (n) {
|
|
2208
2199
|
this.handlePassflowError(
|
|
2209
|
-
|
|
2200
|
+
n,
|
|
2210
2201
|
`Add user to group failed for tenant ID ${e}, group ID ${t}, user ID ${s}`
|
|
2211
2202
|
);
|
|
2212
2203
|
}
|
|
@@ -2222,9 +2213,9 @@ class Pe {
|
|
|
2222
2213
|
async removeUserRolesFromGroup(e, t, s, r) {
|
|
2223
2214
|
try {
|
|
2224
2215
|
return await this.tenantApi.removeUserRolesFromGroup(e, t, s, r);
|
|
2225
|
-
} catch (
|
|
2216
|
+
} catch (n) {
|
|
2226
2217
|
this.handlePassflowError(
|
|
2227
|
-
|
|
2218
|
+
n,
|
|
2228
2219
|
`Remove user roles from group failed for tenant ID ${e}, group ID ${t}, user ID ${s}`
|
|
2229
2220
|
);
|
|
2230
2221
|
}
|
|
@@ -2240,9 +2231,9 @@ class Pe {
|
|
|
2240
2231
|
async changeUserRoles(e, t, s, r) {
|
|
2241
2232
|
try {
|
|
2242
2233
|
return await this.tenantApi.changeUserRoles(e, t, s, r);
|
|
2243
|
-
} catch (
|
|
2234
|
+
} catch (n) {
|
|
2244
2235
|
this.handlePassflowError(
|
|
2245
|
-
|
|
2236
|
+
n,
|
|
2246
2237
|
`Change user roles failed for tenant ID ${e}, group ID ${t}, user ID ${s}`
|
|
2247
2238
|
);
|
|
2248
2239
|
}
|
|
@@ -2343,8 +2334,8 @@ class Pe {
|
|
|
2343
2334
|
async getGroupInvitations(e, t, s, r) {
|
|
2344
2335
|
try {
|
|
2345
2336
|
return await this.tenantApi.getGroupInvitations(e, t, s, r);
|
|
2346
|
-
} catch (
|
|
2347
|
-
this.handlePassflowError(
|
|
2337
|
+
} catch (n) {
|
|
2338
|
+
this.handlePassflowError(n, `Get group invitations failed for tenant ID ${e}, group ID ${t}`);
|
|
2348
2339
|
}
|
|
2349
2340
|
}
|
|
2350
2341
|
/**
|
|
@@ -2412,7 +2403,7 @@ class De {
|
|
|
2412
2403
|
return;
|
|
2413
2404
|
}
|
|
2414
2405
|
const t = y(e.access_token);
|
|
2415
|
-
|
|
2406
|
+
m(t) ? (this.tokenExpiredFlag = !0, this.stopTokenCheck(), this.subscribeStore.notify(a.TokenCacheExpired, { isExpired: !0 })) : (this.setTokensCache(e), this.startTokenCheck());
|
|
2416
2407
|
} catch (e) {
|
|
2417
2408
|
const t = {
|
|
2418
2409
|
message: e instanceof Error ? e.message : "Failed to get tokens",
|
|
@@ -2479,7 +2470,7 @@ class De {
|
|
|
2479
2470
|
if (!this.tokensCache.access_token)
|
|
2480
2471
|
return this.tokensCache;
|
|
2481
2472
|
const e = y(this.tokensCache.access_token);
|
|
2482
|
-
return
|
|
2473
|
+
return m(e) && !this.tokenExpiredFlag ? (await this.refreshTokensCache(this.tokensCache), this.tokensCache) : this.tokensCache;
|
|
2483
2474
|
} catch (e) {
|
|
2484
2475
|
const t = {
|
|
2485
2476
|
message: e instanceof Error ? e.message : "Failed to get tokens",
|
|
@@ -2497,17 +2488,17 @@ class De {
|
|
|
2497
2488
|
if (!this.tokensCache.access_token)
|
|
2498
2489
|
return !1;
|
|
2499
2490
|
const e = y(this.tokensCache.access_token);
|
|
2500
|
-
return
|
|
2491
|
+
return m(e);
|
|
2501
2492
|
}
|
|
2502
2493
|
}
|
|
2503
|
-
class
|
|
2494
|
+
class Me {
|
|
2504
2495
|
constructor(e, t) {
|
|
2505
2496
|
this.twoFactorApi = e, this.subscribeStore = t, this.PARTIAL_AUTH_TIMEOUT_MS = 300 * 1e3, this.SESSION_STORAGE_KEY = "passflow_2fa_challenge", this.totpDigits = 6;
|
|
2506
2497
|
const s = {
|
|
2507
|
-
onAuthChange: (r,
|
|
2498
|
+
onAuthChange: (r, n) => {
|
|
2508
2499
|
if (r === a.TwoFactorRequired) {
|
|
2509
|
-
const
|
|
2510
|
-
this.setPartialAuthState(
|
|
2500
|
+
const o = n;
|
|
2501
|
+
this.setPartialAuthState(o.email, o.challengeId, o.tfaToken);
|
|
2511
2502
|
}
|
|
2512
2503
|
}
|
|
2513
2504
|
};
|
|
@@ -2518,12 +2509,12 @@ class Fe {
|
|
|
2518
2509
|
* Helper method to ensure errors are properly emitted to subscribers
|
|
2519
2510
|
*/
|
|
2520
2511
|
emitErrorAndThrow(e, t) {
|
|
2521
|
-
const s = {
|
|
2512
|
+
const s = e, r = {
|
|
2522
2513
|
message: e instanceof Error ? e.message : `${t} failed`,
|
|
2523
2514
|
originalError: e,
|
|
2524
|
-
code:
|
|
2515
|
+
code: s?.id || void 0
|
|
2525
2516
|
};
|
|
2526
|
-
throw this.subscribeStore.notify(a.Error,
|
|
2517
|
+
throw this.subscribeStore.notify(a.Error, r), e;
|
|
2527
2518
|
}
|
|
2528
2519
|
/**
|
|
2529
2520
|
* Get 2FA enrollment status for current user
|
|
@@ -2772,7 +2763,7 @@ class Fe {
|
|
|
2772
2763
|
return this.totpDigits;
|
|
2773
2764
|
}
|
|
2774
2765
|
}
|
|
2775
|
-
class
|
|
2766
|
+
class Fe {
|
|
2776
2767
|
constructor(e, t) {
|
|
2777
2768
|
this.userAPI = e, this.deviceService = t;
|
|
2778
2769
|
}
|
|
@@ -2810,31 +2801,31 @@ class Me {
|
|
|
2810
2801
|
passkeyUsername: t,
|
|
2811
2802
|
passkeyDisplayName: s
|
|
2812
2803
|
} = {}) {
|
|
2813
|
-
const r = this.deviceService.getDeviceId(),
|
|
2804
|
+
const r = this.deviceService.getDeviceId(), n = I.web, { challenge_id: o, publicKey: d } = await this.userAPI.addUserPasskeyStart({
|
|
2814
2805
|
relyingPartyId: e || window?.location?.hostname,
|
|
2815
2806
|
deviceId: r,
|
|
2816
|
-
os:
|
|
2807
|
+
os: n,
|
|
2817
2808
|
passkeyDisplayName: s,
|
|
2818
2809
|
passkeyUsername: t
|
|
2819
2810
|
});
|
|
2820
2811
|
d.user.id = btoa(d.user.id);
|
|
2821
2812
|
const c = await K({ optionsJSON: d });
|
|
2822
|
-
return await this.userAPI.addUserPasskeyComplete(c, r,
|
|
2813
|
+
return await this.userAPI.addUserPasskeyComplete(c, r, o);
|
|
2823
2814
|
}
|
|
2824
2815
|
}
|
|
2825
2816
|
const O = class O {
|
|
2826
2817
|
constructor(e) {
|
|
2827
2818
|
this.doRefreshTokens = !1, this.origin = window.location.origin, this.session = async ({
|
|
2828
|
-
createSession:
|
|
2829
|
-
expiredSession:
|
|
2819
|
+
createSession: n,
|
|
2820
|
+
expiredSession: o,
|
|
2830
2821
|
doRefresh: d = !1
|
|
2831
2822
|
}) => {
|
|
2832
|
-
this.createSessionCallback =
|
|
2823
|
+
this.createSessionCallback = n, this.expiredSessionCallback = o, this.doRefreshTokens = d, await this.submitSessionCheck();
|
|
2833
2824
|
};
|
|
2834
2825
|
const { url: t, appId: s, scopes: r } = e;
|
|
2835
2826
|
this.url = t || G, this.appId = s, this.storageManager = new $({
|
|
2836
2827
|
prefix: e.keyStoragePrefix ?? ""
|
|
2837
|
-
}), this.deviceService = new
|
|
2828
|
+
}), this.deviceService = new B(this.storageManager), this.authApi = new fe(e, this.storageManager, this.deviceService), this.appApi = new pe(e, this.storageManager, this.deviceService), this.userApi = new Se(e, this.storageManager, this.deviceService), this.settingApi = new ye(e, this.storageManager, this.deviceService), this.tenantApi = new ve(e, this.storageManager, this.deviceService), this.invitationApi = new ke(e, this.storageManager, this.deviceService), this.twoFactorApi = new me(e, this.storageManager, this.deviceService), this.subscribeStore = new we(), this.tokenCacheService = new De(this.storageManager, this.authApi, this.subscribeStore), this.scopes = r ?? Q, this.createTenantForNewUser = e.createTenantForNewUser ?? !1, this.authService = new Ie(
|
|
2838
2829
|
this.authApi,
|
|
2839
2830
|
this.deviceService,
|
|
2840
2831
|
this.storageManager,
|
|
@@ -2850,7 +2841,7 @@ const O = class O {
|
|
|
2850
2841
|
},
|
|
2851
2842
|
this.appId ?? "",
|
|
2852
2843
|
e.tokenExchange
|
|
2853
|
-
), this.userService = new
|
|
2844
|
+
), this.userService = new Fe(this.userApi, this.deviceService), this.tenantService = new Pe(this.tenantApi, this.scopes), this.tenant = this.tenantService, this.invitationService = new be(this.invitationApi), this.twoFactorService = new Me(this.twoFactorApi, this.subscribeStore), this.twoFactor = this.twoFactorService, e.parseQueryParams && this.checkAndSetTokens(), this.setTokensToCacheFromLocalStorage();
|
|
2854
2845
|
}
|
|
2855
2846
|
/**
|
|
2856
2847
|
* Update the appId and propagate it to all API clients.
|
|
@@ -2954,10 +2945,10 @@ const O = class O {
|
|
|
2954
2945
|
const c = new URLSearchParams(window.location.hash.substring(1));
|
|
2955
2946
|
c.get("access_token") && (e = c, t = !0);
|
|
2956
2947
|
}
|
|
2957
|
-
const s = e.get("access_token"), r = e.get("refresh_token"),
|
|
2948
|
+
const s = e.get("access_token"), r = e.get("refresh_token"), n = e.get("id_token"), o = e.get("scopes")?.split(",") ?? this.scopes;
|
|
2958
2949
|
let d;
|
|
2959
2950
|
if (s) {
|
|
2960
|
-
if (!
|
|
2951
|
+
if (!M(s)) {
|
|
2961
2952
|
const c = {
|
|
2962
2953
|
message: "Invalid access token format received",
|
|
2963
2954
|
code: "INVALID_TOKEN_FORMAT"
|
|
@@ -2965,7 +2956,7 @@ const O = class O {
|
|
|
2965
2956
|
this.subscribeStore.notify(a.Error, c), this.cleanupUrlParams(t);
|
|
2966
2957
|
return;
|
|
2967
2958
|
}
|
|
2968
|
-
if (r && !
|
|
2959
|
+
if (r && !M(r)) {
|
|
2969
2960
|
const c = {
|
|
2970
2961
|
message: "Invalid refresh token format received",
|
|
2971
2962
|
code: "INVALID_TOKEN_FORMAT"
|
|
@@ -2973,7 +2964,7 @@ const O = class O {
|
|
|
2973
2964
|
this.subscribeStore.notify(a.Error, c), this.cleanupUrlParams(t);
|
|
2974
2965
|
return;
|
|
2975
2966
|
}
|
|
2976
|
-
if (
|
|
2967
|
+
if (n && !M(n)) {
|
|
2977
2968
|
const c = {
|
|
2978
2969
|
message: "Invalid ID token format received",
|
|
2979
2970
|
code: "INVALID_TOKEN_FORMAT"
|
|
@@ -2984,8 +2975,8 @@ const O = class O {
|
|
|
2984
2975
|
return d = {
|
|
2985
2976
|
access_token: s,
|
|
2986
2977
|
refresh_token: r ?? void 0,
|
|
2987
|
-
id_token:
|
|
2988
|
-
scopes:
|
|
2978
|
+
id_token: n ?? void 0,
|
|
2979
|
+
scopes: o
|
|
2989
2980
|
}, this.storageManager.saveTokens(d), this.tokenCacheService.setTokensCache(d), this.subscribeStore.notify(a.SignIn, { tokens: d, parsedTokens: this.getParsedTokens() }), this.submitSessionCheck(), this.cleanupUrlParams(t), this.error = void 0, d;
|
|
2990
2981
|
} else
|
|
2991
2982
|
this.error = this.checkErrorsFromURL();
|
|
@@ -4299,7 +4290,7 @@ const Ge = {
|
|
|
4299
4290
|
RateLimitExceeded: "rate_limit_exceeded",
|
|
4300
4291
|
ServerError: "server_error",
|
|
4301
4292
|
TemporarilyUnavailable: "temporarily_unavailable"
|
|
4302
|
-
},
|
|
4293
|
+
}, S = {
|
|
4303
4294
|
/** Default token endpoint path */
|
|
4304
4295
|
TOKEN_ENDPOINT: "/oauth2/token",
|
|
4305
4296
|
/** Default request timeout in milliseconds */
|
|
@@ -4317,18 +4308,18 @@ class xe {
|
|
|
4317
4308
|
constructor() {
|
|
4318
4309
|
this.cache = /* @__PURE__ */ new Map();
|
|
4319
4310
|
}
|
|
4320
|
-
|
|
4311
|
+
get(e) {
|
|
4321
4312
|
const t = this.cache.get(e);
|
|
4322
|
-
return t ? Date.now() >= t.expiresAt ? (this.cache.delete(e), null) : t.token : null;
|
|
4313
|
+
return t ? Date.now() >= t.expiresAt ? (this.cache.delete(e), Promise.resolve(null)) : Promise.resolve(t.token) : Promise.resolve(null);
|
|
4323
4314
|
}
|
|
4324
|
-
|
|
4325
|
-
this.cache.set(e, {
|
|
4315
|
+
set(e, t, s) {
|
|
4316
|
+
return this.cache.set(e, {
|
|
4326
4317
|
token: t,
|
|
4327
4318
|
expiresAt: Date.now() + s * 1e3
|
|
4328
|
-
});
|
|
4319
|
+
}), Promise.resolve();
|
|
4329
4320
|
}
|
|
4330
|
-
|
|
4331
|
-
this.cache.delete(e);
|
|
4321
|
+
delete(e) {
|
|
4322
|
+
return this.cache.delete(e), Promise.resolve();
|
|
4332
4323
|
}
|
|
4333
4324
|
}
|
|
4334
4325
|
const Ue = {
|
|
@@ -4370,16 +4361,16 @@ class Ve {
|
|
|
4370
4361
|
scopes: e.scopes,
|
|
4371
4362
|
audience: e.audience,
|
|
4372
4363
|
autoRefresh: e.autoRefresh ?? !1,
|
|
4373
|
-
refreshThreshold: e.refreshThreshold ??
|
|
4374
|
-
timeout: e.timeout ??
|
|
4375
|
-
retries: e.retries ??
|
|
4376
|
-
retryDelay: e.retryDelay ??
|
|
4364
|
+
refreshThreshold: e.refreshThreshold ?? S.REFRESH_THRESHOLD,
|
|
4365
|
+
timeout: e.timeout ?? S.TIMEOUT,
|
|
4366
|
+
retries: e.retries ?? S.RETRIES,
|
|
4367
|
+
retryDelay: e.retryDelay ?? S.RETRY_DELAY,
|
|
4377
4368
|
retryStrategy: e.retryStrategy,
|
|
4378
4369
|
cache: e.cache,
|
|
4379
4370
|
onTokenRequest: e.onTokenRequest,
|
|
4380
4371
|
onTokenResponse: e.onTokenResponse,
|
|
4381
4372
|
onError: e.onError
|
|
4382
|
-
}, this.cache = e.cache ?? new xe(), this.retryStrategy = e.retryStrategy ?? Ue, this.tokenEndpoint = `${t}${
|
|
4373
|
+
}, this.cache = e.cache ?? new xe(), this.retryStrategy = e.retryStrategy ?? Ue, this.tokenEndpoint = `${t}${S.TOKEN_ENDPOINT}`;
|
|
4383
4374
|
}
|
|
4384
4375
|
/**
|
|
4385
4376
|
* Get the cache key for this client
|
|
@@ -4410,9 +4401,9 @@ class Ve {
|
|
|
4410
4401
|
async getToken(e) {
|
|
4411
4402
|
const t = e?.scopes ?? this.config.scopes, s = e?.audience ?? this.config.audience, r = this.getCacheKey(t, s);
|
|
4412
4403
|
if (!e?.forceRefresh) {
|
|
4413
|
-
const
|
|
4414
|
-
if (
|
|
4415
|
-
return
|
|
4404
|
+
const n = await this.cache.get(r);
|
|
4405
|
+
if (n && !this.isTokenExpired(n))
|
|
4406
|
+
return n;
|
|
4416
4407
|
}
|
|
4417
4408
|
return this.requestToken(t, s, r);
|
|
4418
4409
|
}
|
|
@@ -4456,8 +4447,8 @@ class Ve {
|
|
|
4456
4447
|
audience: t ?? [],
|
|
4457
4448
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
4458
4449
|
});
|
|
4459
|
-
const
|
|
4460
|
-
return
|
|
4450
|
+
const n = await this.executeWithRetry(() => this.doTokenRequest(r));
|
|
4451
|
+
return n.issued_at = Math.floor(Date.now() / 1e3), s && await this.cache.set(s, n, n.expires_in), this.config.onTokenResponse && this.config.onTokenResponse(n), n;
|
|
4461
4452
|
}
|
|
4462
4453
|
/**
|
|
4463
4454
|
* Execute the actual HTTP request to the token endpoint
|
|
@@ -4467,30 +4458,30 @@ class Ve {
|
|
|
4467
4458
|
t.append("grant_type", e.grant_type), t.append("client_id", e.client_id), t.append("client_secret", e.client_secret), e.scope && t.append("scope", e.scope), e.audience && t.append("audience", e.audience);
|
|
4468
4459
|
const s = new AbortController(), r = setTimeout(() => s.abort(), this.config.timeout);
|
|
4469
4460
|
try {
|
|
4470
|
-
const
|
|
4461
|
+
const n = await fetch(this.tokenEndpoint, {
|
|
4471
4462
|
method: "POST",
|
|
4472
4463
|
headers: {
|
|
4473
|
-
"Content-Type":
|
|
4464
|
+
"Content-Type": S.CONTENT_TYPE,
|
|
4474
4465
|
Accept: "application/json"
|
|
4475
4466
|
},
|
|
4476
4467
|
body: t.toString(),
|
|
4477
4468
|
signal: s.signal
|
|
4478
4469
|
});
|
|
4479
4470
|
clearTimeout(r);
|
|
4480
|
-
const
|
|
4481
|
-
|
|
4482
|
-
|
|
4471
|
+
const o = {};
|
|
4472
|
+
n.headers.forEach((c, g) => {
|
|
4473
|
+
o[g.toLowerCase()] = c;
|
|
4483
4474
|
});
|
|
4484
|
-
const d = await
|
|
4485
|
-
if (!
|
|
4475
|
+
const d = await n.json();
|
|
4476
|
+
if (!n.ok) {
|
|
4486
4477
|
const c = l.fromOAuthError(
|
|
4487
4478
|
{
|
|
4488
4479
|
error: d.error || "server_error",
|
|
4489
4480
|
error_description: d.error_description || d.message,
|
|
4490
4481
|
error_uri: d.error_uri
|
|
4491
4482
|
},
|
|
4492
|
-
|
|
4493
|
-
|
|
4483
|
+
n.status,
|
|
4484
|
+
o
|
|
4494
4485
|
);
|
|
4495
4486
|
throw this.config.onError && this.config.onError({
|
|
4496
4487
|
error: c.code,
|
|
@@ -4498,8 +4489,8 @@ class Ve {
|
|
|
4498
4489
|
}), c;
|
|
4499
4490
|
}
|
|
4500
4491
|
return d;
|
|
4501
|
-
} catch (
|
|
4502
|
-
throw clearTimeout(r),
|
|
4492
|
+
} catch (n) {
|
|
4493
|
+
throw clearTimeout(r), n instanceof Error && n.name === "AbortError" ? new N(`Request timed out after ${this.config.timeout}ms`) : n instanceof TypeError && n.message.includes("fetch") ? new N(`Network error: ${n.message}`, n) : n instanceof l ? n : l.fromError(n instanceof Error ? n : new Error(String(n)));
|
|
4503
4494
|
}
|
|
4504
4495
|
}
|
|
4505
4496
|
/**
|
|
@@ -4514,8 +4505,8 @@ class Ve {
|
|
|
4514
4505
|
if (!(r instanceof l))
|
|
4515
4506
|
throw r;
|
|
4516
4507
|
if (t = r, s < this.config.retries && this.retryStrategy.shouldRetry({ code: r.code, status: r.status }, s)) {
|
|
4517
|
-
const
|
|
4518
|
-
await this.sleep(
|
|
4508
|
+
const n = this.retryStrategy.getDelay(s);
|
|
4509
|
+
await this.sleep(n);
|
|
4519
4510
|
continue;
|
|
4520
4511
|
}
|
|
4521
4512
|
throw r;
|
|
@@ -4572,8 +4563,8 @@ class Ve {
|
|
|
4572
4563
|
*/
|
|
4573
4564
|
isTokenExpired(e, t = 0) {
|
|
4574
4565
|
if (!e) return !0;
|
|
4575
|
-
const s = Math.floor(Date.now() / 1e3),
|
|
4576
|
-
return s >=
|
|
4566
|
+
const s = Math.floor(Date.now() / 1e3), n = (e.issued_at ?? s - e.expires_in) + e.expires_in;
|
|
4567
|
+
return s >= n - t;
|
|
4577
4568
|
}
|
|
4578
4569
|
/**
|
|
4579
4570
|
* Parse token claims from a JWT access token
|
|
@@ -4598,8 +4589,8 @@ class Ve {
|
|
|
4598
4589
|
const s = t[1];
|
|
4599
4590
|
if (!s)
|
|
4600
4591
|
throw new P("Invalid JWT format: missing payload");
|
|
4601
|
-
const r = atob(s.replace(/-/g, "+").replace(/_/g, "/")),
|
|
4602
|
-
return
|
|
4592
|
+
const r = atob(s.replace(/-/g, "+").replace(/_/g, "/")), n = JSON.parse(r);
|
|
4593
|
+
return n.scopes && typeof n.scopes == "string" ? n.scopes = n.scopes.split(" ") : n.scopes || (n.scopes = []), n;
|
|
4603
4594
|
} catch (t) {
|
|
4604
4595
|
throw t instanceof P ? t : new P(`Failed to parse token: ${t instanceof Error ? t.message : "Unknown error"}`);
|
|
4605
4596
|
}
|
|
@@ -4642,16 +4633,16 @@ class Ve {
|
|
|
4642
4633
|
const r = await fetch(t, {
|
|
4643
4634
|
method: "POST",
|
|
4644
4635
|
headers: {
|
|
4645
|
-
"Content-Type":
|
|
4636
|
+
"Content-Type": S.CONTENT_TYPE
|
|
4646
4637
|
},
|
|
4647
4638
|
body: s.toString()
|
|
4648
4639
|
});
|
|
4649
4640
|
if (!r.ok && r.status !== 200) {
|
|
4650
|
-
const
|
|
4641
|
+
const n = await r.json().catch(() => ({}));
|
|
4651
4642
|
throw l.fromOAuthError(
|
|
4652
4643
|
{
|
|
4653
|
-
error:
|
|
4654
|
-
error_description:
|
|
4644
|
+
error: n.error || "server_error",
|
|
4645
|
+
error_description: n.error_description || "Token revocation failed"
|
|
4655
4646
|
},
|
|
4656
4647
|
r.status
|
|
4657
4648
|
);
|
|
@@ -4696,7 +4687,7 @@ export {
|
|
|
4696
4687
|
Q as DEFAULT_SCOPES,
|
|
4697
4688
|
W as DEVICE_ID_HEADER_KEY,
|
|
4698
4689
|
J as DEVICE_TYPE_HEADER_KEY,
|
|
4699
|
-
|
|
4690
|
+
oe as ERROR_MESSAGE_MAX_LENGTH,
|
|
4700
4691
|
ke as InvitationAPI,
|
|
4701
4692
|
be as InvitationService,
|
|
4702
4693
|
Ve as M2MClient,
|
|
@@ -4705,7 +4696,7 @@ export {
|
|
|
4705
4696
|
Ge as M2MErrorCodes,
|
|
4706
4697
|
N as M2MNetworkError,
|
|
4707
4698
|
P as M2MTokenParseError,
|
|
4708
|
-
|
|
4699
|
+
S as M2M_DEFAULTS,
|
|
4709
4700
|
Ne as MINIMAL_DEFAULT_SCOPES,
|
|
4710
4701
|
I as OS,
|
|
4711
4702
|
G as PASSFLOW_CLOUD_URL,
|
|
@@ -4730,16 +4721,16 @@ export {
|
|
|
4730
4721
|
De as TokenCacheService,
|
|
4731
4722
|
v as TokenDeliveryMode,
|
|
4732
4723
|
k as TokenType,
|
|
4733
|
-
|
|
4724
|
+
me as TwoFactorApiClient,
|
|
4734
4725
|
ue as TwoFactorPolicy,
|
|
4735
|
-
|
|
4736
|
-
|
|
4726
|
+
Me as TwoFactorService,
|
|
4727
|
+
ne as USERNAME_MAX_LENGTH,
|
|
4737
4728
|
ie as USERNAME_MIN_LENGTH,
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4729
|
+
Se as UserAPI,
|
|
4730
|
+
Fe as UserService,
|
|
4731
|
+
m as isTokenExpired,
|
|
4732
|
+
F as isValidEmail,
|
|
4733
|
+
M as isValidJWTFormat,
|
|
4743
4734
|
x as isValidPhoneNumber,
|
|
4744
4735
|
Ee as isValidUsername,
|
|
4745
4736
|
y as parseToken,
|