@passflow/core 0.30.2 → 0.32.0
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/README.md +195 -6
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +599 -392
- package/dist/index.d.ts +599 -392
- package/dist/index.mjs +991 -750
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import e, { AxiosError as t } from "axios";
|
|
2
2
|
import { startAuthentication as n, startRegistration as r } from "@simplewebauthn/browser";
|
|
3
3
|
// package.json
|
|
4
|
-
var i = "0.
|
|
4
|
+
var i = "0.32.0", a = "X-Passflow-Clientid", o = "Authorization", s = "X-Passflow-DeviceId", c = "X-Passflow-DeviceType", l = i, u = [
|
|
5
5
|
"id",
|
|
6
6
|
"offline",
|
|
7
7
|
"openid"
|
|
@@ -147,8 +147,8 @@ var M = /* @__PURE__ */ function(e) {
|
|
|
147
147
|
getSessionState() {
|
|
148
148
|
return this.sessionState;
|
|
149
149
|
}
|
|
150
|
-
reset() {
|
|
151
|
-
this.mode = "json_body", this.sessionState = "unknown", this.isInitializedFlag = !1, this.clearPersistedMode(), this.clearPersistedSessionState();
|
|
150
|
+
reset(e = !1) {
|
|
151
|
+
this.mode = "json_body", this.sessionState = "unknown", this.isInitializedFlag = !1, e || (this.clearPersistedMode(), this.clearPersistedSessionState());
|
|
152
152
|
}
|
|
153
153
|
loadPersistedMode() {
|
|
154
154
|
try {
|
|
@@ -183,28 +183,65 @@ var M = /* @__PURE__ */ function(e) {
|
|
|
183
183
|
} catch {}
|
|
184
184
|
}
|
|
185
185
|
}, ne = class {
|
|
186
|
-
constructor({ storage: e, prefix: t } = {}) {
|
|
187
|
-
this.keyStoragePrefix = "", this.scopes = `${this.keyStoragePrefix}tokens_scopes`, this.deviceId = `${this.keyStoragePrefix}passflowDeviceId`, this.invitationToken = `${this.keyStoragePrefix}passflowInvitationToken`, this.previousRedirectUrl = `${this.keyStoragePrefix}passflowPreviousRedirectUrl`, this.STORAGE_PREFIX = "passflow_", this.ID_TOKEN_KEY = `${this.STORAGE_PREFIX}id_token`, this.CSRF_TOKEN_KEY = `${this.STORAGE_PREFIX}csrf_token`, this.DELIVERY_MODE_KEY = `${this.STORAGE_PREFIX}delivery_mode`, this.storage = e ?? localStorage, this.keyStoragePrefix = t ? `${t}_` : "";
|
|
186
|
+
constructor({ storage: e, prefix: t, appId: n } = {}) {
|
|
187
|
+
this.keyStoragePrefix = "", this.scopes = `${this.keyStoragePrefix}tokens_scopes`, this.deviceId = `${this.keyStoragePrefix}passflowDeviceId`, this.invitationToken = `${this.keyStoragePrefix}passflowInvitationToken`, this.previousRedirectUrl = `${this.keyStoragePrefix}passflowPreviousRedirectUrl`, this.STORAGE_PREFIX = "passflow_", this.ID_TOKEN_KEY = `${this.STORAGE_PREFIX}id_token`, this.CSRF_TOKEN_KEY = `${this.STORAGE_PREFIX}csrf_token`, this.DELIVERY_MODE_KEY = `${this.STORAGE_PREFIX}delivery_mode`, this.storage = e ?? localStorage, this.keyStoragePrefix = t ? `${t}_` : "", this.appId = n || void 0;
|
|
188
|
+
}
|
|
189
|
+
setAppId(e) {
|
|
190
|
+
this.appId = e || void 0;
|
|
191
|
+
}
|
|
192
|
+
ownToken(e) {
|
|
193
|
+
if (!e) return;
|
|
194
|
+
if (!this.appId) return e;
|
|
195
|
+
let t;
|
|
196
|
+
try {
|
|
197
|
+
t = j(e).aud;
|
|
198
|
+
} catch {
|
|
199
|
+
return e;
|
|
200
|
+
}
|
|
201
|
+
return t === void 0 || (Array.isArray(t) ? t : [t]).includes(this.appId) ? e : void 0;
|
|
202
|
+
}
|
|
203
|
+
readToken(e) {
|
|
204
|
+
return this.ownToken(this.storage.getItem(e));
|
|
205
|
+
}
|
|
206
|
+
tokenValueKeys() {
|
|
207
|
+
return [
|
|
208
|
+
this.getKeyForTokenType(M.access_token),
|
|
209
|
+
this.getKeyForTokenType(M.refresh_token),
|
|
210
|
+
this.getKeyForTokenType(M.id_token),
|
|
211
|
+
this.ID_TOKEN_KEY
|
|
212
|
+
];
|
|
213
|
+
}
|
|
214
|
+
holdsOtherAppToken(e) {
|
|
215
|
+
if (!this.appId) return !1;
|
|
216
|
+
let t = this.storage.getItem(e);
|
|
217
|
+
return !!t && this.ownToken(t) === void 0;
|
|
218
|
+
}
|
|
219
|
+
holdsOnlyOtherAppSession() {
|
|
220
|
+
if (!this.appId) return !1;
|
|
221
|
+
let e = this.tokenValueKeys();
|
|
222
|
+
return e.some((e) => this.holdsOtherAppToken(e)) && !e.some((e) => !!this.readToken(e));
|
|
223
|
+
}
|
|
224
|
+
removeOwnToken(e) {
|
|
225
|
+
this.holdsOtherAppToken(e) || this.storage.removeItem(e);
|
|
188
226
|
}
|
|
189
227
|
saveTokens(e, t) {
|
|
190
228
|
let { id_token: n, access_token: r, refresh_token: i, scopes: a } = e;
|
|
191
229
|
t === N.Cookie || t === N.BFF ? n && this.storage.setItem(this.ID_TOKEN_KEY, n) : (n && this.storage.setItem(this.getKeyForTokenType(M.id_token), n), r && this.storage.setItem(this.getKeyForTokenType(M.access_token), r), i && this.storage.setItem(this.getKeyForTokenType(M.refresh_token), i), a && this.storage.setItem(this.scopes, a.join(",")));
|
|
192
230
|
}
|
|
193
231
|
getToken(e) {
|
|
194
|
-
|
|
195
|
-
return this.storage.getItem(t) ?? void 0;
|
|
232
|
+
return this.readToken(this.getKeyForTokenType(e));
|
|
196
233
|
}
|
|
197
234
|
getTokens() {
|
|
198
235
|
let e = this.getDeliveryMode();
|
|
199
236
|
if (e === N.Cookie || e === N.BFF) {
|
|
200
|
-
let e = this.
|
|
237
|
+
let e = this.readToken(this.ID_TOKEN_KEY);
|
|
201
238
|
return e ? { id_token: e } : void 0;
|
|
202
239
|
}
|
|
203
|
-
let t = this.
|
|
240
|
+
let t = this.readToken(this.getKeyForTokenType(M.access_token));
|
|
204
241
|
if (t) return {
|
|
205
242
|
access_token: t,
|
|
206
|
-
id_token: this.
|
|
207
|
-
refresh_token: this.
|
|
243
|
+
id_token: this.readToken(this.getKeyForTokenType(M.id_token)),
|
|
244
|
+
refresh_token: this.readToken(this.getKeyForTokenType(M.refresh_token)),
|
|
208
245
|
scopes: this.storage.getItem(this.scopes)?.split(",") ?? void 0
|
|
209
246
|
};
|
|
210
247
|
}
|
|
@@ -212,17 +249,36 @@ var M = /* @__PURE__ */ function(e) {
|
|
|
212
249
|
return this.storage.getItem(this.scopes)?.split(",") ?? void 0;
|
|
213
250
|
}
|
|
214
251
|
hasJsonModeTokens() {
|
|
215
|
-
return !!this.
|
|
252
|
+
return !!this.readToken(this.getKeyForTokenType(M.access_token));
|
|
216
253
|
}
|
|
217
254
|
hasCookieModeIdToken() {
|
|
218
|
-
return !!this.
|
|
255
|
+
return !!this.readToken(this.ID_TOKEN_KEY);
|
|
219
256
|
}
|
|
220
257
|
deleteToken(e) {
|
|
221
258
|
let t = this.getKeyForTokenType(e);
|
|
222
259
|
this.storage.removeItem(t);
|
|
223
260
|
}
|
|
224
261
|
deleteTokens() {
|
|
225
|
-
|
|
262
|
+
let e = this.holdsOnlyOtherAppSession();
|
|
263
|
+
for (let e of this.tokenValueKeys()) this.removeOwnToken(e);
|
|
264
|
+
e || (this.storage.removeItem(this.scopes), this.clearDeliveryMode(), this.removeCsrfToken()), this.appId && this.getHostedSignIn() === void 0 && this.storage.getItem(this.hostedSignInKey()) || this.storage.removeItem(this.hostedSignInKey());
|
|
265
|
+
}
|
|
266
|
+
setHostedSignIn(e) {
|
|
267
|
+
this.storage.setItem(this.hostedSignInKey(), JSON.stringify({
|
|
268
|
+
appId: this.appId ?? "",
|
|
269
|
+
returnUrl: e
|
|
270
|
+
}));
|
|
271
|
+
}
|
|
272
|
+
getHostedSignIn() {
|
|
273
|
+
try {
|
|
274
|
+
let e = JSON.parse(this.storage.getItem(this.hostedSignInKey()) ?? "");
|
|
275
|
+
return e.appId !== (this.appId ?? "") || typeof e.returnUrl != "string" ? void 0 : e.returnUrl || void 0;
|
|
276
|
+
} catch {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
hostedSignInKey() {
|
|
281
|
+
return `${this.keyStoragePrefix}${this.STORAGE_PREFIX}hosted_sign_in`;
|
|
226
282
|
}
|
|
227
283
|
getDeviceId() {
|
|
228
284
|
return this.storage.getItem(this.deviceId) ?? void 0;
|
|
@@ -269,7 +325,7 @@ var M = /* @__PURE__ */ function(e) {
|
|
|
269
325
|
}
|
|
270
326
|
getIdToken() {
|
|
271
327
|
try {
|
|
272
|
-
return this.
|
|
328
|
+
return this.readToken(this.ID_TOKEN_KEY);
|
|
273
329
|
} catch {
|
|
274
330
|
return;
|
|
275
331
|
}
|
|
@@ -281,7 +337,7 @@ var M = /* @__PURE__ */ function(e) {
|
|
|
281
337
|
}
|
|
282
338
|
clearIdToken() {
|
|
283
339
|
try {
|
|
284
|
-
this.
|
|
340
|
+
this.removeOwnToken(this.ID_TOKEN_KEY);
|
|
285
341
|
} catch {}
|
|
286
342
|
}
|
|
287
343
|
getCsrfToken() {
|
|
@@ -297,6 +353,9 @@ var M = /* @__PURE__ */ function(e) {
|
|
|
297
353
|
} catch {}
|
|
298
354
|
}
|
|
299
355
|
clearCsrfToken() {
|
|
356
|
+
this.holdsOnlyOtherAppSession() || this.removeCsrfToken();
|
|
357
|
+
}
|
|
358
|
+
removeCsrfToken() {
|
|
300
359
|
try {
|
|
301
360
|
this.storage.removeItem(this.CSRF_TOKEN_KEY);
|
|
302
361
|
} catch {}
|
|
@@ -495,10 +554,14 @@ var M = /* @__PURE__ */ function(e) {
|
|
|
495
554
|
}, ge = (e, t) => {
|
|
496
555
|
if (!e || typeof e != "object") return;
|
|
497
556
|
let n = e;
|
|
498
|
-
if (n.error
|
|
557
|
+
if (n.error !== "upgrade_required") return;
|
|
558
|
+
let r = Array.isArray(n.available_factors) ? n.available_factors.filter((e) => typeof e == "string") : void 0;
|
|
559
|
+
return {
|
|
499
560
|
acrValues: typeof n.acr_values == "string" && n.acr_values ? n.acr_values : void 0,
|
|
500
561
|
maxAge: me(n.max_age),
|
|
501
|
-
status: t
|
|
562
|
+
status: t,
|
|
563
|
+
...r ? { availableFactors: r } : {},
|
|
564
|
+
...typeof n.sign_in_required == "boolean" ? { signInRequired: n.sign_in_required } : {}
|
|
502
565
|
};
|
|
503
566
|
}, _e = (e, t, n) => ({
|
|
504
567
|
channel: e,
|
|
@@ -550,7 +613,9 @@ var M = /* @__PURE__ */ function(e) {
|
|
|
550
613
|
requiredLevel: f,
|
|
551
614
|
maxAge: m,
|
|
552
615
|
status: n,
|
|
553
|
-
channels: l.map((e) => e.channel)
|
|
616
|
+
channels: l.map((e) => e.channel),
|
|
617
|
+
...o?.availableFactors ? { availableFactors: o.availableFactors } : {},
|
|
618
|
+
...o?.signInRequired === void 0 ? {} : { signInRequired: o.signInRequired }
|
|
554
619
|
},
|
|
555
620
|
diagnostics: s
|
|
556
621
|
};
|
|
@@ -583,36 +648,40 @@ var M = /* @__PURE__ */ function(e) {
|
|
|
583
648
|
}
|
|
584
649
|
}, Ae = (e) => typeof e == "object" && !!e && e.email_verification_required === !0, je = "error.service.unavailable", Me = "Passflow is temporarily unavailable. Please try again in a moment.", V = class extends Error {
|
|
585
650
|
constructor(e, t) {
|
|
586
|
-
super(), this.id = e?.id ?? "unknown", this.message = e?.message ?? e ?? "Something went wrong", this.status = e?.status ?? 500, this.location = e?.location ?? "unknown", this.time = e?.time ?? (/* @__PURE__ */ new Date()).toISOString(), t?.cause !== void 0 && (this.cause = t.cause);
|
|
651
|
+
super(), this.name = "PassflowError", this.id = e?.id ?? "unknown", this.message = e?.message ?? e ?? "Something went wrong", this.status = e?.status ?? 500, this.location = e?.location ?? "unknown", this.time = e?.time ?? (/* @__PURE__ */ new Date()).toISOString(), t?.cause !== void 0 && (this.cause = t.cause);
|
|
587
652
|
}
|
|
588
|
-
}, Ne =
|
|
653
|
+
}, Ne = "error.api.password.change.required", Pe = class extends V {
|
|
654
|
+
constructor(e, t) {
|
|
655
|
+
super(e, t), this.name = "PassflowPasswordChangeRequiredError";
|
|
656
|
+
}
|
|
657
|
+
}, Fe = /* @__PURE__ */ function(e) {
|
|
589
658
|
return e.google = "google", e.facebook = "facebook", e;
|
|
590
|
-
}({}),
|
|
659
|
+
}({}), Ie = Object.freeze([
|
|
591
660
|
"debug_otp_code_for_registration",
|
|
592
661
|
"fcm_server_key",
|
|
593
662
|
"webpush_vapid_private_key"
|
|
594
|
-
]),
|
|
663
|
+
]), Le = "mask://", Re = "error.server.update.settings.masked.value.unknown", ze = (e) => typeof e == "string" && e.startsWith("mask://"), Be = /* @__PURE__ */ function(e) {
|
|
595
664
|
return e.web = "web", e.ios = "ios", e.android = "android", e;
|
|
596
665
|
}({});
|
|
597
|
-
function
|
|
666
|
+
function Ve(e) {
|
|
598
667
|
return e;
|
|
599
668
|
}
|
|
600
|
-
function
|
|
669
|
+
function He(e, t) {
|
|
601
670
|
let n = e;
|
|
602
671
|
return Object.entries(t).forEach(([e, t]) => {
|
|
603
672
|
n = n.replace(`:${e}`, t);
|
|
604
673
|
}), n;
|
|
605
674
|
}
|
|
606
|
-
var
|
|
675
|
+
var Ue = /* @__PURE__ */ function(e) {
|
|
607
676
|
return e.Disabled = "disabled", e.Optional = "optional", e.Required = "required", e;
|
|
608
|
-
}({}),
|
|
677
|
+
}({}), We = 3, Ge = 1e3, Ke = (e) => (t) => {
|
|
609
678
|
let n = e.headers?.[t] ?? e.headers?.[t.toLowerCase()];
|
|
610
679
|
return Array.isArray(n) ? n.join(", ") : n;
|
|
611
|
-
},
|
|
680
|
+
}, qe = (e) => be(e.status, Ke(e), e.data), Je = (e) => qe(e) !== void 0, Ye = (n) => e.isAxiosError(n) && !n.response && (n.code === t.ERR_NETWORK || !n.code && n.cause instanceof TypeError), Xe = [
|
|
612
681
|
502,
|
|
613
682
|
503,
|
|
614
683
|
504
|
|
615
|
-
],
|
|
684
|
+
], Ze = (e) => typeof e == "object" && !!e && typeof e.error == "object" && e.error !== null, Qe = (e, n) => {
|
|
616
685
|
let r = new t(e.message, e.code);
|
|
617
686
|
return e.cause instanceof TypeError && (r.cause = e.cause), new V({
|
|
618
687
|
id: je,
|
|
@@ -621,10 +690,10 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
621
690
|
location: e.config?.url ?? "unknown",
|
|
622
691
|
time: (/* @__PURE__ */ new Date()).toISOString()
|
|
623
692
|
}, { cause: r });
|
|
624
|
-
},
|
|
693
|
+
}, $e = (e) => e?.includes(z.refresh) ?? !1, et = (e) => e?.includes("/auth/session/") ?? !1, tt = (e) => e?.includes("logout") ?? !1, nt = "__passflowOwnBearer", rt = (e) => typeof e == "object" && !!e && e[nt] === !0, it = (e) => e ? {
|
|
625
694
|
headers: { [o]: `Bearer ${e}` },
|
|
626
|
-
[
|
|
627
|
-
} : {},
|
|
695
|
+
[nt]: !0
|
|
696
|
+
} : {}, at = class {
|
|
628
697
|
get origin() {
|
|
629
698
|
return this._platform.getCurrentUrl()?.origin ?? "";
|
|
630
699
|
}
|
|
@@ -642,7 +711,10 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
642
711
|
"upgrade"
|
|
643
712
|
];
|
|
644
713
|
let { url: i, appId: l, keyStoragePrefix: u } = t;
|
|
645
|
-
this._platform = t.platform ?? ae, this.url = i || "https://auth.passflow.cloud", this.upgradeDomain = ke(i), this.storageManager = n ?? new ne({
|
|
714
|
+
this._platform = t.platform ?? ae, this.url = i || "https://auth.passflow.cloud", this.upgradeDomain = ke(i), this.storageManager = n ?? new ne({
|
|
715
|
+
prefix: u ?? "",
|
|
716
|
+
appId: l
|
|
717
|
+
}), this.deviceService = r ?? new re(this.storageManager), this.tokenService = new k(this.storageManager), this.tokenDeliveryManager = new P(this.storageManager), l && (this.appId = l, this.defaultHeaders = {
|
|
646
718
|
...this.defaultHeaders,
|
|
647
719
|
[a]: l
|
|
648
720
|
});
|
|
@@ -655,17 +727,17 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
655
727
|
baseURL: this.url,
|
|
656
728
|
headers: { ...this.defaultHeaders }
|
|
657
729
|
}), this.instance.interceptors.request.use(async (e) => {
|
|
658
|
-
if (this.isNonAuthEndpoint(e.url) ||
|
|
730
|
+
if (this.isNonAuthEndpoint(e.url) || rt(e) || et(e.url)) return e;
|
|
659
731
|
if (this.tokenDeliveryManager.isCookieMode()) {
|
|
660
732
|
e.withCredentials = !0;
|
|
661
733
|
let t = this.storageManager.getCsrfToken();
|
|
662
734
|
return t && (e.headers["X-CSRF-Token"] = t), e;
|
|
663
735
|
}
|
|
664
|
-
if (
|
|
736
|
+
if ($e(e.url)) return e;
|
|
665
737
|
let t = this.storageManager.getTokens();
|
|
666
738
|
if (!t?.access_token) return e;
|
|
667
739
|
let n = t.access_token;
|
|
668
|
-
if (this.refreshHandler && t.refresh_token &&
|
|
740
|
+
if (this.refreshHandler && t.refresh_token && !tt(e.url)) {
|
|
669
741
|
let e = j(t.access_token);
|
|
670
742
|
if (A(e, 30)) {
|
|
671
743
|
let t = !A(e, 0);
|
|
@@ -681,8 +753,8 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
681
753
|
}
|
|
682
754
|
return e.headers[o] = `Bearer ${n}`, e;
|
|
683
755
|
}), this.instance.interceptors.response.use((e) => e, async (e) => {
|
|
684
|
-
if (e.response?.status !== 401 ||
|
|
685
|
-
let t =
|
|
756
|
+
if (e.response?.status !== 401 || $e(e.config?.url) || et(e.config?.url) || rt(e.config) || this.isUpgradeTransactionError(e) || this.tokenDeliveryManager.setSessionInvalid(), e.response && this.upgradeHandler && !et(e.config?.url)) {
|
|
757
|
+
let t = qe(e.response);
|
|
686
758
|
if (t) try {
|
|
687
759
|
return await this.upgradeHandler(e, t);
|
|
688
760
|
} catch (t) {
|
|
@@ -693,7 +765,7 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
693
765
|
});
|
|
694
766
|
}
|
|
695
767
|
isUpgradeTransactionError(e) {
|
|
696
|
-
return Te(e.config) || e.response !== void 0 &&
|
|
768
|
+
return Te(e.config) || e.response !== void 0 && Je(e.response);
|
|
697
769
|
}
|
|
698
770
|
setUpgradeInterceptor(e) {
|
|
699
771
|
this.upgradeHandler = e;
|
|
@@ -715,7 +787,7 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
715
787
|
}
|
|
716
788
|
async handleRateLimitError(e) {
|
|
717
789
|
let t = e.config;
|
|
718
|
-
if (!t ||
|
|
790
|
+
if (!t || $e(t.url)) return Promise.reject(e);
|
|
719
791
|
let n = t.method?.toUpperCase();
|
|
720
792
|
if (![
|
|
721
793
|
"GET",
|
|
@@ -723,8 +795,8 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
723
795
|
"OPTIONS"
|
|
724
796
|
].includes(n || "")) return Promise.reject(e);
|
|
725
797
|
let r = t._retryCount || 0;
|
|
726
|
-
if (r >=
|
|
727
|
-
let i =
|
|
798
|
+
if (r >= We) return Promise.reject(e);
|
|
799
|
+
let i = Ge * 2 ** r, a = e.response?.headers?.["retry-after"];
|
|
728
800
|
if (a) {
|
|
729
801
|
let e = Number.parseInt(a, 10);
|
|
730
802
|
if (!Number.isNaN(e)) i = e * 1e3;
|
|
@@ -736,14 +808,14 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
736
808
|
return await new Promise((e) => setTimeout(e, i)), t._retryCount = r + 1, this.instance.request(t);
|
|
737
809
|
}
|
|
738
810
|
async handleAxiosError(e) {
|
|
739
|
-
if (
|
|
811
|
+
if (Ye(e)) return Promise.reject(Qe(e, 0));
|
|
740
812
|
if (!e.response) return Promise.reject(e);
|
|
741
813
|
let t = e.response.status;
|
|
742
|
-
if (
|
|
814
|
+
if (Xe.includes(t) && !Ze(e.response.data)) return Promise.reject(Qe(e, t));
|
|
743
815
|
let n = e.response.data;
|
|
744
816
|
if ("error" in n && typeof n.error == "object" && n.error !== null) {
|
|
745
817
|
let { error: e } = n;
|
|
746
|
-
return Promise.reject(new V(e));
|
|
818
|
+
return e.id === "error.api.password.change.required" ? Promise.reject(new Pe(e)) : Promise.reject(new V(e));
|
|
747
819
|
}
|
|
748
820
|
return Promise.reject(new V({
|
|
749
821
|
id: `error.http.${t}`,
|
|
@@ -790,9 +862,9 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
790
862
|
[a]: e
|
|
791
863
|
}, this.instance.defaults.headers[a] = e;
|
|
792
864
|
}
|
|
793
|
-
},
|
|
865
|
+
}, ot = class {
|
|
794
866
|
constructor(e, t, n) {
|
|
795
|
-
this.axiosClient = new
|
|
867
|
+
this.axiosClient = new at(e, t, n);
|
|
796
868
|
}
|
|
797
869
|
setAppId(e) {
|
|
798
870
|
this.axiosClient.setAppId(e);
|
|
@@ -800,7 +872,7 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
800
872
|
getAppSettings() {
|
|
801
873
|
return this.axiosClient.get(z.appSettings);
|
|
802
874
|
}
|
|
803
|
-
},
|
|
875
|
+
}, st = { withCredentials: !0 }, ct = 15e3, lt = "Sign-in failed. Start again.", ut = "Something went wrong. Try again later.", dt = (e, t, n, r) => {
|
|
804
876
|
if (e instanceof V) return e;
|
|
805
877
|
let i = e?.response?.data?.error;
|
|
806
878
|
return new V({
|
|
@@ -810,9 +882,9 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
810
882
|
location: t,
|
|
811
883
|
time: (/* @__PURE__ */ new Date()).toISOString()
|
|
812
884
|
});
|
|
813
|
-
},
|
|
885
|
+
}, ft = class {
|
|
814
886
|
constructor(e, t, n) {
|
|
815
|
-
this.axiosClient = new
|
|
887
|
+
this.axiosClient = new at(e, t, n);
|
|
816
888
|
}
|
|
817
889
|
setAppId(e) {
|
|
818
890
|
this.axiosClient.setAppId(e);
|
|
@@ -831,7 +903,7 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
831
903
|
device: t,
|
|
832
904
|
os: n
|
|
833
905
|
};
|
|
834
|
-
return this.axiosClient.post(z.signin, r,
|
|
906
|
+
return this.axiosClient.post(z.signin, r, st);
|
|
835
907
|
}
|
|
836
908
|
signUp(e) {
|
|
837
909
|
let { create_tenant: t, anonymous: n } = e, r = {
|
|
@@ -839,16 +911,16 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
839
911
|
create_tenant: t ?? !1,
|
|
840
912
|
anonymous: n ?? !1
|
|
841
913
|
};
|
|
842
|
-
return this.axiosClient.post(z.signup, r,
|
|
914
|
+
return this.axiosClient.post(z.signup, r, st);
|
|
843
915
|
}
|
|
844
916
|
async pkceExchange(e, t) {
|
|
845
917
|
try {
|
|
846
918
|
return await this.axiosClient.post(z.pkceExchange, {
|
|
847
919
|
authz_code: e,
|
|
848
920
|
verifier: t
|
|
849
|
-
},
|
|
921
|
+
}, st);
|
|
850
922
|
} catch (e) {
|
|
851
|
-
throw
|
|
923
|
+
throw dt(e, z.pkceExchange, "error.pkce.exchange", lt);
|
|
852
924
|
}
|
|
853
925
|
}
|
|
854
926
|
async passwordlessSignIn(e, t, n) {
|
|
@@ -861,53 +933,53 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
861
933
|
try {
|
|
862
934
|
return await this.axiosClient.post(z.passwordless, i);
|
|
863
935
|
} catch (e) {
|
|
864
|
-
throw
|
|
936
|
+
throw dt(e, z.passwordless, "error.passwordless.start", ut);
|
|
865
937
|
}
|
|
866
938
|
}
|
|
867
939
|
async passwordlessSignInComplete(e) {
|
|
868
940
|
try {
|
|
869
|
-
return await this.axiosClient.post(z.passwordlessComplete, e,
|
|
941
|
+
return await this.axiosClient.post(z.passwordlessComplete, e, st);
|
|
870
942
|
} catch (e) {
|
|
871
|
-
throw
|
|
943
|
+
throw dt(e, z.passwordlessComplete, "error.passwordless.complete", ut);
|
|
872
944
|
}
|
|
873
945
|
}
|
|
874
946
|
async passwordlessStatus(e, t) {
|
|
875
947
|
try {
|
|
876
948
|
return await this.axiosClient.post(z.passwordlessStatus, e, {
|
|
877
|
-
...
|
|
878
|
-
timeout:
|
|
949
|
+
...st,
|
|
950
|
+
timeout: ct,
|
|
879
951
|
signal: t?.signal
|
|
880
952
|
});
|
|
881
953
|
} catch (e) {
|
|
882
|
-
throw
|
|
954
|
+
throw dt(e, z.passwordlessStatus, "error.passwordless.status", lt);
|
|
883
955
|
}
|
|
884
956
|
}
|
|
885
957
|
async checkRedirectUrl(e) {
|
|
886
958
|
try {
|
|
887
959
|
return (await this.axiosClient.post(z.redirectCheck, { redirect_url: e })).redirect_url;
|
|
888
960
|
} catch (e) {
|
|
889
|
-
throw
|
|
961
|
+
throw dt(e, z.redirectCheck, "error.redirect.check", ut);
|
|
890
962
|
}
|
|
891
963
|
}
|
|
892
964
|
async passwordlessApprovalInfo(e) {
|
|
893
965
|
try {
|
|
894
966
|
return await this.axiosClient.post(z.passwordlessApprovalInfo, e);
|
|
895
967
|
} catch (e) {
|
|
896
|
-
throw
|
|
968
|
+
throw dt(e, z.passwordlessApprovalInfo, "error.passwordless.approval", ut);
|
|
897
969
|
}
|
|
898
970
|
}
|
|
899
971
|
async passwordlessApprovalDecide(e) {
|
|
900
972
|
try {
|
|
901
973
|
return await this.axiosClient.post(z.passwordlessApprovalDecide, e);
|
|
902
974
|
} catch (e) {
|
|
903
|
-
throw
|
|
975
|
+
throw dt(e, z.passwordlessApprovalDecide, "error.passwordless.approval", ut);
|
|
904
976
|
}
|
|
905
977
|
}
|
|
906
978
|
validateEmailCode(e) {
|
|
907
979
|
return this.axiosClient.post(z.passkeyValidate, {
|
|
908
980
|
challenge_id: e.challenge_id,
|
|
909
981
|
otp: e.otp
|
|
910
|
-
},
|
|
982
|
+
}, st);
|
|
911
983
|
}
|
|
912
984
|
logOut(e, t, n = !1) {
|
|
913
985
|
let r = n ? void 0 : {
|
|
@@ -948,7 +1020,7 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
948
1020
|
device: t,
|
|
949
1021
|
passkey_data: e
|
|
950
1022
|
}, a = r ? B.passkeyRegisterComplete : z.passkeyRegisterComplete;
|
|
951
|
-
return this.axiosClient.post(a, i,
|
|
1023
|
+
return this.axiosClient.post(a, i, st);
|
|
952
1024
|
}
|
|
953
1025
|
passkeyAuthenticateStart(e, t, n, r = !1) {
|
|
954
1026
|
let i = {
|
|
@@ -965,7 +1037,7 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
965
1037
|
device: t,
|
|
966
1038
|
passkey_data: e
|
|
967
1039
|
}, a = r ? B.passkeyAuthenticateComplete : z.passkeyAuthenticateComplete;
|
|
968
|
-
return this.axiosClient.post(a, i,
|
|
1040
|
+
return this.axiosClient.post(a, i, st);
|
|
969
1041
|
}
|
|
970
1042
|
passkeyValidate(e, t, n, r = !1, i) {
|
|
971
1043
|
let o = {
|
|
@@ -977,23 +1049,23 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
977
1049
|
let c = i ? { [a]: i } : {};
|
|
978
1050
|
return this.axiosClient.post(s, o, { headers: c });
|
|
979
1051
|
}
|
|
980
|
-
},
|
|
1052
|
+
}, pt = class {
|
|
981
1053
|
constructor(e, t, n) {
|
|
982
|
-
this.axiosClient = new
|
|
1054
|
+
this.axiosClient = new at(e, t, n);
|
|
983
1055
|
}
|
|
984
1056
|
setAppId(e) {
|
|
985
1057
|
this.axiosClient.setAppId(e);
|
|
986
1058
|
}
|
|
987
1059
|
getCLIAuthStatus(e) {
|
|
988
|
-
let t =
|
|
1060
|
+
let t = He(z.cliAuthStatus, { sessionId: e });
|
|
989
1061
|
return this.axiosClient.get(t);
|
|
990
1062
|
}
|
|
991
1063
|
completeCLIAuth(e) {
|
|
992
1064
|
return this.axiosClient.post(z.cliAuthComplete, e);
|
|
993
1065
|
}
|
|
994
|
-
},
|
|
1066
|
+
}, mt = class {
|
|
995
1067
|
constructor(e, t, n) {
|
|
996
|
-
this.axiosClient = new
|
|
1068
|
+
this.axiosClient = new at(e, t, n);
|
|
997
1069
|
}
|
|
998
1070
|
setAppId(e) {
|
|
999
1071
|
this.axiosClient.setAppId(e);
|
|
@@ -1004,27 +1076,27 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
1004
1076
|
getInvitations(e) {
|
|
1005
1077
|
let t = {};
|
|
1006
1078
|
e.groupID && (t.group_id = e.groupID.toString()), e.skip !== void 0 && (t.skip = e.skip.toString()), e.limit !== void 0 && (t.limit = e.limit.toString());
|
|
1007
|
-
let n =
|
|
1079
|
+
let n = He(z.invitationsPath, { tenantID: e.tenantID });
|
|
1008
1080
|
return this.axiosClient.get(n, { params: t }).then((e) => ({
|
|
1009
1081
|
invites: e.invites,
|
|
1010
1082
|
nextPageSkip: e.next_page_skip
|
|
1011
1083
|
}));
|
|
1012
1084
|
}
|
|
1013
1085
|
deleteInvitation(e) {
|
|
1014
|
-
let t =
|
|
1086
|
+
let t = He(z.invitationDelete, { invitationID: e });
|
|
1015
1087
|
return this.axiosClient.delete(t);
|
|
1016
1088
|
}
|
|
1017
1089
|
resendInvitation(e) {
|
|
1018
|
-
let t =
|
|
1090
|
+
let t = He(z.invitationResend, { invitationID: e });
|
|
1019
1091
|
return this.axiosClient.post(t, {});
|
|
1020
1092
|
}
|
|
1021
1093
|
getInvitationLink(e) {
|
|
1022
|
-
let t =
|
|
1094
|
+
let t = He(z.invitationGetLink, { invitationID: e });
|
|
1023
1095
|
return this.axiosClient.get(t);
|
|
1024
1096
|
}
|
|
1025
|
-
},
|
|
1097
|
+
}, ht = class {
|
|
1026
1098
|
constructor(e, t, n) {
|
|
1027
|
-
this.axiosClient = new
|
|
1099
|
+
this.axiosClient = new at(e, t, n);
|
|
1028
1100
|
}
|
|
1029
1101
|
setAppId(e) {
|
|
1030
1102
|
this.axiosClient.setAppId(e);
|
|
@@ -1038,9 +1110,9 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
1038
1110
|
getPasskeySettings() {
|
|
1039
1111
|
return this.axiosClient.get(z.settingsPasskey);
|
|
1040
1112
|
}
|
|
1041
|
-
},
|
|
1113
|
+
}, gt = class {
|
|
1042
1114
|
constructor(e, t, n) {
|
|
1043
|
-
this.axiosClient = new
|
|
1115
|
+
this.axiosClient = new at(e, t, n);
|
|
1044
1116
|
}
|
|
1045
1117
|
setAppId(e) {
|
|
1046
1118
|
this.axiosClient.setAppId(e);
|
|
@@ -1154,58 +1226,58 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
1154
1226
|
let r = `${z.tenantPath}/${e}/group/${t}/invite/email/${n}`;
|
|
1155
1227
|
return this.axiosClient.delete(r);
|
|
1156
1228
|
}
|
|
1157
|
-
},
|
|
1229
|
+
}, _t = (e) => e ? { headers: { Authorization: `Bearer ${e}` } } : {}, vt = (e) => ({
|
|
1158
1230
|
withCredentials: !0,
|
|
1159
|
-
...
|
|
1160
|
-
}),
|
|
1231
|
+
..._t(e)
|
|
1232
|
+
}), yt = ({ qr_code_image: e, qr_code: t, ...n }) => ({
|
|
1161
1233
|
...n,
|
|
1162
1234
|
qr_code: (t ?? e ?? "").replace(/^data:image\/png;base64,/, "")
|
|
1163
|
-
}),
|
|
1235
|
+
}), bt = {
|
|
1164
1236
|
"error.2fa.setup.token.expired": "EXPIRED_TOKEN",
|
|
1165
1237
|
"error.2fa.setup.token.revoked": "REVOKED_TOKEN",
|
|
1166
1238
|
"error.2fa.setup.token.already_used": "ALREADY_USED",
|
|
1167
1239
|
"error.2fa.setup.token.rate.limit.exceeded": "RATE_LIMITED"
|
|
1168
|
-
},
|
|
1240
|
+
}, xt = class {
|
|
1169
1241
|
constructor(e, t, n) {
|
|
1170
|
-
this.axiosClient = new
|
|
1242
|
+
this.axiosClient = new at(e, t, n);
|
|
1171
1243
|
}
|
|
1172
1244
|
setAppId(e) {
|
|
1173
1245
|
this.axiosClient.setAppId(e);
|
|
1174
1246
|
}
|
|
1175
1247
|
getStatus(e) {
|
|
1176
|
-
return this.axiosClient.get(z.twoFactorStatus,
|
|
1248
|
+
return this.axiosClient.get(z.twoFactorStatus, it(e));
|
|
1177
1249
|
}
|
|
1178
1250
|
async beginSetup(e) {
|
|
1179
|
-
return
|
|
1251
|
+
return yt(await this.axiosClient.post(z.twoFactorSetupBegin, {}, it(e)));
|
|
1180
1252
|
}
|
|
1181
1253
|
confirmSetup(e, t) {
|
|
1182
|
-
return this.axiosClient.post(z.twoFactorSetupConfirm, e,
|
|
1254
|
+
return this.axiosClient.post(z.twoFactorSetupConfirm, e, it(t));
|
|
1183
1255
|
}
|
|
1184
|
-
|
|
1185
|
-
return
|
|
1256
|
+
getEnrollment(e) {
|
|
1257
|
+
return this.axiosClient.get(z.twoFactorEnrollment, it(e));
|
|
1186
1258
|
}
|
|
1187
1259
|
sendSetupLink(e) {
|
|
1188
|
-
return this.axiosClient.post(z.twoFactorEnrollmentEmailLink, void 0,
|
|
1260
|
+
return this.axiosClient.post(z.twoFactorEnrollmentEmailLink, void 0, it(e));
|
|
1189
1261
|
}
|
|
1190
1262
|
async beginEnrollment(e) {
|
|
1191
|
-
return
|
|
1263
|
+
return yt(await this.axiosClient.post(z.twoFactorEnrollmentBegin, void 0, it(e)));
|
|
1192
1264
|
}
|
|
1193
1265
|
confirmEnrollment(e, t) {
|
|
1194
|
-
return this.axiosClient.post(z.twoFactorEnrollmentConfirm, t,
|
|
1266
|
+
return this.axiosClient.post(z.twoFactorEnrollmentConfirm, t, it(e));
|
|
1195
1267
|
}
|
|
1196
1268
|
verify(e) {
|
|
1197
1269
|
let { tfa_token: t, code: n, trust_device: r } = e;
|
|
1198
1270
|
return this.axiosClient.post(z.twoFactorVerify, {
|
|
1199
1271
|
code: n,
|
|
1200
1272
|
...r ? { trust_device: !0 } : {}
|
|
1201
|
-
},
|
|
1273
|
+
}, vt(t));
|
|
1202
1274
|
}
|
|
1203
1275
|
useRecoveryCode(e) {
|
|
1204
1276
|
let { tfa_token: t, recovery_code: n, trust_device: r } = e;
|
|
1205
1277
|
return this.axiosClient.post(z.twoFactorRecovery, {
|
|
1206
1278
|
recovery_code: n,
|
|
1207
1279
|
...r ? { trust_device: !0 } : {}
|
|
1208
|
-
},
|
|
1280
|
+
}, vt(t));
|
|
1209
1281
|
}
|
|
1210
1282
|
disable(e) {
|
|
1211
1283
|
return this.axiosClient.delete(z.twoFactor, { data: e });
|
|
@@ -1234,7 +1306,7 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
1234
1306
|
if (e instanceof V) return {
|
|
1235
1307
|
success: !1,
|
|
1236
1308
|
error: {
|
|
1237
|
-
code:
|
|
1309
|
+
code: bt[e.id] ?? this.mapStatusToErrorCode(e.status),
|
|
1238
1310
|
message: e.message || this.getDefaultErrorMessage(e.status)
|
|
1239
1311
|
}
|
|
1240
1312
|
};
|
|
@@ -1276,11 +1348,11 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
1276
1348
|
default: return "An error occurred while validating the magic link.";
|
|
1277
1349
|
}
|
|
1278
1350
|
}
|
|
1279
|
-
getAvailableMethods() {
|
|
1280
|
-
return this.axiosClient.get(z.TwoFactorMethodsAvailable);
|
|
1351
|
+
async getAvailableMethods() {
|
|
1352
|
+
return (await this.axiosClient.get(z.TwoFactorMethodsAvailable))?.available_methods ?? [];
|
|
1281
1353
|
}
|
|
1282
|
-
getRegisteredMethods() {
|
|
1283
|
-
return this.axiosClient.get(z.TwoFactorMethodsRegistered);
|
|
1354
|
+
async getRegisteredMethods() {
|
|
1355
|
+
return (await this.axiosClient.get(z.TwoFactorMethodsRegistered))?.registered_methods ?? [];
|
|
1284
1356
|
}
|
|
1285
1357
|
startMethodSetup(e, t) {
|
|
1286
1358
|
return this.axiosClient.post(z.TwoFactorSetupStart, {
|
|
@@ -1295,32 +1367,32 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
1295
1367
|
});
|
|
1296
1368
|
}
|
|
1297
1369
|
removeMethod(e) {
|
|
1298
|
-
let t =
|
|
1370
|
+
let t = He(z.TwoFactorMethodRemove, { id: e });
|
|
1299
1371
|
return this.axiosClient.delete(t);
|
|
1300
1372
|
}
|
|
1301
1373
|
requestChallenge(e, t) {
|
|
1302
|
-
return this.axiosClient.post(z.TwoFactorChallenge, e,
|
|
1374
|
+
return this.axiosClient.post(z.TwoFactorChallenge, e, _t(t));
|
|
1303
1375
|
}
|
|
1304
1376
|
verifyV2(e, t) {
|
|
1305
1377
|
let { trust_device: n, ...r } = e;
|
|
1306
1378
|
return this.axiosClient.post(z.TwoFactorVerifyV2, {
|
|
1307
1379
|
...r,
|
|
1308
1380
|
...n ? { trust_device: !0 } : {}
|
|
1309
|
-
},
|
|
1381
|
+
}, vt(t));
|
|
1310
1382
|
}
|
|
1311
1383
|
switchToAlternative(e, t) {
|
|
1312
|
-
return this.axiosClient.post(z.TwoFactorAlternative, e,
|
|
1384
|
+
return this.axiosClient.post(z.TwoFactorAlternative, e, _t(t));
|
|
1313
1385
|
}
|
|
1314
1386
|
async getTrustedDevices() {
|
|
1315
1387
|
return (await this.axiosClient.get(z.TwoFactorTrustedDevices, { withCredentials: !0 }))?.devices ?? [];
|
|
1316
1388
|
}
|
|
1317
1389
|
revokeTrustedDevice(e) {
|
|
1318
|
-
let t =
|
|
1390
|
+
let t = He(z.TwoFactorTrustedDeviceRevoke, { id: e });
|
|
1319
1391
|
return this.axiosClient.delete(t);
|
|
1320
1392
|
}
|
|
1321
|
-
},
|
|
1393
|
+
}, St = class {
|
|
1322
1394
|
constructor(e, t, n) {
|
|
1323
|
-
this.axiosClient = new
|
|
1395
|
+
this.axiosClient = new at(e, t, n);
|
|
1324
1396
|
}
|
|
1325
1397
|
setAppId(e) {
|
|
1326
1398
|
this.axiosClient.setAppId(e);
|
|
@@ -1334,9 +1406,9 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
1334
1406
|
async commitHostedUpgrade(e) {
|
|
1335
1407
|
await this.axiosClient.post(z.hostedUpgrade, e, { withCredentials: !0 });
|
|
1336
1408
|
}
|
|
1337
|
-
},
|
|
1409
|
+
}, Ct = class {
|
|
1338
1410
|
constructor(e, t, n) {
|
|
1339
|
-
this.axiosClient = new
|
|
1411
|
+
this.axiosClient = new at(e, t, n);
|
|
1340
1412
|
}
|
|
1341
1413
|
setAppId(e) {
|
|
1342
1414
|
this.axiosClient.setAppId(e);
|
|
@@ -1367,48 +1439,48 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
1367
1439
|
passkey_data: e
|
|
1368
1440
|
});
|
|
1369
1441
|
}
|
|
1370
|
-
},
|
|
1442
|
+
}, wt = 10, Tt = 20, Et = class extends Error {
|
|
1371
1443
|
constructor(e) {
|
|
1372
1444
|
super(`Passflow fetch middleware '${e}' resolved without calling next(). Every registered middleware must delegate exactly once; swallowing a request would drop a caller's fetch inside the Passflow wrapper.`), this.name = "FetchMiddlewareContractError", this.middlewareName = e;
|
|
1373
1445
|
}
|
|
1374
|
-
},
|
|
1446
|
+
}, Dt = [], Ot = 0, kt = !1, At, jt, Mt = (e, t) => e.priority - t.priority || e.seq - t.seq, Nt = () => typeof globalThis > "u" ? void 0 : globalThis, Pt = async (e, t, n, r) => {
|
|
1375
1447
|
if (t >= e.length) {
|
|
1376
|
-
let e =
|
|
1448
|
+
let e = At;
|
|
1377
1449
|
if (!e) throw Error("Passflow fetch registry: no captured fetch to delegate to.");
|
|
1378
1450
|
return e(n, r);
|
|
1379
1451
|
}
|
|
1380
1452
|
let i = e[t];
|
|
1381
|
-
if (!i) return
|
|
1382
|
-
let a = !1, o = await i.middleware((n, r) => (a = !0,
|
|
1383
|
-
if (!a) throw new
|
|
1453
|
+
if (!i) return Pt(e, e.length, n, r);
|
|
1454
|
+
let a = !1, o = await i.middleware((n, r) => (a = !0, Pt(e, t + 1, n, r)), n, r);
|
|
1455
|
+
if (!a) throw new Et(i.name);
|
|
1384
1456
|
return o;
|
|
1385
|
-
},
|
|
1386
|
-
let e =
|
|
1457
|
+
}, Ft = () => {
|
|
1458
|
+
let e = Nt();
|
|
1387
1459
|
if (!e || typeof e.fetch != "function") return !1;
|
|
1388
|
-
let t = e.fetch.bind(e), n = (e, t) =>
|
|
1389
|
-
return
|
|
1390
|
-
},
|
|
1391
|
-
let e =
|
|
1392
|
-
e &&
|
|
1393
|
-
},
|
|
1394
|
-
if (!
|
|
1460
|
+
let t = e.fetch.bind(e), n = (e, t) => Pt([...Dt].sort(Mt), 0, e, t);
|
|
1461
|
+
return At = t, jt = n, e.fetch = n, kt = !0, !0;
|
|
1462
|
+
}, It = () => {
|
|
1463
|
+
let e = Nt();
|
|
1464
|
+
e && jt && e.fetch === jt && (At && (e.fetch = At), kt = !1, jt = void 0, At = void 0);
|
|
1465
|
+
}, Lt = (e, t) => {
|
|
1466
|
+
if (!kt && !Ft()) return () => {};
|
|
1395
1467
|
let n = {
|
|
1396
1468
|
middleware: e,
|
|
1397
1469
|
name: t.name,
|
|
1398
1470
|
priority: t.priority,
|
|
1399
|
-
seq:
|
|
1471
|
+
seq: Ot++
|
|
1400
1472
|
};
|
|
1401
|
-
|
|
1473
|
+
Dt.push(n);
|
|
1402
1474
|
let r = !1;
|
|
1403
1475
|
return () => {
|
|
1404
|
-
r || (r = !0,
|
|
1476
|
+
r || (r = !0, Dt = Dt.filter((e) => e !== n), Dt.length === 0 && It());
|
|
1405
1477
|
};
|
|
1406
|
-
},
|
|
1407
|
-
let e =
|
|
1478
|
+
}, Rt = () => {
|
|
1479
|
+
let e = Nt();
|
|
1408
1480
|
return {
|
|
1409
|
-
installed:
|
|
1410
|
-
names: [...
|
|
1411
|
-
foreignPatch:
|
|
1481
|
+
installed: kt,
|
|
1482
|
+
names: [...Dt].sort(Mt).map((e) => e.name),
|
|
1483
|
+
foreignPatch: kt && !!e && !!jt && e.fetch !== jt
|
|
1412
1484
|
};
|
|
1413
1485
|
}, H = class e extends Error {
|
|
1414
1486
|
constructor(t) {
|
|
@@ -1479,7 +1551,7 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
1479
1551
|
let e = `M2MError [${this.code}]: ${this.message}`;
|
|
1480
1552
|
return this.status && (e += ` (HTTP ${this.status})`), e;
|
|
1481
1553
|
}
|
|
1482
|
-
},
|
|
1554
|
+
}, zt = class extends H {
|
|
1483
1555
|
constructor(e, t) {
|
|
1484
1556
|
super({
|
|
1485
1557
|
code: "temporarily_unavailable",
|
|
@@ -1488,7 +1560,7 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
1488
1560
|
cause: t
|
|
1489
1561
|
}), this.name = "M2MNetworkError";
|
|
1490
1562
|
}
|
|
1491
|
-
},
|
|
1563
|
+
}, Bt = class extends H {
|
|
1492
1564
|
constructor(e, t) {
|
|
1493
1565
|
super({
|
|
1494
1566
|
code: "invalid_request",
|
|
@@ -1497,7 +1569,7 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
1497
1569
|
cause: t
|
|
1498
1570
|
}), this.name = "M2MTokenParseError";
|
|
1499
1571
|
}
|
|
1500
|
-
},
|
|
1572
|
+
}, Vt = class extends H {
|
|
1501
1573
|
constructor(e) {
|
|
1502
1574
|
super({
|
|
1503
1575
|
code: "invalid_request",
|
|
@@ -1505,7 +1577,7 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
1505
1577
|
status: 400
|
|
1506
1578
|
}), this.name = "M2MConfigError";
|
|
1507
1579
|
}
|
|
1508
|
-
},
|
|
1580
|
+
}, Ht = {
|
|
1509
1581
|
InvalidRequest: "invalid_request",
|
|
1510
1582
|
InvalidClient: "invalid_client",
|
|
1511
1583
|
InvalidGrant: "invalid_grant",
|
|
@@ -1515,14 +1587,14 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
1515
1587
|
RateLimitExceeded: "rate_limit_exceeded",
|
|
1516
1588
|
ServerError: "server_error",
|
|
1517
1589
|
TemporarilyUnavailable: "temporarily_unavailable"
|
|
1518
|
-
},
|
|
1590
|
+
}, Ut = {
|
|
1519
1591
|
TOKEN_ENDPOINT: "/oauth2/token",
|
|
1520
1592
|
TIMEOUT: 1e4,
|
|
1521
1593
|
RETRIES: 3,
|
|
1522
1594
|
RETRY_DELAY: 1e3,
|
|
1523
1595
|
REFRESH_THRESHOLD: 30,
|
|
1524
1596
|
CONTENT_TYPE: "application/x-www-form-urlencoded"
|
|
1525
|
-
},
|
|
1597
|
+
}, Wt = class {
|
|
1526
1598
|
constructor() {
|
|
1527
1599
|
this.cache = /* @__PURE__ */ new Map();
|
|
1528
1600
|
}
|
|
@@ -1539,18 +1611,18 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
1539
1611
|
delete(e) {
|
|
1540
1612
|
return this.cache.delete(e), Promise.resolve();
|
|
1541
1613
|
}
|
|
1542
|
-
},
|
|
1614
|
+
}, Gt = {
|
|
1543
1615
|
shouldRetry(e, t) {
|
|
1544
1616
|
return t >= 3 ? !1 : e.code === "server_error" || e.code === "temporarily_unavailable" || e.code === "rate_limit_exceeded" || e.status !== void 0 && e.status >= 500;
|
|
1545
1617
|
},
|
|
1546
1618
|
getDelay(e) {
|
|
1547
1619
|
return 2 ** (e - 1) * 1e3;
|
|
1548
1620
|
}
|
|
1549
|
-
},
|
|
1621
|
+
}, Kt = class {
|
|
1550
1622
|
constructor(e) {
|
|
1551
|
-
if (!e.url) throw new
|
|
1552
|
-
if (!e.clientId) throw new
|
|
1553
|
-
if (!e.clientSecret) throw new
|
|
1623
|
+
if (!e.url) throw new Vt("M2M client requires a URL");
|
|
1624
|
+
if (!e.clientId) throw new Vt("M2M client requires a clientId");
|
|
1625
|
+
if (!e.clientSecret) throw new Vt("M2M client requires a clientSecret");
|
|
1554
1626
|
let t = e.url.replace(/\/$/, "");
|
|
1555
1627
|
this.config = {
|
|
1556
1628
|
url: t,
|
|
@@ -1559,16 +1631,16 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
1559
1631
|
scopes: e.scopes,
|
|
1560
1632
|
audience: e.audience,
|
|
1561
1633
|
autoRefresh: e.autoRefresh ?? !1,
|
|
1562
|
-
refreshThreshold: e.refreshThreshold ??
|
|
1563
|
-
timeout: e.timeout ??
|
|
1564
|
-
retries: e.retries ??
|
|
1565
|
-
retryDelay: e.retryDelay ??
|
|
1634
|
+
refreshThreshold: e.refreshThreshold ?? Ut.REFRESH_THRESHOLD,
|
|
1635
|
+
timeout: e.timeout ?? Ut.TIMEOUT,
|
|
1636
|
+
retries: e.retries ?? Ut.RETRIES,
|
|
1637
|
+
retryDelay: e.retryDelay ?? Ut.RETRY_DELAY,
|
|
1566
1638
|
retryStrategy: e.retryStrategy,
|
|
1567
1639
|
cache: e.cache,
|
|
1568
1640
|
onTokenRequest: e.onTokenRequest,
|
|
1569
1641
|
onTokenResponse: e.onTokenResponse,
|
|
1570
1642
|
onError: e.onError
|
|
1571
|
-
}, this.cache = e.cache ?? new
|
|
1643
|
+
}, this.cache = e.cache ?? new Wt(), this.retryStrategy = e.retryStrategy ?? Gt, this.tokenEndpoint = `${t}${Ut.TOKEN_ENDPOINT}`;
|
|
1572
1644
|
}
|
|
1573
1645
|
getCacheKey(e, t) {
|
|
1574
1646
|
let n = e?.sort().join(",") || "", r = t?.sort().join(",") || "";
|
|
@@ -1613,7 +1685,7 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
1613
1685
|
let e = await fetch(this.tokenEndpoint, {
|
|
1614
1686
|
method: "POST",
|
|
1615
1687
|
headers: {
|
|
1616
|
-
"Content-Type":
|
|
1688
|
+
"Content-Type": Ut.CONTENT_TYPE,
|
|
1617
1689
|
Accept: "application/json"
|
|
1618
1690
|
},
|
|
1619
1691
|
body: t.toString(),
|
|
@@ -1638,7 +1710,7 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
1638
1710
|
}
|
|
1639
1711
|
return a;
|
|
1640
1712
|
} catch (e) {
|
|
1641
|
-
throw clearTimeout(r), e instanceof Error && e.name === "AbortError" ? new
|
|
1713
|
+
throw clearTimeout(r), e instanceof Error && e.name === "AbortError" ? new zt(`Request timed out after ${this.config.timeout}ms`) : e instanceof TypeError && e.message.includes("fetch") ? new zt(`Network error: ${e.message}`, e) : e instanceof H ? e : H.fromError(e instanceof Error ? e : Error(String(e)));
|
|
1642
1714
|
}
|
|
1643
1715
|
}
|
|
1644
1716
|
async executeWithRetry(e) {
|
|
@@ -1681,13 +1753,13 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
1681
1753
|
parseToken(e) {
|
|
1682
1754
|
try {
|
|
1683
1755
|
let t = e.split(".");
|
|
1684
|
-
if (t.length !== 3) throw new
|
|
1756
|
+
if (t.length !== 3) throw new Bt("Invalid JWT format: expected 3 parts");
|
|
1685
1757
|
let n = t[1];
|
|
1686
|
-
if (!n) throw new
|
|
1758
|
+
if (!n) throw new Bt("Invalid JWT format: missing payload");
|
|
1687
1759
|
let r = atob(n.replace(/-/g, "+").replace(/_/g, "/")), i = JSON.parse(r);
|
|
1688
1760
|
return i.scopes && typeof i.scopes == "string" ? i.scopes = i.scopes.split(" ") : i.scopes || (i.scopes = []), i;
|
|
1689
1761
|
} catch (e) {
|
|
1690
|
-
throw e instanceof
|
|
1762
|
+
throw e instanceof Bt ? e : new Bt(`Failed to parse token: ${e instanceof Error ? e.message : "Unknown error"}`);
|
|
1691
1763
|
}
|
|
1692
1764
|
}
|
|
1693
1765
|
clearCache() {
|
|
@@ -1702,7 +1774,7 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
1702
1774
|
try {
|
|
1703
1775
|
let e = await fetch(t, {
|
|
1704
1776
|
method: "POST",
|
|
1705
|
-
headers: { "Content-Type":
|
|
1777
|
+
headers: { "Content-Type": Ut.CONTENT_TYPE },
|
|
1706
1778
|
body: n.toString()
|
|
1707
1779
|
});
|
|
1708
1780
|
if (!e.ok && e.status !== 200) {
|
|
@@ -1729,50 +1801,50 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
1729
1801
|
get audience() {
|
|
1730
1802
|
return this.config.audience;
|
|
1731
1803
|
}
|
|
1732
|
-
},
|
|
1804
|
+
}, qt = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", Jt = 32, Yt = (e) => {
|
|
1733
1805
|
let t = "";
|
|
1734
1806
|
for (let n = 0; n < e.length; n += 3) {
|
|
1735
1807
|
let r = e[n], i = e[n + 1], a = e[n + 2];
|
|
1736
|
-
t +=
|
|
1808
|
+
t += qt.charAt(r >> 2), t += qt.charAt((r & 3) << 4 | (i ?? 0) >> 4), i !== void 0 && (t += qt.charAt((i & 15) << 2 | (a ?? 0) >> 6)), a !== void 0 && (t += qt.charAt(a & 63));
|
|
1737
1809
|
}
|
|
1738
1810
|
return t;
|
|
1739
|
-
},
|
|
1811
|
+
}, Xt = () => {
|
|
1740
1812
|
let e = globalThis.crypto;
|
|
1741
1813
|
if (!e?.subtle) throw Error("PKCE needs the Web Crypto API, which is available only in a secure context (https or localhost)");
|
|
1742
1814
|
return e;
|
|
1743
|
-
},
|
|
1744
|
-
let t = await
|
|
1745
|
-
return
|
|
1746
|
-
},
|
|
1747
|
-
let e =
|
|
1815
|
+
}, Zt = async (e) => {
|
|
1816
|
+
let t = await Xt().subtle.digest("SHA-256", new TextEncoder().encode(e));
|
|
1817
|
+
return Yt(new Uint8Array(t));
|
|
1818
|
+
}, Qt = (e = Jt) => Yt(Xt().getRandomValues(new Uint8Array(e))), $t = async () => {
|
|
1819
|
+
let e = Qt(Jt);
|
|
1748
1820
|
return {
|
|
1749
1821
|
verifier: e,
|
|
1750
|
-
challenge: await
|
|
1822
|
+
challenge: await Zt(e)
|
|
1751
1823
|
};
|
|
1752
|
-
},
|
|
1824
|
+
}, en = () => !!globalThis.crypto?.subtle, U = class extends Error {
|
|
1753
1825
|
constructor(e, t) {
|
|
1754
1826
|
super(t), this.code = e, this.name = "PassflowOidcError";
|
|
1755
1827
|
}
|
|
1756
|
-
},
|
|
1828
|
+
}, tn = "Sign in again.", nn = (e) => `This app is type ${e} and is a confidential client (it has a secret). For a browser app set its type to SPA; a server-side app redeems the code on its server with the secret.`, rn = "This app is a confidential client. For a browser app set its type to SPA (or token_endpoint_auth_method to none); a server-side app must redeem the code on its server with the client secret.", an = () => new U("TOKENS_IN_URL_NOT_ALLOWED", "Tokens in the URL are accepted only for apps in Simple mode"), on = "passflow_oidc_pkce", sn = 6e5, cn = (e) => {
|
|
1757
1829
|
try {
|
|
1758
1830
|
let t = new URL(e);
|
|
1759
1831
|
return `${t.protocol}//${t.host}${t.pathname.replace(/\/+$/, "")}`;
|
|
1760
1832
|
} catch {
|
|
1761
1833
|
return e;
|
|
1762
1834
|
}
|
|
1763
|
-
},
|
|
1764
|
-
if (!
|
|
1765
|
-
let t =
|
|
1835
|
+
}, ln = (e) => !e.includes("openid") && (e.includes("id") || e.includes("oidc")) ? [...e, "openid"] : [...e], un = async (e) => {
|
|
1836
|
+
if (!en()) throw new U("SECURE_CONTEXT_REQUIRED", "Sign-in needs the Web Crypto API, which is available only in a secure context (https or localhost)");
|
|
1837
|
+
let t = ln(e.scopes), n = await $t(), r = {
|
|
1766
1838
|
verifier: n.verifier,
|
|
1767
|
-
state:
|
|
1768
|
-
...t.includes("openid") ? { nonce:
|
|
1839
|
+
state: Qt(),
|
|
1840
|
+
...t.includes("openid") ? { nonce: Qt() } : {},
|
|
1769
1841
|
clientId: e.clientId,
|
|
1770
1842
|
redirectUri: e.redirectUri,
|
|
1771
1843
|
scopes: t,
|
|
1772
|
-
expiresAt: Date.now() +
|
|
1844
|
+
expiresAt: Date.now() + sn
|
|
1773
1845
|
};
|
|
1774
1846
|
try {
|
|
1775
|
-
sessionStorage.setItem(
|
|
1847
|
+
sessionStorage.setItem(on, JSON.stringify(r));
|
|
1776
1848
|
} catch {
|
|
1777
1849
|
throw new U("STORAGE_UNAVAILABLE", "Sign-in needs sessionStorage, which cannot be written here");
|
|
1778
1850
|
}
|
|
@@ -1787,37 +1859,37 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
1787
1859
|
code_challenge_method: "S256",
|
|
1788
1860
|
...r.nonce ? { nonce: r.nonce } : {}
|
|
1789
1861
|
}).toString(), i.toString();
|
|
1790
|
-
},
|
|
1862
|
+
}, dn = (e) => {
|
|
1791
1863
|
let t = e;
|
|
1792
1864
|
return typeof t == "object" && !!t && typeof t.verifier == "string" && typeof t.state == "string" && typeof t.clientId == "string" && typeof t.redirectUri == "string" && Array.isArray(t.scopes) && typeof t.expiresAt == "number";
|
|
1793
|
-
},
|
|
1865
|
+
}, fn = () => {
|
|
1794
1866
|
let e;
|
|
1795
1867
|
try {
|
|
1796
|
-
e = sessionStorage.getItem(
|
|
1868
|
+
e = sessionStorage.getItem(on);
|
|
1797
1869
|
} catch {
|
|
1798
1870
|
return { status: "none" };
|
|
1799
1871
|
}
|
|
1800
1872
|
if (!e) return { status: "none" };
|
|
1801
1873
|
try {
|
|
1802
1874
|
let t = JSON.parse(e);
|
|
1803
|
-
if (
|
|
1875
|
+
if (dn(t) && Date.now() < t.expiresAt) return {
|
|
1804
1876
|
status: "live",
|
|
1805
1877
|
slot: t
|
|
1806
1878
|
};
|
|
1807
1879
|
} catch {}
|
|
1808
1880
|
return { status: "unusable" };
|
|
1809
|
-
},
|
|
1881
|
+
}, pn = () => {
|
|
1810
1882
|
try {
|
|
1811
|
-
sessionStorage.removeItem(
|
|
1883
|
+
sessionStorage.removeItem(on);
|
|
1812
1884
|
} catch {}
|
|
1813
|
-
},
|
|
1885
|
+
}, mn = async (e) => {
|
|
1814
1886
|
try {
|
|
1815
1887
|
let t = await e.json();
|
|
1816
1888
|
return typeof t == "object" && t ? t : void 0;
|
|
1817
1889
|
} catch {
|
|
1818
1890
|
return;
|
|
1819
1891
|
}
|
|
1820
|
-
},
|
|
1892
|
+
}, hn = async (e, t, n) => {
|
|
1821
1893
|
let r;
|
|
1822
1894
|
try {
|
|
1823
1895
|
r = await fetch(`${e.replace(/\/+$/, "")}/oidc/token`, {
|
|
@@ -1832,11 +1904,11 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
1832
1904
|
}).toString()
|
|
1833
1905
|
});
|
|
1834
1906
|
} catch {
|
|
1835
|
-
throw new U("TOKEN_EXCHANGE_FAILED",
|
|
1907
|
+
throw new U("TOKEN_EXCHANGE_FAILED", tn);
|
|
1836
1908
|
}
|
|
1837
|
-
let i = await
|
|
1838
|
-
if (!r.ok) throw i?.error === "invalid_client" ? new U("invalid_client",
|
|
1839
|
-
if (typeof i?.access_token != "string") throw new U("TOKEN_EXCHANGE_FAILED",
|
|
1909
|
+
let i = await mn(r);
|
|
1910
|
+
if (!r.ok) throw i?.error === "invalid_client" ? new U("invalid_client", rn) : i?.error === "invalid_grant" ? new U("invalid_grant", tn) : new U("TOKEN_EXCHANGE_FAILED", tn);
|
|
1911
|
+
if (typeof i?.access_token != "string") throw new U("TOKEN_EXCHANGE_FAILED", tn);
|
|
1840
1912
|
let a = typeof i.id_token == "string" ? i.id_token : void 0;
|
|
1841
1913
|
if (n.scopes.includes("openid")) {
|
|
1842
1914
|
let e;
|
|
@@ -1845,7 +1917,7 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
1845
1917
|
} catch {
|
|
1846
1918
|
e = void 0;
|
|
1847
1919
|
}
|
|
1848
|
-
if (!a || e !== n.nonce) throw new U("ID_TOKEN_INVALID", `The ID token is missing or not issued for this sign-in. ${
|
|
1920
|
+
if (!a || e !== n.nonce) throw new U("ID_TOKEN_INVALID", `The ID token is missing or not issued for this sign-in. ${tn}`);
|
|
1849
1921
|
}
|
|
1850
1922
|
return {
|
|
1851
1923
|
access_token: i.access_token,
|
|
@@ -1853,101 +1925,101 @@ var Ve = /* @__PURE__ */ function(e) {
|
|
|
1853
1925
|
...a ? { id_token: a } : {},
|
|
1854
1926
|
scopes: n.scopes
|
|
1855
1927
|
};
|
|
1856
|
-
},
|
|
1928
|
+
}, gn = "error", _n = /* @__PURE__ */ new WeakMap(), vn = (e, t) => {
|
|
1857
1929
|
if (typeof t != "object" && typeof t != "function" || t === null) return !0;
|
|
1858
|
-
let n =
|
|
1859
|
-
return n || (n = /* @__PURE__ */ new WeakSet(),
|
|
1860
|
-
}, W = (e, t) =>
|
|
1930
|
+
let n = _n.get(e);
|
|
1931
|
+
return n || (n = /* @__PURE__ */ new WeakSet(), _n.set(e, n)), !n.has(t) && (n.add(t), !0);
|
|
1932
|
+
}, W = (e, t) => vn(e, t.originalError) ? (e.notify(gn, t), !0) : !1, yn = "passflow-refresh", bn = "passflow-refresh-takeover", xn = "passflow-auth", Sn = Object.freeze([
|
|
1861
1933
|
1e3,
|
|
1862
1934
|
3e3,
|
|
1863
1935
|
1e4,
|
|
1864
1936
|
3e4,
|
|
1865
1937
|
6e4
|
|
1866
|
-
]),
|
|
1938
|
+
]), Cn = .2, wn = 6e5, Tn = 5e3, G = 2e4, En = 2e4, Dn = 1e3, On = 2e3, kn = 1e3, An = 1e4, jn = 5e3;
|
|
1867
1939
|
// lib/refresh/protocol.ts
|
|
1868
|
-
function
|
|
1940
|
+
function Mn(e) {
|
|
1869
1941
|
let t = e ? `:${e}` : "";
|
|
1870
1942
|
return {
|
|
1871
|
-
lock: `${
|
|
1872
|
-
takeoverLock: `${
|
|
1873
|
-
channel: `${
|
|
1943
|
+
lock: `${yn}${t}`,
|
|
1944
|
+
takeoverLock: `${bn}${t}`,
|
|
1945
|
+
channel: `${xn}${t}`
|
|
1874
1946
|
};
|
|
1875
1947
|
}
|
|
1876
1948
|
function K(e) {
|
|
1877
1949
|
return typeof e == "string" && e !== "" ? e : void 0;
|
|
1878
1950
|
}
|
|
1879
|
-
function
|
|
1951
|
+
function Nn(e) {
|
|
1880
1952
|
return typeof e == "number" && Number.isFinite(e) ? e : void 0;
|
|
1881
1953
|
}
|
|
1882
|
-
function
|
|
1954
|
+
function Pn(e) {
|
|
1883
1955
|
return typeof e == "object" && !!e;
|
|
1884
1956
|
}
|
|
1885
|
-
function
|
|
1957
|
+
function Fn(e, t) {
|
|
1886
1958
|
for (let [n, r] of Object.entries(t)) r !== void 0 && (e[n] = r);
|
|
1887
1959
|
return e;
|
|
1888
1960
|
}
|
|
1889
|
-
function
|
|
1890
|
-
if (!
|
|
1961
|
+
function In(e) {
|
|
1962
|
+
if (!Pn(e)) return null;
|
|
1891
1963
|
let t = Array.isArray(e.scopes) ? e.scopes.filter((e) => typeof e == "string") : void 0;
|
|
1892
|
-
return
|
|
1964
|
+
return Fn({}, {
|
|
1893
1965
|
access_token: K(e.access_token),
|
|
1894
1966
|
refresh_token: K(e.refresh_token),
|
|
1895
1967
|
id_token: K(e.id_token),
|
|
1896
1968
|
scopes: Array.isArray(e.scopes) && t?.length === e.scopes.length ? t : void 0
|
|
1897
1969
|
});
|
|
1898
1970
|
}
|
|
1899
|
-
function
|
|
1900
|
-
if (!
|
|
1971
|
+
function Ln(e) {
|
|
1972
|
+
if (!Pn(e)) return null;
|
|
1901
1973
|
let { kind: t, attempt: n, nextAt: r, strikes: i } = e;
|
|
1902
|
-
return t !== "transient" && t !== "auth" || typeof n != "number" || !Number.isInteger(n) || n < 1 ||
|
|
1974
|
+
return t !== "transient" && t !== "auth" || typeof n != "number" || !Number.isInteger(n) || n < 1 || Nn(r) === void 0 || typeof i != "number" || !Number.isFinite(i) || i < 0 ? null : Fn({
|
|
1903
1975
|
kind: t,
|
|
1904
1976
|
attempt: n,
|
|
1905
1977
|
nextAt: r,
|
|
1906
1978
|
strikes: i
|
|
1907
1979
|
}, {
|
|
1908
1980
|
from: K(e.from),
|
|
1909
|
-
failingSince:
|
|
1981
|
+
failingSince: Nn(e.failingSince)
|
|
1910
1982
|
});
|
|
1911
1983
|
}
|
|
1912
|
-
function
|
|
1913
|
-
return
|
|
1984
|
+
function Rn(e) {
|
|
1985
|
+
return Fn({}, {
|
|
1914
1986
|
fp: K(e.fp),
|
|
1915
1987
|
sub: K(e.sub),
|
|
1916
1988
|
sid: K(e.sid),
|
|
1917
|
-
iat:
|
|
1989
|
+
iat: Nn(e.iat)
|
|
1918
1990
|
});
|
|
1919
1991
|
}
|
|
1920
|
-
function
|
|
1921
|
-
if (!
|
|
1992
|
+
function zn(e) {
|
|
1993
|
+
if (!Pn(e)) return null;
|
|
1922
1994
|
let t = e;
|
|
1923
1995
|
if (t.v !== void 0 && t.v !== 1) return null;
|
|
1924
1996
|
let n = K(t.tabId);
|
|
1925
1997
|
if (!n) return null;
|
|
1926
1998
|
switch (t.type) {
|
|
1927
1999
|
case "tokens-refreshed": {
|
|
1928
|
-
let e =
|
|
1929
|
-
return !e || !r || !i ? null :
|
|
2000
|
+
let e = In(t.tokens), r = K(t.from), i = K(t.to);
|
|
2001
|
+
return !e || !r || !i ? null : Fn({
|
|
1930
2002
|
type: t.type,
|
|
1931
2003
|
tabId: n,
|
|
1932
2004
|
tokens: e,
|
|
1933
2005
|
from: r,
|
|
1934
2006
|
to: i
|
|
1935
2007
|
}, {
|
|
1936
|
-
fromIat:
|
|
2008
|
+
fromIat: Nn(t.fromIat),
|
|
1937
2009
|
fromSid: typeof t.fromSid == "string" ? t.fromSid : void 0,
|
|
1938
|
-
sentAt:
|
|
2010
|
+
sentAt: Nn(t.sentAt)
|
|
1939
2011
|
});
|
|
1940
2012
|
}
|
|
1941
2013
|
case "session-refreshed": {
|
|
1942
|
-
let e =
|
|
1943
|
-
return e === void 0 ? null :
|
|
2014
|
+
let e = Nn(t.at);
|
|
2015
|
+
return e === void 0 ? null : Fn({
|
|
1944
2016
|
type: t.type,
|
|
1945
2017
|
tabId: n,
|
|
1946
2018
|
at: e
|
|
1947
2019
|
}, { sub: K(t.sub) });
|
|
1948
2020
|
}
|
|
1949
2021
|
case "still-refreshing": {
|
|
1950
|
-
let e = t.retry === void 0 ? null :
|
|
2022
|
+
let e = t.retry === void 0 ? null : Ln(t.retry);
|
|
1951
2023
|
return e ? {
|
|
1952
2024
|
type: t.type,
|
|
1953
2025
|
tabId: n,
|
|
@@ -1958,7 +2030,7 @@ function Ln(e) {
|
|
|
1958
2030
|
};
|
|
1959
2031
|
}
|
|
1960
2032
|
case "retry-scheduled": {
|
|
1961
|
-
let e =
|
|
2033
|
+
let e = Ln(t);
|
|
1962
2034
|
return e ? {
|
|
1963
2035
|
type: t.type,
|
|
1964
2036
|
tabId: n,
|
|
@@ -1979,10 +2051,10 @@ function Ln(e) {
|
|
|
1979
2051
|
case "signed-out": return {
|
|
1980
2052
|
type: t.type,
|
|
1981
2053
|
tabId: n,
|
|
1982
|
-
...
|
|
2054
|
+
...Rn(t)
|
|
1983
2055
|
};
|
|
1984
2056
|
case "rate-limited": {
|
|
1985
|
-
let e =
|
|
2057
|
+
let e = Nn(t.until);
|
|
1986
2058
|
return e === void 0 ? null : {
|
|
1987
2059
|
type: t.type,
|
|
1988
2060
|
tabId: n,
|
|
@@ -2001,22 +2073,22 @@ function Ln(e) {
|
|
|
2001
2073
|
default: return null;
|
|
2002
2074
|
}
|
|
2003
2075
|
}
|
|
2004
|
-
function
|
|
2076
|
+
function Bn(e, t) {
|
|
2005
2077
|
let n = {
|
|
2006
2078
|
v: 1,
|
|
2007
2079
|
tabId: e
|
|
2008
2080
|
};
|
|
2009
2081
|
if (t.type === "retry-scheduled") {
|
|
2010
2082
|
let { retry: e, ...r } = t;
|
|
2011
|
-
return
|
|
2083
|
+
return Fn(n, {
|
|
2012
2084
|
...r,
|
|
2013
2085
|
...e
|
|
2014
2086
|
});
|
|
2015
2087
|
}
|
|
2016
|
-
return
|
|
2088
|
+
return Fn(n, { ...t });
|
|
2017
2089
|
}
|
|
2018
2090
|
// lib/refresh/resolve.ts
|
|
2019
|
-
var
|
|
2091
|
+
var Vn = "[passflow] navigator.locks or BroadcastChannel is unavailable (they need a secure context); each tab refreshes on its own, with the save checks only", Hn = {
|
|
2020
2092
|
now: () => Date.now(),
|
|
2021
2093
|
random: () => Math.random(),
|
|
2022
2094
|
setTimeout: (e, t) => {
|
|
@@ -2024,28 +2096,28 @@ var zn = "[passflow] navigator.locks or BroadcastChannel is unavailable (they ne
|
|
|
2024
2096
|
return n.unref?.(), () => clearTimeout(n);
|
|
2025
2097
|
}
|
|
2026
2098
|
};
|
|
2027
|
-
function
|
|
2099
|
+
function Un() {
|
|
2028
2100
|
let e = globalThis.crypto;
|
|
2029
2101
|
return typeof e?.randomUUID == "function" ? e.randomUUID() : `tab-${Math.random().toString(36).slice(2)}-${Date.now()}`;
|
|
2030
2102
|
}
|
|
2031
|
-
function
|
|
2103
|
+
function Wn(e) {
|
|
2032
2104
|
return e ? {
|
|
2033
2105
|
now: () => e.now(),
|
|
2034
2106
|
setTimeout: (t, n) => e.setTimeout(t, n),
|
|
2035
|
-
random: e.random ? () => e.random?.() ?? Math.random() :
|
|
2036
|
-
} :
|
|
2107
|
+
random: e.random ? () => e.random?.() ?? Math.random() : Hn.random
|
|
2108
|
+
} : Hn;
|
|
2037
2109
|
}
|
|
2038
|
-
function
|
|
2110
|
+
function Gn(e) {
|
|
2039
2111
|
return typeof window < "u" && typeof document < "u" && e.getDeviceType() === "web";
|
|
2040
2112
|
}
|
|
2041
|
-
function
|
|
2113
|
+
function Kn(e) {
|
|
2042
2114
|
try {
|
|
2043
2115
|
return e.storageSharedAcrossTabs === !0;
|
|
2044
2116
|
} catch {
|
|
2045
2117
|
return !1;
|
|
2046
2118
|
}
|
|
2047
2119
|
}
|
|
2048
|
-
function
|
|
2120
|
+
function qn() {
|
|
2049
2121
|
try {
|
|
2050
2122
|
let e = globalThis.navigator?.locks;
|
|
2051
2123
|
return e && typeof e.request == "function" ? e : void 0;
|
|
@@ -2053,7 +2125,7 @@ function Gn() {
|
|
|
2053
2125
|
return;
|
|
2054
2126
|
}
|
|
2055
2127
|
}
|
|
2056
|
-
function
|
|
2128
|
+
function Jn(e) {
|
|
2057
2129
|
return (t) => {
|
|
2058
2130
|
let n = (n) => {
|
|
2059
2131
|
let r = n.key;
|
|
@@ -2062,20 +2134,20 @@ function Kn(e) {
|
|
|
2062
2134
|
return window.addEventListener("storage", n), () => window.removeEventListener("storage", n);
|
|
2063
2135
|
};
|
|
2064
2136
|
}
|
|
2065
|
-
function
|
|
2137
|
+
function Yn(e) {
|
|
2066
2138
|
return {
|
|
2067
2139
|
transports: null,
|
|
2068
|
-
names:
|
|
2069
|
-
clock:
|
|
2140
|
+
names: Mn(e),
|
|
2141
|
+
clock: Hn,
|
|
2070
2142
|
warnOnFirstCycle: !1
|
|
2071
2143
|
};
|
|
2072
2144
|
}
|
|
2073
|
-
function
|
|
2074
|
-
let i =
|
|
2145
|
+
function Xn(e, t, n, r) {
|
|
2146
|
+
let i = Mn(n), a = Gn(t), o = a ? Jn(r.tokenKeys) : void 0, s = (e) => {
|
|
2075
2147
|
let t = {
|
|
2076
2148
|
transports: null,
|
|
2077
2149
|
names: i,
|
|
2078
|
-
clock:
|
|
2150
|
+
clock: Hn,
|
|
2079
2151
|
warnOnFirstCycle: e
|
|
2080
2152
|
};
|
|
2081
2153
|
return o && (t.onStorageChange = o), t;
|
|
@@ -2085,16 +2157,16 @@ function Jn(e, t, n, r) {
|
|
|
2085
2157
|
transports: {
|
|
2086
2158
|
locks: e.locks,
|
|
2087
2159
|
channel: e.channel,
|
|
2088
|
-
tabId: e.tabId ??
|
|
2160
|
+
tabId: e.tabId ?? Un()
|
|
2089
2161
|
},
|
|
2090
2162
|
names: i,
|
|
2091
|
-
clock:
|
|
2163
|
+
clock: Wn(e.clock),
|
|
2092
2164
|
warnOnFirstCycle: !1
|
|
2093
2165
|
};
|
|
2094
2166
|
return e.onStorageChange && (t.onStorageChange = e.onStorageChange), t;
|
|
2095
2167
|
}
|
|
2096
|
-
if (e === "none" || !a || !
|
|
2097
|
-
let c =
|
|
2168
|
+
if (e === "none" || !a || !Kn(t)) return s(!1);
|
|
2169
|
+
let c = qn();
|
|
2098
2170
|
if (!c || typeof BroadcastChannel != "function") return s(!0);
|
|
2099
2171
|
let l;
|
|
2100
2172
|
try {
|
|
@@ -2106,16 +2178,16 @@ function Jn(e, t, n, r) {
|
|
|
2106
2178
|
transports: {
|
|
2107
2179
|
locks: c,
|
|
2108
2180
|
channel: l,
|
|
2109
|
-
tabId:
|
|
2181
|
+
tabId: Un()
|
|
2110
2182
|
},
|
|
2111
2183
|
names: i,
|
|
2112
|
-
clock:
|
|
2184
|
+
clock: Hn,
|
|
2113
2185
|
warnOnFirstCycle: !1
|
|
2114
2186
|
};
|
|
2115
2187
|
return o && (u.onStorageChange = o), u;
|
|
2116
2188
|
}
|
|
2117
2189
|
// lib/services/logger.ts
|
|
2118
|
-
var
|
|
2190
|
+
var Zn = class {
|
|
2119
2191
|
error(e, ...t) {
|
|
2120
2192
|
console.error(e, ...t);
|
|
2121
2193
|
}
|
|
@@ -2129,10 +2201,10 @@ var Yn = class {
|
|
|
2129
2201
|
console.debug(e, ...t);
|
|
2130
2202
|
}
|
|
2131
2203
|
};
|
|
2132
|
-
function
|
|
2133
|
-
return new
|
|
2204
|
+
function Qn() {
|
|
2205
|
+
return new Zn();
|
|
2134
2206
|
}
|
|
2135
|
-
var
|
|
2207
|
+
var $n = Object.freeze([
|
|
2136
2208
|
"error.token.invalid.error",
|
|
2137
2209
|
"error.api.token.parse.error",
|
|
2138
2210
|
"error.api.user.blocked",
|
|
@@ -2140,25 +2212,25 @@ var Zn = Object.freeze([
|
|
|
2140
2212
|
"error.validation.token.invalid.subject",
|
|
2141
2213
|
"error.not.found"
|
|
2142
2214
|
]);
|
|
2143
|
-
function
|
|
2215
|
+
function er(e) {
|
|
2144
2216
|
if (typeof e != "object" || !e) return;
|
|
2145
2217
|
let t = e;
|
|
2146
2218
|
return typeof t.get == "function" ? t.get("retry-after") : t["retry-after"] ?? t["Retry-After"];
|
|
2147
2219
|
}
|
|
2148
|
-
function
|
|
2149
|
-
if (typeof e == "number") return !Number.isFinite(e) || e < 0 ? void 0 : Math.min(
|
|
2220
|
+
function tr(e, t) {
|
|
2221
|
+
if (typeof e == "number") return !Number.isFinite(e) || e < 0 ? void 0 : Math.min(wn, Math.floor(e) * 1e3);
|
|
2150
2222
|
if (typeof e != "string") return;
|
|
2151
2223
|
let n = e.trim();
|
|
2152
2224
|
if (n === "") return;
|
|
2153
|
-
if (/^\d+$/.test(n)) return Math.min(
|
|
2225
|
+
if (/^\d+$/.test(n)) return Math.min(wn, Number.parseInt(n, 10) * 1e3);
|
|
2154
2226
|
if (!/[a-z]/i.test(n)) return;
|
|
2155
2227
|
let r = Date.parse(n);
|
|
2156
|
-
if (!Number.isNaN(r)) return Math.min(
|
|
2228
|
+
if (!Number.isNaN(r)) return Math.min(wn, Math.max(0, r - t));
|
|
2157
2229
|
}
|
|
2158
|
-
function
|
|
2230
|
+
function nr(e) {
|
|
2159
2231
|
return typeof e == "number" && Number.isInteger(e) && e >= 100 && e <= 599 ? e : void 0;
|
|
2160
2232
|
}
|
|
2161
|
-
function
|
|
2233
|
+
function rr(e) {
|
|
2162
2234
|
if (typeof e.id == "string" && e.id !== "") return e.id;
|
|
2163
2235
|
let t = e.response?.data;
|
|
2164
2236
|
if (typeof t != "object" || !t) return;
|
|
@@ -2167,14 +2239,14 @@ function tr(e) {
|
|
|
2167
2239
|
let r = n.id;
|
|
2168
2240
|
return typeof r == "string" && r !== "" ? r : void 0;
|
|
2169
2241
|
}
|
|
2170
|
-
function
|
|
2242
|
+
function ir(e, t = Date.now()) {
|
|
2171
2243
|
if (typeof e != "object" || !e) return { kind: "transient" };
|
|
2172
|
-
let n = e, r =
|
|
2244
|
+
let n = e, r = rr(n), i = nr(n.response?.status) ?? nr(n.status), a = {};
|
|
2173
2245
|
if (i !== void 0 && (a.status = i), r !== void 0 && (a.id = r), r === "error.token.blocked") return {
|
|
2174
2246
|
kind: "blocked",
|
|
2175
2247
|
...a
|
|
2176
2248
|
};
|
|
2177
|
-
if (r !== void 0 &&
|
|
2249
|
+
if (r !== void 0 && $n.includes(r) || i !== void 0 && i >= 400 && i <= 499 && i !== 429) return {
|
|
2178
2250
|
kind: "auth",
|
|
2179
2251
|
...a
|
|
2180
2252
|
};
|
|
@@ -2182,7 +2254,7 @@ function nr(e, t = Date.now()) {
|
|
|
2182
2254
|
kind: "transient",
|
|
2183
2255
|
...a
|
|
2184
2256
|
};
|
|
2185
|
-
let o =
|
|
2257
|
+
let o = tr(n.retryAfter ?? er(n.response?.headers), t);
|
|
2186
2258
|
return o === void 0 ? {
|
|
2187
2259
|
kind: "transient",
|
|
2188
2260
|
...a
|
|
@@ -2192,19 +2264,19 @@ function nr(e, t = Date.now()) {
|
|
|
2192
2264
|
retryAfterMs: o
|
|
2193
2265
|
};
|
|
2194
2266
|
}
|
|
2195
|
-
function
|
|
2196
|
-
let r =
|
|
2197
|
-
return Math.max(o, n !== void 0 && Number.isFinite(n) ? Math.min(Math.max(n, 0),
|
|
2267
|
+
function ar(e, t, n) {
|
|
2268
|
+
let r = Sn.length, i = Sn[(Number.isFinite(e) ? Math.min(Math.max(Math.floor(e), 1), r) : 1) - 1] ?? Sn[r - 1] ?? 6e4, a = Number.isFinite(t) ? Math.min(Math.max(t, 0), .999) : 0, o = i + Math.floor(i * Cn * a);
|
|
2269
|
+
return Math.max(o, n !== void 0 && Number.isFinite(n) ? Math.min(Math.max(n, 0), wn) : 0);
|
|
2198
2270
|
}
|
|
2199
2271
|
// lib/refresh/coordinator.ts
|
|
2200
|
-
var
|
|
2272
|
+
var or = {
|
|
2201
2273
|
onGranted: () => !1,
|
|
2202
2274
|
onLockLost: () => void 0,
|
|
2203
2275
|
onMessage: () => void 0
|
|
2204
2276
|
};
|
|
2205
|
-
function
|
|
2206
|
-
let { locks: t, channel: n, tabId: r, names: i, clock: a } = e, o =
|
|
2207
|
-
g || n.postMessage(
|
|
2277
|
+
function sr(e) {
|
|
2278
|
+
let { locks: t, channel: n, tabId: r, names: i, clock: a } = e, o = or, s = null, c = null, l = null, u = null, d = null, f = null, p = 0, m, h = !1, g = !1, _ = (e) => {
|
|
2279
|
+
g || n.postMessage(Bn(r, e));
|
|
2208
2280
|
}, v = () => s !== null && c === null, y = () => {
|
|
2209
2281
|
f?.(), f = null;
|
|
2210
2282
|
}, b = (e) => {
|
|
@@ -2219,7 +2291,7 @@ function ar(e) {
|
|
|
2219
2291
|
type: "still-refreshing",
|
|
2220
2292
|
retry: m
|
|
2221
2293
|
} : { type: "still-refreshing" }), S());
|
|
2222
|
-
},
|
|
2294
|
+
}, Tn);
|
|
2223
2295
|
}, C = () => {
|
|
2224
2296
|
y(), x(), u?.(), u = null;
|
|
2225
2297
|
let e = s;
|
|
@@ -2270,7 +2342,7 @@ function ar(e) {
|
|
|
2270
2342
|
});
|
|
2271
2343
|
}, ee = (e) => {
|
|
2272
2344
|
if (g) return;
|
|
2273
|
-
let t =
|
|
2345
|
+
let t = zn(e.data);
|
|
2274
2346
|
if (t && t.tabId !== r) {
|
|
2275
2347
|
switch (t.type) {
|
|
2276
2348
|
case "still-refreshing":
|
|
@@ -2313,8 +2385,8 @@ function ar(e) {
|
|
|
2313
2385
|
}
|
|
2314
2386
|
};
|
|
2315
2387
|
}
|
|
2316
|
-
function
|
|
2317
|
-
let t =
|
|
2388
|
+
function cr(e = "local") {
|
|
2389
|
+
let t = or, n = !1, r = !1, i = 0, a = !1, o = () => {
|
|
2318
2390
|
n = !1, r = !1, i += 1;
|
|
2319
2391
|
};
|
|
2320
2392
|
return {
|
|
@@ -2362,7 +2434,7 @@ var q = {
|
|
|
2362
2434
|
successorTimeout: "error.refresh.successor_timeout",
|
|
2363
2435
|
identityChanged: "error.refresh.identity_changed",
|
|
2364
2436
|
disposed: "error.refresh.disposed"
|
|
2365
|
-
},
|
|
2437
|
+
}, lr = {
|
|
2366
2438
|
"error.refresh.unavailable": 503,
|
|
2367
2439
|
"error.refresh.auth_retry": 401,
|
|
2368
2440
|
"error.refresh.session_ended": 401,
|
|
@@ -2370,7 +2442,7 @@ var q = {
|
|
|
2370
2442
|
"error.refresh.successor_timeout": 401,
|
|
2371
2443
|
"error.refresh.identity_changed": 401,
|
|
2372
2444
|
"error.refresh.disposed": 499
|
|
2373
|
-
},
|
|
2445
|
+
}, ur = {
|
|
2374
2446
|
"error.refresh.unavailable": "Token refresh is unavailable; a retry is scheduled",
|
|
2375
2447
|
"error.refresh.auth_retry": "Token refresh was refused; a retry is scheduled",
|
|
2376
2448
|
"error.refresh.session_ended": "The session has ended",
|
|
@@ -2382,19 +2454,19 @@ var q = {
|
|
|
2382
2454
|
constructor(e, t = {}) {
|
|
2383
2455
|
super({
|
|
2384
2456
|
id: e,
|
|
2385
|
-
message: t.message ??
|
|
2386
|
-
status:
|
|
2457
|
+
message: t.message ?? ur[e],
|
|
2458
|
+
status: lr[e],
|
|
2387
2459
|
location: "/auth/refresh",
|
|
2388
2460
|
time: (/* @__PURE__ */ new Date()).toISOString()
|
|
2389
2461
|
}), this.name = "PassflowRefreshError", t.nextRetryAt !== void 0 && (this.nextRetryAt = t.nextRetryAt), t.cause !== void 0 && (this.cause = t.cause);
|
|
2390
2462
|
}
|
|
2391
|
-
},
|
|
2463
|
+
}, dr = class extends Error {
|
|
2392
2464
|
constructor(e, t) {
|
|
2393
2465
|
super(t ?? (e === "lock-timeout" ? "Step-up commit could not take the refresh lock in time" : "Step-up commit answer arrived after the stored session moved on")), this.name = "UpgradeCommitInterruptedError", this.reason = e;
|
|
2394
2466
|
}
|
|
2395
2467
|
};
|
|
2396
2468
|
// lib/refresh/lineage.ts
|
|
2397
|
-
function
|
|
2469
|
+
function fr(e) {
|
|
2398
2470
|
if (!e) return;
|
|
2399
2471
|
let t = 3735928559, n = 1103547991;
|
|
2400
2472
|
for (let r = 0; r < e.length; r++) {
|
|
@@ -2403,24 +2475,24 @@ function ur(e) {
|
|
|
2403
2475
|
}
|
|
2404
2476
|
return t = Math.imul(t ^ t >>> 16, 2246822507), t ^= Math.imul(n ^ n >>> 13, 3266489909), n = Math.imul(n ^ n >>> 16, 2246822507), n ^= Math.imul(t ^ t >>> 13, 3266489909), (4294967296 * (2097151 & n) + (t >>> 0)).toString(16);
|
|
2405
2477
|
}
|
|
2406
|
-
function
|
|
2478
|
+
function pr(e) {
|
|
2407
2479
|
return typeof e == "string" && e !== "" ? e : void 0;
|
|
2408
2480
|
}
|
|
2409
2481
|
function Y(e) {
|
|
2410
|
-
let t =
|
|
2482
|
+
let t = fr(e);
|
|
2411
2483
|
if (!e || !t) return;
|
|
2412
2484
|
let n = {};
|
|
2413
2485
|
try {
|
|
2414
2486
|
let t = j(e);
|
|
2415
2487
|
typeof t == "object" && t && (n = t);
|
|
2416
2488
|
} catch {}
|
|
2417
|
-
let r = typeof n.iat == "number" && Number.isFinite(n.iat) ? n.iat : void 0, i = { fp: t }, a =
|
|
2489
|
+
let r = typeof n.iat == "number" && Number.isFinite(n.iat) ? n.iat : void 0, i = { fp: t }, a = pr(n.sub), o = pr(n.sid);
|
|
2418
2490
|
return a !== void 0 && (i.sub = a), o !== void 0 && (i.sid = o), r !== void 0 && (i.iat = r), i;
|
|
2419
2491
|
}
|
|
2420
|
-
var
|
|
2421
|
-
function
|
|
2492
|
+
var mr = "[passflow] A refresh token carries no iat claim: it is never taken over an ordered one, and cross-tab adoption falls back to fingerprints";
|
|
2493
|
+
function hr(e = (e) => Qn().warn(e)) {
|
|
2422
2494
|
let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set(), r = !1, i = [], a = !1, o = () => {
|
|
2423
|
-
a || (a = !0, e(
|
|
2495
|
+
a || (a = !0, e(mr));
|
|
2424
2496
|
}, s = (e, t) => e.has(t) ? !0 : e.size >= 32 ? !1 : (e.add(t), !0), c = (e) => {
|
|
2425
2497
|
if (!e) return;
|
|
2426
2498
|
if (e.iat === void 0) {
|
|
@@ -2461,16 +2533,16 @@ function pr(e = (e) => Xn().warn(e)) {
|
|
|
2461
2533
|
};
|
|
2462
2534
|
}
|
|
2463
2535
|
// lib/refresh/fence.ts
|
|
2464
|
-
var
|
|
2536
|
+
var gr = class extends Error {
|
|
2465
2537
|
constructor(e) {
|
|
2466
2538
|
super(e === "emptied" ? "The shared token storage was emptied" : "The stored refresh token belongs to an ended session"), this.name = "SessionEnded", this.cause = e;
|
|
2467
2539
|
}
|
|
2468
|
-
},
|
|
2540
|
+
}, _r = class extends Error {
|
|
2469
2541
|
constructor() {
|
|
2470
2542
|
super("The shared token storage holds another user's tokens"), this.name = "IdentityChanged";
|
|
2471
2543
|
}
|
|
2472
2544
|
};
|
|
2473
|
-
function
|
|
2545
|
+
function vr(e) {
|
|
2474
2546
|
if (e) try {
|
|
2475
2547
|
let t = j(e).sub;
|
|
2476
2548
|
return typeof t == "string" && t !== "" ? t : void 0;
|
|
@@ -2479,20 +2551,20 @@ function gr(e) {
|
|
|
2479
2551
|
}
|
|
2480
2552
|
}
|
|
2481
2553
|
function X(e) {
|
|
2482
|
-
return
|
|
2554
|
+
return vr(e?.access_token) ?? vr(e?.refresh_token) ?? vr(e?.id_token);
|
|
2483
2555
|
}
|
|
2484
|
-
function
|
|
2556
|
+
function yr(e, t) {
|
|
2485
2557
|
return !t || e.iat === void 0 || t.iat === void 0 ? !1 : e.sid === t.sid && e.iat < t.iat;
|
|
2486
2558
|
}
|
|
2487
|
-
function
|
|
2559
|
+
function br(e) {
|
|
2488
2560
|
return typeof e == "object" && !!e;
|
|
2489
2561
|
}
|
|
2490
|
-
function
|
|
2491
|
-
let { storage: t, cache: n, schedule: r } = e, i = e.identity ?? (() => void 0), a = e.warn ?? ((e) =>
|
|
2562
|
+
function xr(e) {
|
|
2563
|
+
let { storage: t, cache: n, schedule: r } = e, i = e.identity ?? (() => void 0), a = e.warn ?? ((e) => Qn().warn(e)), o = e.lineage ?? hr(a), s = e.onSessionLost, c, l = 0, u = [], d = [], f = 0, p, m = 0, h, g, _, v, y = () => {
|
|
2492
2564
|
let e = t.getTokens(), n = e?.refresh_token;
|
|
2493
2565
|
if (!n) return p = l, e;
|
|
2494
2566
|
p !== void 0 && (f = Math.max(f, p, m), p = void 0);
|
|
2495
|
-
let r =
|
|
2567
|
+
let r = fr(n) ?? "";
|
|
2496
2568
|
return r !== c?.fp && (c = {
|
|
2497
2569
|
fp: r,
|
|
2498
2570
|
seq: l
|
|
@@ -2525,7 +2597,7 @@ function yr(e) {
|
|
|
2525
2597
|
let t = E();
|
|
2526
2598
|
t === "wait" && e && (t = "end"), t !== "wait" && D(), t === "wait" && !h && (h = r(() => {
|
|
2527
2599
|
h = void 0, y()?.refresh_token ? P() : O(!0) === "end" && s?.("emptied");
|
|
2528
|
-
},
|
|
2600
|
+
}, On));
|
|
2529
2601
|
let n = t === "keep" ? T() : void 0;
|
|
2530
2602
|
return n && (m = Math.max(m, n.seq)), n && g !== n.fp && (g = n.fp, a(`[passflow] The shared token storage was emptied by the end of the session of ${n.fp}, a refresh token the ${b()?.fp ?? "(none)"} this tab holds is ahead of: keeping it. Nothing is refreshed until the storage holds a token again.`)), t;
|
|
2531
2603
|
}, ee = (e) => e.held !== void 0 && b()?.fp === e.held.cachedFp, k = (e) => {
|
|
@@ -2538,7 +2610,7 @@ function yr(e) {
|
|
|
2538
2610
|
return e.iat !== void 0 && t?.iat !== void 0 && t.sid === e.sid;
|
|
2539
2611
|
}, j = (e, t) => o.isForward(e, t) ? !0 : !!e && !!t && e.iat !== void 0 && e.sid !== t.sid && o.isRetired(t) && !o.isRetired(e) && !o.isEnded(e), M = (e) => {
|
|
2540
2612
|
let t = b();
|
|
2541
|
-
t && t.fp !==
|
|
2613
|
+
t && t.fp !== fr(e.refresh_token) && o.retire(t), n.setTokensCache(e);
|
|
2542
2614
|
}, N = (e) => {
|
|
2543
2615
|
let t = y(), n = t?.refresh_token;
|
|
2544
2616
|
if (n === e.refreshToken) return null;
|
|
@@ -2549,7 +2621,7 @@ function yr(e) {
|
|
|
2549
2621
|
kind: "superseded",
|
|
2550
2622
|
adopted: !1
|
|
2551
2623
|
};
|
|
2552
|
-
let r =
|
|
2624
|
+
let r = vr(t.access_token) ?? vr(n);
|
|
2553
2625
|
if (e.sub && r && e.sub !== r) return {
|
|
2554
2626
|
kind: "identity-changed",
|
|
2555
2627
|
saved: !1
|
|
@@ -2589,22 +2661,22 @@ function yr(e) {
|
|
|
2589
2661
|
}, ne = !!s || !!e.onStoredSessionSeen, re = ne && e.onStorageChange ? e.onStorageChange(P) : void 0, ie = ne && e.onWake ? e.onWake(P) : void 0, F = () => {
|
|
2590
2662
|
let e = y();
|
|
2591
2663
|
if (!e?.refresh_token) {
|
|
2592
|
-
if (O() === "end") throw new
|
|
2664
|
+
if (O() === "end") throw new gr("emptied");
|
|
2593
2665
|
return "held";
|
|
2594
2666
|
}
|
|
2595
2667
|
let t = n.getTokens();
|
|
2596
2668
|
if (e.refresh_token === t?.refresh_token) return "send";
|
|
2597
2669
|
let r = i() ?? X(t), a = X(e);
|
|
2598
|
-
if (r && a && r !== a) throw new
|
|
2670
|
+
if (r && a && r !== a) throw new _r();
|
|
2599
2671
|
let s = Y(e.refresh_token);
|
|
2600
2672
|
if (o.isEnded(s)) {
|
|
2601
2673
|
if (s && C(s)) return "held";
|
|
2602
|
-
throw new
|
|
2674
|
+
throw new gr("ended");
|
|
2603
2675
|
}
|
|
2604
2676
|
let c = Y(t?.refresh_token);
|
|
2605
2677
|
return j(s, c) ? (M(e), "adopted") : s && c && s.sid !== c.sid ? "send" : s && k(s) ? "held" : "send";
|
|
2606
2678
|
}, ae = (e) => {
|
|
2607
|
-
let t = i(), r =
|
|
2679
|
+
let t = i(), r = vr(e);
|
|
2608
2680
|
if (t && r && t !== r) return { kind: "identity-changed" };
|
|
2609
2681
|
let a = Y(e) ?? { fp: e };
|
|
2610
2682
|
if (o.isEnded(a)) return C(a) ? { kind: "superseded" } : { kind: "ended" };
|
|
@@ -2612,7 +2684,7 @@ function yr(e) {
|
|
|
2612
2684
|
let s = {
|
|
2613
2685
|
refreshToken: e,
|
|
2614
2686
|
order: a
|
|
2615
|
-
}, c = t ?? r ??
|
|
2687
|
+
}, c = t ?? r ?? vr(n.getTokens()?.access_token);
|
|
2616
2688
|
return c !== void 0 && (s.sub = c), v && v.fp === a.fp && (s.held = { cachedFp: v.cachedFp }), {
|
|
2617
2689
|
kind: "send",
|
|
2618
2690
|
sent: s
|
|
@@ -2621,7 +2693,7 @@ function yr(e) {
|
|
|
2621
2693
|
if (o.isEnded(e.order)) return te(e.order);
|
|
2622
2694
|
let i = N(e);
|
|
2623
2695
|
if (i) return i;
|
|
2624
|
-
if (!ee(e) && A(e.order)) return o.retire(e.order), a(`[passflow] Refused to save a late refresh result: it rotated ${e.order.fp} into ${
|
|
2696
|
+
if (!ee(e) && A(e.order)) return o.retire(e.order), a(`[passflow] Refused to save a late refresh result: it rotated ${e.order.fp} into ${fr(r.refresh_token) ?? "(no refresh token)"}, but this tab already holds ${b()?.fp ?? "(none)"}, a later successor of ${e.order.fp}. Neither saved nor adopted.`), {
|
|
2625
2697
|
kind: "superseded",
|
|
2626
2698
|
adopted: !1
|
|
2627
2699
|
};
|
|
@@ -2631,7 +2703,7 @@ function yr(e) {
|
|
|
2631
2703
|
saved: !0
|
|
2632
2704
|
};
|
|
2633
2705
|
let c = Y(r.refresh_token);
|
|
2634
|
-
return c && (
|
|
2706
|
+
return c && (yr(c, e.order) || yr(c, b())) ? (a(`[passflow] Refused to save a refresh result older than the token this tab holds: ${e.order.fp} was answered with ${c.fp}. Neither saved nor adopted.`), {
|
|
2635
2707
|
kind: "superseded",
|
|
2636
2708
|
adopted: !1
|
|
2637
2709
|
}) : (o.retire(e.order), t.saveTokens(r), n.setTokensCache(r), { kind: "saved" });
|
|
@@ -2643,7 +2715,7 @@ function yr(e) {
|
|
|
2643
2715
|
kind: "superseded",
|
|
2644
2716
|
adopted: !1
|
|
2645
2717
|
};
|
|
2646
|
-
let r =
|
|
2718
|
+
let r = ir(t), i = r.kind === "blocked" || r.kind === "auth";
|
|
2647
2719
|
return ee(e) && i ? (o.retire(e.order), _ = e.order, {
|
|
2648
2720
|
kind: "own",
|
|
2649
2721
|
failure: r,
|
|
@@ -2654,11 +2726,11 @@ function yr(e) {
|
|
|
2654
2726
|
heldRefused: !1
|
|
2655
2727
|
});
|
|
2656
2728
|
}, se = (e) => {
|
|
2657
|
-
if (!
|
|
2729
|
+
if (!br(e)) return !1;
|
|
2658
2730
|
let { from: t, fromIat: r, fromSid: a, to: c, tokens: l } = e;
|
|
2659
|
-
if (typeof t != "string" || typeof c != "string" || !
|
|
2731
|
+
if (typeof t != "string" || typeof c != "string" || !br(l)) return !1;
|
|
2660
2732
|
let u = l;
|
|
2661
|
-
if (typeof u.access_token != "string" || u.access_token === "" || typeof u.refresh_token != "string" || u.refresh_token === "" ||
|
|
2733
|
+
if (typeof u.access_token != "string" || u.access_token === "" || typeof u.refresh_token != "string" || u.refresh_token === "" || fr(u.refresh_token) !== c) return !1;
|
|
2662
2734
|
let d = y();
|
|
2663
2735
|
if (!d?.refresh_token) return !1;
|
|
2664
2736
|
let f = n.getTokens(), p = i() ?? X(f), m = X(u);
|
|
@@ -2675,7 +2747,7 @@ function yr(e) {
|
|
|
2675
2747
|
}
|
|
2676
2748
|
return !0;
|
|
2677
2749
|
};
|
|
2678
|
-
return g?.fp === c ? _() : !o.isForward(h, g) || g?.fp !== t &&
|
|
2750
|
+
return g?.fp === c ? _() : !o.isForward(h, g) || g?.fp !== t && fr(d.refresh_token) !== c ? !1 : (M({ ...u }), _());
|
|
2679
2751
|
}, L = (e) => {
|
|
2680
2752
|
if (!e || !_) return !1;
|
|
2681
2753
|
let t = _;
|
|
@@ -2741,7 +2813,7 @@ function yr(e) {
|
|
|
2741
2813
|
};
|
|
2742
2814
|
}
|
|
2743
2815
|
// lib/refresh/controller.ts
|
|
2744
|
-
function
|
|
2816
|
+
function Sr() {
|
|
2745
2817
|
let e, t, n = new Promise((n, r) => {
|
|
2746
2818
|
e = n, t = r;
|
|
2747
2819
|
});
|
|
@@ -2751,7 +2823,7 @@ function br() {
|
|
|
2751
2823
|
reject: t
|
|
2752
2824
|
};
|
|
2753
2825
|
}
|
|
2754
|
-
var
|
|
2826
|
+
var Cr = {
|
|
2755
2827
|
strikes: q.sessionEnded,
|
|
2756
2828
|
"session-ended": q.sessionEnded,
|
|
2757
2829
|
"stored-ended": q.sessionEnded,
|
|
@@ -2762,42 +2834,42 @@ var xr = {
|
|
|
2762
2834
|
"identity-changed": q.identityChanged,
|
|
2763
2835
|
disposed: q.disposed
|
|
2764
2836
|
};
|
|
2765
|
-
function
|
|
2837
|
+
function wr(e) {
|
|
2766
2838
|
throw Error(`Unexpected refresh state: ${JSON.stringify(e)}`);
|
|
2767
2839
|
}
|
|
2768
|
-
function
|
|
2840
|
+
function Tr(e) {
|
|
2769
2841
|
if (e === void 0 || !Number.isFinite(e)) return 3;
|
|
2770
2842
|
let t = Math.floor(e);
|
|
2771
2843
|
return t >= 1 ? t : 3;
|
|
2772
2844
|
}
|
|
2773
|
-
function
|
|
2845
|
+
function Er(e, t) {
|
|
2774
2846
|
return e instanceof Error && e.message ? e.message : t;
|
|
2775
2847
|
}
|
|
2776
|
-
function
|
|
2848
|
+
function Dr(e) {
|
|
2777
2849
|
if (typeof e != "object" || !e) return;
|
|
2778
2850
|
let t = e.id;
|
|
2779
2851
|
return typeof t == "string" || typeof t == "number" ? t : void 0;
|
|
2780
2852
|
}
|
|
2781
|
-
function
|
|
2853
|
+
function Or(e) {
|
|
2782
2854
|
let t = {};
|
|
2783
2855
|
return e?.access_token && (t.access_token = e.access_token), e?.refresh_token && (t.refresh_token = e.refresh_token), e?.id_token && (t.id_token = e.id_token), e?.scopes && (t.scopes = [...e.scopes]), t;
|
|
2784
2856
|
}
|
|
2785
|
-
function
|
|
2857
|
+
function kr(e, t) {
|
|
2786
2858
|
let n = {};
|
|
2787
2859
|
e.access_token && (n.access_token = e.access_token), e.refresh_token && (n.refresh_token = e.refresh_token), e.id_token && (n.id_token = e.id_token);
|
|
2788
2860
|
let r = t?.scopes ?? e.scopes;
|
|
2789
2861
|
return r && (n.scopes = r), n;
|
|
2790
2862
|
}
|
|
2791
|
-
function
|
|
2792
|
-
let { emit: t, storage: n, cache: r, transport: i, coordination: a } = e, o = a.clock, s = e.logger ??
|
|
2863
|
+
function Ar(e) {
|
|
2864
|
+
let { emit: t, storage: n, cache: r, transport: i, coordination: a } = e, o = a.clock, s = e.logger ?? Qn(), c = Tr(e.strikes), l = a.transports ? sr({
|
|
2793
2865
|
locks: a.transports.locks,
|
|
2794
2866
|
channel: a.transports.channel,
|
|
2795
2867
|
tabId: a.transports.tabId,
|
|
2796
2868
|
names: a.names,
|
|
2797
2869
|
clock: o
|
|
2798
|
-
}) :
|
|
2870
|
+
}) : cr(), u = { kind: "idle" }, d = 0, f = !1, p = !a.warnOnFirstCycle, m = 0, h = 0, g, _, v, y, b, x, S, C, w = !1, T = () => o.now(), E = () => i.mode(), D = () => fr(r.getTokens()?.refresh_token), O = () => ({ ...r.getTokens() ?? {} }), ee = () => i.opaqueMarker ? i.opaqueMarker() : n.getTokens()?.id_token, k = () => (S === void 0 && (S = X(r.getTokens() ?? n.getTokens())), S), A = /* @__PURE__ */ new Set(), j = /* @__PURE__ */ new Set(), M = (e) => () => {
|
|
2799
2871
|
for (let t of Array.from(e)) t();
|
|
2800
|
-
}, N = a.onStorageChange?.(M(A)), te = e.platform?.onForeground(M(j)), P =
|
|
2872
|
+
}, N = a.onStorageChange?.(M(A)), te = e.platform?.onForeground(M(j)), P = xr({
|
|
2801
2873
|
storage: n,
|
|
2802
2874
|
cache: r,
|
|
2803
2875
|
identity: k,
|
|
@@ -2812,13 +2884,13 @@ function Or(e) {
|
|
|
2812
2884
|
}), ne = (e) => ({
|
|
2813
2885
|
trigger: e,
|
|
2814
2886
|
startedAt: T(),
|
|
2815
|
-
plain:
|
|
2887
|
+
plain: Sr(),
|
|
2816
2888
|
fresh: []
|
|
2817
2889
|
}), re = (e) => e.kind === "idle" || e.kind === "ended" ? void 0 : e.pending, ie = (e, t) => {
|
|
2818
2890
|
if (t === void 0) return e.plain.promise;
|
|
2819
2891
|
let n = {
|
|
2820
2892
|
callTime: t,
|
|
2821
|
-
deferred:
|
|
2893
|
+
deferred: Sr()
|
|
2822
2894
|
};
|
|
2823
2895
|
return e.fresh.push(n), n.deferred.promise;
|
|
2824
2896
|
}, F = (e, t, n = !1) => {
|
|
@@ -2837,11 +2909,11 @@ function Or(e) {
|
|
|
2837
2909
|
}
|
|
2838
2910
|
}, I = (e, n, r, i) => {
|
|
2839
2911
|
let a = {
|
|
2840
|
-
message:
|
|
2912
|
+
message: Er(r, "Token refresh failed"),
|
|
2841
2913
|
originalError: r,
|
|
2842
2914
|
operation: e,
|
|
2843
2915
|
source: n
|
|
2844
|
-
}, o =
|
|
2916
|
+
}, o = Dr(r);
|
|
2845
2917
|
o !== void 0 && (a.code = o), i && (a.refresh = i), t("error", a);
|
|
2846
2918
|
}, se = (e, t) => {
|
|
2847
2919
|
let n = {
|
|
@@ -2871,10 +2943,10 @@ function Or(e) {
|
|
|
2871
2943
|
};
|
|
2872
2944
|
n !== void 0 && (i.nextRetryAt = n), t("refresh:failing", i);
|
|
2873
2945
|
}, le = (e, t) => {
|
|
2874
|
-
let n = r.getTokens(), i =
|
|
2946
|
+
let n = r.getTokens(), i = fr(n?.refresh_token);
|
|
2875
2947
|
e.fp && i && l.post({
|
|
2876
2948
|
type: "tokens-refreshed",
|
|
2877
|
-
tokens:
|
|
2949
|
+
tokens: Or(n),
|
|
2878
2950
|
from: e.fp,
|
|
2879
2951
|
...e.iat === void 0 ? {} : { fromIat: e.iat },
|
|
2880
2952
|
fromSid: e.sid ?? "",
|
|
@@ -2882,7 +2954,7 @@ function Or(e) {
|
|
|
2882
2954
|
...t === void 0 ? {} : { sentAt: t }
|
|
2883
2955
|
});
|
|
2884
2956
|
}, ue = () => {
|
|
2885
|
-
p || (p = !0, s.warn(
|
|
2957
|
+
p || (p = !0, s.warn(Vn));
|
|
2886
2958
|
}, de = (e) => {
|
|
2887
2959
|
(e.kind === "backoff" || e.kind === "blocked-wait") && e.cancel();
|
|
2888
2960
|
}, R = (e, n) => {
|
|
@@ -2896,7 +2968,7 @@ function Or(e) {
|
|
|
2896
2968
|
}, e !== "disposed" && P.dropSession(), (e === "strikes" || e === "successor-timeout") && E() !== "json" && i.invalidate(), u = {
|
|
2897
2969
|
kind: "ended",
|
|
2898
2970
|
cause: e
|
|
2899
|
-
}, oe(r, n ?? new J(
|
|
2971
|
+
}, oe(r, n ?? new J(Cr[e])), e) {
|
|
2900
2972
|
case "strikes":
|
|
2901
2973
|
t("session:expired", {
|
|
2902
2974
|
reason: "refresh_failed",
|
|
@@ -2931,7 +3003,7 @@ function Or(e) {
|
|
|
2931
3003
|
break;
|
|
2932
3004
|
case "signed-out-here":
|
|
2933
3005
|
case "disposed": break;
|
|
2934
|
-
default:
|
|
3006
|
+
default: wr(e);
|
|
2935
3007
|
}
|
|
2936
3008
|
}, fe = () => {
|
|
2937
3009
|
if (u.kind !== "ended" || u.cause === "disposed" || f || E() !== "json") return;
|
|
@@ -2948,10 +3020,10 @@ function Or(e) {
|
|
|
2948
3020
|
}, pe = (e) => {
|
|
2949
3021
|
u.kind === "ended" || f || E() === "json" && (R(e === "emptied" ? "emptied" : "identity-changed"), e === "identity-changed" && fe());
|
|
2950
3022
|
}, me = (e) => {
|
|
2951
|
-
e instanceof
|
|
3023
|
+
e instanceof _r ? (R("identity-changed"), fe()) : e instanceof gr ? R(e.cause === "emptied" ? "emptied" : "stored-ended") : R("stored-ended", e);
|
|
2952
3024
|
}, he = () => {
|
|
2953
3025
|
u = { kind: "idle" }, w || l.release();
|
|
2954
|
-
}, ge = (e) => !e.from || E() !== "json" || e.from === D() || e.from ===
|
|
3026
|
+
}, ge = (e) => !e.from || E() !== "json" || e.from === D() || e.from === fr(n.getTokens()?.refresh_token), _e = (e) => {
|
|
2955
3027
|
let t = g;
|
|
2956
3028
|
if (!t) return;
|
|
2957
3029
|
if (!l.holding) {
|
|
@@ -3017,14 +3089,14 @@ function Or(e) {
|
|
|
3017
3089
|
case "ended": return P.endHeldSend(), R("stored-ended"), !1;
|
|
3018
3090
|
case "identity-changed": return P.endHeldSend(), R("identity-changed"), fe(), !1;
|
|
3019
3091
|
case "send": return Ce(e, t, a.sent, r);
|
|
3020
|
-
default: return
|
|
3092
|
+
default: return wr(a);
|
|
3021
3093
|
}
|
|
3022
3094
|
}, Ce = (e, n, r, a) => {
|
|
3023
3095
|
let o = {
|
|
3024
3096
|
generation: d,
|
|
3025
3097
|
sentAt: T(),
|
|
3026
3098
|
trigger: n,
|
|
3027
|
-
settled:
|
|
3099
|
+
settled: Sr()
|
|
3028
3100
|
};
|
|
3029
3101
|
r ? o.sent = r : o.marker = ee(), a && (o.stored = a), u = {
|
|
3030
3102
|
kind: "refreshing",
|
|
@@ -3061,7 +3133,7 @@ function Or(e) {
|
|
|
3061
3133
|
if (!we(e)) return;
|
|
3062
3134
|
r.setTokensCache({
|
|
3063
3135
|
...n.getTokens() ?? {},
|
|
3064
|
-
...
|
|
3136
|
+
...kr(t, void 0)
|
|
3065
3137
|
}), L("refresh", "this-tab");
|
|
3066
3138
|
let c = k();
|
|
3067
3139
|
l.post(c === void 0 ? {
|
|
@@ -3074,7 +3146,7 @@ function Or(e) {
|
|
|
3074
3146
|
}), he(), F(a, e.sentAt);
|
|
3075
3147
|
return;
|
|
3076
3148
|
}
|
|
3077
|
-
let o = D(), s = P.commitSave(e.sent,
|
|
3149
|
+
let o = D(), s = P.commitSave(e.sent, kr(t, e.stored));
|
|
3078
3150
|
switch (s.kind) {
|
|
3079
3151
|
case "saved":
|
|
3080
3152
|
L("refresh", "this-tab"), le(e.sent.order, e.sentAt), he(), F(a, e.sentAt);
|
|
@@ -3092,7 +3164,7 @@ function Or(e) {
|
|
|
3092
3164
|
I("refresh", e.trigger, t, se("auth")), R("identity-changed", t), fe();
|
|
3093
3165
|
return;
|
|
3094
3166
|
}
|
|
3095
|
-
default:
|
|
3167
|
+
default: wr(s);
|
|
3096
3168
|
}
|
|
3097
3169
|
}, Ee = (e, t) => {
|
|
3098
3170
|
if (e.sent?.held && P.endHeldSend(), !we(e) || u.kind !== "refreshing") return;
|
|
@@ -3112,9 +3184,9 @@ function Or(e) {
|
|
|
3112
3184
|
case "own":
|
|
3113
3185
|
r = o.failure, i = o.heldRefused;
|
|
3114
3186
|
break;
|
|
3115
|
-
default:
|
|
3187
|
+
default: wr(o);
|
|
3116
3188
|
}
|
|
3117
|
-
} else r =
|
|
3189
|
+
} else r = ir(t, T());
|
|
3118
3190
|
if (i) I("refresh", e.trigger, t, se(r.kind)), L("adopted", "other-tab"), he(), F(n, void 0, !0);
|
|
3119
3191
|
else switch (r.kind) {
|
|
3120
3192
|
case "blocked":
|
|
@@ -3130,10 +3202,10 @@ function Or(e) {
|
|
|
3130
3202
|
case "transient":
|
|
3131
3203
|
m += 1, De(e, n, t, r);
|
|
3132
3204
|
return;
|
|
3133
|
-
default:
|
|
3205
|
+
default: wr(r.kind);
|
|
3134
3206
|
}
|
|
3135
3207
|
}, De = (e, t, n, r) => {
|
|
3136
|
-
let i = T() +
|
|
3208
|
+
let i = T() + ar(m, o.random(), r.retryAfterMs), a = r.kind === "auth" ? "auth" : "transient";
|
|
3137
3209
|
I("refresh", e.trigger, n, se(a, i)), a === "transient" && ce(T(), i, "this-tab");
|
|
3138
3210
|
let s = {
|
|
3139
3211
|
kind: a,
|
|
@@ -3143,7 +3215,7 @@ function Or(e) {
|
|
|
3143
3215
|
}, c = e.sent?.order.fp;
|
|
3144
3216
|
c && (s.from = c), _ && (s.failingSince = _.since), g = s, l.holding && l.post({
|
|
3145
3217
|
type: "retry-scheduled",
|
|
3146
|
-
message:
|
|
3218
|
+
message: Er(n, "Token refresh failed"),
|
|
3147
3219
|
retry: s
|
|
3148
3220
|
}), _e(ne("retry")), ae(t, n, e.sentAt);
|
|
3149
3221
|
}, Oe = (e, t) => {
|
|
@@ -3156,8 +3228,8 @@ function Or(e) {
|
|
|
3156
3228
|
fp: i.fp
|
|
3157
3229
|
})), r && P.deleteIfStillDead(r), R("strikes", t);
|
|
3158
3230
|
}, z = (e, t, n, r) => {
|
|
3159
|
-
l.release(), s.warn(`[passflow] The refresh token was already used, most likely by another tab; waiting for its successor: ${
|
|
3160
|
-
let i = d, a = T() +
|
|
3231
|
+
l.release(), s.warn(`[passflow] The refresh token was already used, most likely by another tab; waiting for its successor: ${Er(n, "blocked")}`);
|
|
3232
|
+
let i = d, a = T() + En, c = {
|
|
3161
3233
|
kind: "blocked-wait",
|
|
3162
3234
|
pending: e,
|
|
3163
3235
|
deadline: a,
|
|
@@ -3170,9 +3242,9 @@ function Or(e) {
|
|
|
3170
3242
|
i === d && u === c && (B() || (f ? (e.cookieRetried = !0, u = {
|
|
3171
3243
|
kind: "waiting",
|
|
3172
3244
|
pending: e
|
|
3173
|
-
}, l.request()) : T() >= a ? (s.warn("[passflow] No successor of the used refresh token appeared; ending the session in this tab only."), R("successor-timeout")) : c.cancel = o.setTimeout(p,
|
|
3245
|
+
}, l.request()) : T() >= a ? (s.warn("[passflow] No successor of the used refresh token appeared; ending the session in this tab only."), R("successor-timeout")) : c.cancel = o.setTimeout(p, Dn)));
|
|
3174
3246
|
};
|
|
3175
|
-
c.cancel = o.setTimeout(p, f ?
|
|
3247
|
+
c.cancel = o.setTimeout(p, f ? kn : Dn);
|
|
3176
3248
|
}, B = () => {
|
|
3177
3249
|
if (u.kind !== "blocked-wait") return !1;
|
|
3178
3250
|
let e = u;
|
|
@@ -3216,7 +3288,7 @@ function Or(e) {
|
|
|
3216
3288
|
case "idle":
|
|
3217
3289
|
case "refreshing":
|
|
3218
3290
|
case "ended": return;
|
|
3219
|
-
default:
|
|
3291
|
+
default: wr(u);
|
|
3220
3292
|
}
|
|
3221
3293
|
}, V = (e) => {
|
|
3222
3294
|
let t = {};
|
|
@@ -3259,7 +3331,7 @@ function Or(e) {
|
|
|
3259
3331
|
je(e.retry, !0, e.message), Pe();
|
|
3260
3332
|
return;
|
|
3261
3333
|
case "refresh-failed":
|
|
3262
|
-
if (u.kind === "ended" || E() !== "json" || e.from !== D() && e.from !==
|
|
3334
|
+
if (u.kind === "ended" || E() !== "json" || e.from !== D() && e.from !== fr(n.getTokens()?.refresh_token)) return;
|
|
3263
3335
|
if (ce(T(), void 0, "other-tab"), u.kind === "waiting") {
|
|
3264
3336
|
let t = u.pending;
|
|
3265
3337
|
u.pending = ne(t.trigger), ae(t, new J(q.unavailable, { cause: e.message }), void 0);
|
|
@@ -3280,7 +3352,7 @@ function Or(e) {
|
|
|
3280
3352
|
return;
|
|
3281
3353
|
case "takeover":
|
|
3282
3354
|
case "rate-limited": return;
|
|
3283
|
-
default:
|
|
3355
|
+
default: wr(e);
|
|
3284
3356
|
}
|
|
3285
3357
|
}, Pe = () => {
|
|
3286
3358
|
C && !l.holding && l.post({
|
|
@@ -3345,7 +3417,7 @@ function Or(e) {
|
|
|
3345
3417
|
case "refreshing":
|
|
3346
3418
|
case "backoff":
|
|
3347
3419
|
case "blocked-wait": return ie(u.pending, t);
|
|
3348
|
-
default: return
|
|
3420
|
+
default: return wr(u);
|
|
3349
3421
|
}
|
|
3350
3422
|
}, Le = (e) => {
|
|
3351
3423
|
if (f) return Promise.reject(new J(q.disposed));
|
|
@@ -3396,9 +3468,9 @@ function Or(e) {
|
|
|
3396
3468
|
}, He = async (e, t) => {
|
|
3397
3469
|
if (f) throw new J(q.disposed);
|
|
3398
3470
|
ue();
|
|
3399
|
-
let n = T() +
|
|
3471
|
+
let n = T() + An;
|
|
3400
3472
|
if (await Be(n - T()), (!l.holding || u.kind === "refreshing") && (u.kind === "refreshing" ? "timeout" : await ze("commit", n - T())) === "timeout") {
|
|
3401
|
-
let e = new
|
|
3473
|
+
let e = new dr("lock-timeout");
|
|
3402
3474
|
throw I("upgrade.commit", "upgrade", e), e;
|
|
3403
3475
|
}
|
|
3404
3476
|
w = !0;
|
|
@@ -3445,7 +3517,7 @@ function Or(e) {
|
|
|
3445
3517
|
if (!o) {
|
|
3446
3518
|
await i.applyOpaque(u), r.setTokensCache({
|
|
3447
3519
|
...n.getTokens() ?? {},
|
|
3448
|
-
...
|
|
3520
|
+
...kr(u, void 0)
|
|
3449
3521
|
}), We(c);
|
|
3450
3522
|
let e = k();
|
|
3451
3523
|
return l.post(e === void 0 ? {
|
|
@@ -3457,9 +3529,9 @@ function Or(e) {
|
|
|
3457
3529
|
sub: e
|
|
3458
3530
|
}), O();
|
|
3459
3531
|
}
|
|
3460
|
-
let d = P.commitSave(o,
|
|
3532
|
+
let d = P.commitSave(o, kr(u, s));
|
|
3461
3533
|
if (d.kind === "saved") return We(c), le(o.order, c), O();
|
|
3462
|
-
let f = new
|
|
3534
|
+
let f = new dr("superseded");
|
|
3463
3535
|
throw I("upgrade.commit", "upgrade", f), d.kind === "superseded" && d.adopted && L("adopted", "other-tab"), f;
|
|
3464
3536
|
}, We = (e) => {
|
|
3465
3537
|
if (L("upgrade", "this-tab"), u.kind === "waiting" || u.kind === "backoff" || u.kind === "blocked-wait") {
|
|
@@ -3485,7 +3557,7 @@ function Or(e) {
|
|
|
3485
3557
|
commitUpgrade: He,
|
|
3486
3558
|
signOut: async (e) => {
|
|
3487
3559
|
if (f) return e(n.getTokens()?.refresh_token);
|
|
3488
|
-
let t = T() +
|
|
3560
|
+
let t = T() + jn;
|
|
3489
3561
|
Ke(), await Be(t - T()), Ke(), l.coordinated && !l.holding && await ze("logout", t - T());
|
|
3490
3562
|
try {
|
|
3491
3563
|
Ge(), await e(n.getTokens()?.refresh_token);
|
|
@@ -3530,7 +3602,7 @@ function Or(e) {
|
|
|
3530
3602
|
// lib/store.ts
|
|
3531
3603
|
var Z = /* @__PURE__ */ function(e) {
|
|
3532
3604
|
return e.SignIn = "signin", e.SignInStart = "signin:start", e.Register = "register", e.RegisterStart = "register:start", e.EmailVerificationRequired = "email-verification:required", e.SignOut = "signout", e.SessionRestored = "session:restored", e.SessionExpired = "session:expired", e.Error = "error", e.Refresh = "refresh", e.RefreshStart = "refresh:start", e.TokenCacheExpired = "token-cache-expired", e.TwoFactorRequired = "2fa:required", e.TwoFactorSetupStarted = "2fa:setup_started", e.TwoFactorEnabled = "2fa:enabled", e.TwoFactorDisabled = "2fa:disabled", e.TwoFactorVerified = "2fa:verified", e.TwoFactorRecoveryUsed = "2fa:recovery_used", e.TwoFactorRecoveryCodesLow = "2fa:recovery_low", e.TwoFactorRecoveryCodesExhausted = "2fa:recovery_exhausted", e.TwoFactorSetupMagicLinkValidated = "2fa:magic_link_validated", e.TwoFactorSetupMagicLinkFailed = "2fa:magic_link_failed", e.TwoFactorChallengeReceived = "two_factor_challenge_received", e.TwoFactorMethodSwitched = "two_factor_method_switched", e.TwoFactorDeviceTrusted = "two_factor_device_trusted", e.RefreshFailing = "refresh:failing", e.RefreshRecovered = "refresh:recovered", e;
|
|
3533
|
-
}({}),
|
|
3605
|
+
}({}), jr = class {
|
|
3534
3606
|
constructor() {
|
|
3535
3607
|
this.subscribers = /* @__PURE__ */ new Map();
|
|
3536
3608
|
}
|
|
@@ -3549,14 +3621,14 @@ var Z = /* @__PURE__ */ function(e) {
|
|
|
3549
3621
|
n && (t.forEach((e) => n.delete(e)), n.size === 0 && this.subscribers.delete(e));
|
|
3550
3622
|
}
|
|
3551
3623
|
notify(e, t) {
|
|
3552
|
-
e === "error" &&
|
|
3624
|
+
e === "error" && vn(this, t?.originalError), this.subscribers.forEach((n, r) => {
|
|
3553
3625
|
(!n || n.has(e)) && r.onAuthChange?.(e, t);
|
|
3554
3626
|
});
|
|
3555
3627
|
}
|
|
3556
3628
|
notifyError(e) {
|
|
3557
3629
|
return W(this, e);
|
|
3558
3630
|
}
|
|
3559
|
-
},
|
|
3631
|
+
}, Mr = {
|
|
3560
3632
|
ES256: {
|
|
3561
3633
|
kty: "EC",
|
|
3562
3634
|
key: (e) => ({
|
|
@@ -3587,34 +3659,34 @@ var Z = /* @__PURE__ */ function(e) {
|
|
|
3587
3659
|
},
|
|
3588
3660
|
signature: { name: "RSASSA-PKCS1-v1_5" }
|
|
3589
3661
|
}
|
|
3590
|
-
},
|
|
3662
|
+
}, Nr = (e) => {
|
|
3591
3663
|
let t = e.replace(/-/g, "+").replace(/_/g, "/"), n = globalThis.atob(t + "=".repeat((4 - t.length % 4) % 4));
|
|
3592
3664
|
return Uint8Array.from(n, (e) => e.charCodeAt(0));
|
|
3593
|
-
},
|
|
3665
|
+
}, Pr = () => {
|
|
3594
3666
|
let e = globalThis.crypto;
|
|
3595
3667
|
if (!e?.subtle) throw Error("Verifying tokens needs the Web Crypto API, available only in a secure context (https or localhost)");
|
|
3596
3668
|
return e;
|
|
3597
3669
|
};
|
|
3598
|
-
async function
|
|
3599
|
-
let [a = "", o = "", s = ""] = e.split("."), c = JSON.parse(new TextDecoder().decode(
|
|
3670
|
+
async function Fr(e, t, n, r, i) {
|
|
3671
|
+
let [a = "", o = "", s = ""] = e.split("."), c = JSON.parse(new TextDecoder().decode(Nr(a))), l = c.alg === "ES256" || c.alg === "RS256" ? Mr[c.alg] : void 0;
|
|
3600
3672
|
if (!l) throw Error(`Token signing algorithm ${String(c.alg)} is not accepted`);
|
|
3601
3673
|
let u = t.find((e) => e.kid === c.kid && e.kty === l.kty && (e.kty !== "EC" || e.crv === "P-256"));
|
|
3602
3674
|
if (!u) throw Error("Token signing key is not published by the server");
|
|
3603
|
-
let d =
|
|
3604
|
-
if (!await d.verify(l.signature, f,
|
|
3675
|
+
let d = Pr().subtle, f = await d.importKey("jwk", l.key(u), l.imported, !1, ["verify"]), p = new TextEncoder().encode(`${a}.${o}`);
|
|
3676
|
+
if (!await d.verify(l.signature, f, Nr(s), p)) throw Error("Token signature is not valid");
|
|
3605
3677
|
let m = j(e), h = Array.isArray(m.aud) ? m.aud : [m.aud];
|
|
3606
3678
|
if (m.iss !== n) throw Error("Token issuer does not match the server");
|
|
3607
3679
|
if (!h.includes(r)) throw Error("Token is not issued for this app");
|
|
3608
3680
|
if (typeof m.exp != "number" || A(m, 0)) throw Error("Token has expired");
|
|
3609
3681
|
if (i && m.type !== i) throw Error("Token type is not valid");
|
|
3610
3682
|
}
|
|
3611
|
-
async function
|
|
3683
|
+
async function Ir(t, n, r) {
|
|
3612
3684
|
if (!n) throw Error("An app id is required to accept tokens from the URL");
|
|
3613
3685
|
if (!r.access_token) throw Error("No access token received");
|
|
3614
|
-
|
|
3686
|
+
Pr();
|
|
3615
3687
|
let i = t.replace(/\/+$/, ""), [a, o] = await Promise.all([e.get(`${i}/.well-known/openid-configuration`), e.get(`${i}/.well-known/jwks.json`)]), s = a.data?.issuer, c = o.data?.keys ?? [];
|
|
3616
3688
|
if (!s) throw Error("The server did not publish an issuer");
|
|
3617
|
-
await
|
|
3689
|
+
await Fr(r.access_token, c, s, n, M.access_token), r.refresh_token && await Fr(r.refresh_token, c, s, n, M.refresh_token), r.id_token && await Fr(r.id_token, c, s, n);
|
|
3618
3690
|
}
|
|
3619
3691
|
// lib/upgrade/errors.ts
|
|
3620
3692
|
var Q = {
|
|
@@ -3631,21 +3703,22 @@ var Q = {
|
|
|
3631
3703
|
twoFactorNotEnabled: "error.2fa.not_enabled",
|
|
3632
3704
|
notImplemented: "error.not.implemented",
|
|
3633
3705
|
tokenInvalid: "error.api.request.token.invalid"
|
|
3634
|
-
},
|
|
3706
|
+
}, Lr = Object.freeze([
|
|
3635
3707
|
Q.twoFactorCodeInvalid,
|
|
3636
3708
|
Q.twoFactorNotEnabled,
|
|
3637
3709
|
Q.challengeInvalid,
|
|
3638
3710
|
Q.challengeSessionMismatch,
|
|
3639
3711
|
Q.challengeTooManyAttempts
|
|
3640
|
-
]),
|
|
3712
|
+
]), Rr = Object.freeze([Q.tokenInvalid]), zr = Object.freeze([
|
|
3641
3713
|
"wrong_code",
|
|
3642
3714
|
"challenge_spent",
|
|
3643
3715
|
"not_registered",
|
|
3644
3716
|
"prepare_not_required"
|
|
3645
|
-
]),
|
|
3717
|
+
]), Br = (e) => zr.includes(e), Vr = {
|
|
3646
3718
|
wrong_code: "That code was not accepted. Try again.",
|
|
3647
3719
|
challenge_spent: "That verification challenge is no longer valid. Start again.",
|
|
3648
3720
|
exhausted: "Too many attempts. Try again later.",
|
|
3721
|
+
rate_limited: "Too many requests. Try again later.",
|
|
3649
3722
|
attempts_exhausted: "Too many incorrect attempts. Verification was not completed.",
|
|
3650
3723
|
not_registered: "That verification method is not set up for this account.",
|
|
3651
3724
|
prepare_not_required: "This verification method needs no preparation round.",
|
|
@@ -3656,16 +3729,24 @@ var Q = {
|
|
|
3656
3729
|
session_changed: "The session ended during verification."
|
|
3657
3730
|
}, $ = class extends Error {
|
|
3658
3731
|
constructor(e) {
|
|
3659
|
-
super(e.message ||
|
|
3732
|
+
super(e.message || Vr[e.kind]), this.name = "UpgradeTransportError", this.code = "upgrade_transport", this.kind = e.kind, this.status = e.status, this.errorId = e.errorId, e.retryAfter !== void 0 && (this.retryAfter = e.retryAfter), this.retryable = Br(e.kind), e.cause !== void 0 && (this.cause = e.cause);
|
|
3660
3733
|
}
|
|
3661
|
-
},
|
|
3734
|
+
}, Hr = Object.freeze([
|
|
3662
3735
|
"upgrade_transport",
|
|
3663
3736
|
"upgrade_insufficient",
|
|
3664
3737
|
"upgrade_unavailable",
|
|
3665
3738
|
"upgrade_session_changed",
|
|
3666
3739
|
"upgrade_cancelled",
|
|
3667
|
-
"upgrade_unsatisfiable"
|
|
3668
|
-
|
|
3740
|
+
"upgrade_unsatisfiable",
|
|
3741
|
+
"upgrade_sign_in_required"
|
|
3742
|
+
]), Ur = (e) => typeof e == "object" && !!e && typeof e.code == "string" && Hr.includes(e.code), Wr = (e) => e instanceof $ || typeof e == "object" && !!e && e.code === "upgrade_transport", Gr = (e) => {
|
|
3743
|
+
let t = e?.error, n = typeof t == "string" ? t : t?.message;
|
|
3744
|
+
if (typeof n == "string" && n && !n.startsWith("localized error:")) return n;
|
|
3745
|
+
}, Kr = (e) => {
|
|
3746
|
+
if (!e || typeof e != "object") return;
|
|
3747
|
+
let t = e["retry-after"];
|
|
3748
|
+
return typeof t == "string" && /^\d+$/.test(t.trim()) ? Number(t.trim()) : void 0;
|
|
3749
|
+
}, qr = (e) => {
|
|
3669
3750
|
if (typeof e != "object" || !e) return {
|
|
3670
3751
|
hasResponse: !1,
|
|
3671
3752
|
message: typeof e == "string" ? e : void 0
|
|
@@ -3675,9 +3756,11 @@ var Q = {
|
|
|
3675
3756
|
status: typeof t.status == "number" ? t.status : typeof n?.status == "number" ? n.status : void 0,
|
|
3676
3757
|
errorId: typeof t.id == "string" ? t.id : i,
|
|
3677
3758
|
message: typeof t.message == "string" ? t.message : void 0,
|
|
3678
|
-
hasResponse: n !== void 0 || typeof t.status == "number"
|
|
3759
|
+
hasResponse: n !== void 0 || typeof t.status == "number",
|
|
3760
|
+
serverText: Gr(n?.data),
|
|
3761
|
+
retryAfter: Kr(n?.headers)
|
|
3679
3762
|
};
|
|
3680
|
-
},
|
|
3763
|
+
}, Jr = (e, t) => {
|
|
3681
3764
|
switch (e) {
|
|
3682
3765
|
case Q.twoFactorCodeInvalid: return "wrong_code";
|
|
3683
3766
|
case Q.challengeInvalid:
|
|
@@ -3695,74 +3778,83 @@ var Q = {
|
|
|
3695
3778
|
case "error.service.unavailable": return "network";
|
|
3696
3779
|
default: return;
|
|
3697
3780
|
}
|
|
3698
|
-
},
|
|
3781
|
+
}, Yr = (e, t) => e === void 0 ? "network" : e === 501 ? "unavailable" : e === 400 ? "fatal" : e === 429 ? "rate_limited" : e === 401 || e === 403 ? t === "start" ? "challenge_spent" : "session_changed" : e >= 500 ? "network" : "fatal", Xr = (e, t) => {
|
|
3699
3782
|
if (e instanceof $) return e;
|
|
3700
|
-
let n =
|
|
3701
|
-
|
|
3702
|
-
kind:
|
|
3783
|
+
let n = qr(e);
|
|
3784
|
+
if (!n.hasResponse) return new $({
|
|
3785
|
+
kind: "network",
|
|
3703
3786
|
message: n.message,
|
|
3787
|
+
cause: e
|
|
3788
|
+
});
|
|
3789
|
+
let r = Jr(n.errorId, t) ?? Yr(n.status, t);
|
|
3790
|
+
return r === "rate_limited" ? new $({
|
|
3791
|
+
kind: r,
|
|
3792
|
+
message: n.serverText,
|
|
3704
3793
|
status: n.status,
|
|
3705
3794
|
errorId: n.errorId,
|
|
3795
|
+
retryAfter: n.retryAfter,
|
|
3706
3796
|
cause: e
|
|
3707
3797
|
}) : new $({
|
|
3708
|
-
kind:
|
|
3798
|
+
kind: r,
|
|
3709
3799
|
message: n.message,
|
|
3800
|
+
status: n.status,
|
|
3801
|
+
errorId: n.errorId,
|
|
3710
3802
|
cause: e
|
|
3711
3803
|
});
|
|
3712
|
-
},
|
|
3804
|
+
}, Zr = (e) => e.errorId !== void 0 && Lr.includes(e.errorId), Qr = (e) => e.errorId !== void 0 && Rr.includes(e.errorId), $r = class extends Error {
|
|
3713
3805
|
constructor(e, t, n) {
|
|
3714
3806
|
super(n ?? "The session was elevated, but this action requires a higher assurance level"), this.name = "UpgradeInsufficientError", this.code = "upgrade_insufficient", this.obtained = e, this.required = t;
|
|
3715
3807
|
}
|
|
3716
|
-
},
|
|
3808
|
+
}, ei = class extends Error {
|
|
3717
3809
|
constructor(e = "Step-up verification is not available on this deployment") {
|
|
3718
3810
|
super(e), this.name = "UpgradeUnavailableError", this.code = "upgrade_unavailable";
|
|
3719
3811
|
}
|
|
3720
|
-
},
|
|
3812
|
+
}, ti = class extends Error {
|
|
3721
3813
|
constructor(e = "The session changed during verification") {
|
|
3722
3814
|
super(e), this.name = "UpgradeSessionChangedError", this.code = "upgrade_session_changed";
|
|
3723
3815
|
}
|
|
3724
|
-
},
|
|
3816
|
+
}, ni = (e) => {
|
|
3725
3817
|
if (e && typeof e.sub == "string" && e.sub !== "") return typeof e.sid == "string" && e.sid !== "" ? {
|
|
3726
3818
|
sub: e.sub,
|
|
3727
3819
|
sid: e.sid
|
|
3728
3820
|
} : { sub: e.sub };
|
|
3729
|
-
},
|
|
3821
|
+
}, ri = (e, t) => !t || t.sub !== e.sub ? !1 : e.sid !== void 0 && t.sid !== void 0 ? e.sid === t.sid : !0;
|
|
3730
3822
|
// lib/utils/validation.ts
|
|
3731
|
-
function
|
|
3823
|
+
function ii(e) {
|
|
3732
3824
|
if (!e || typeof e != "string") return !1;
|
|
3733
3825
|
let t = e.split(".");
|
|
3734
3826
|
if (t.length !== 3) return !1;
|
|
3735
3827
|
let n = /^[A-Za-z0-9_-]+$/;
|
|
3736
3828
|
return t.every((e) => n.test(e) && e.length > 0);
|
|
3737
3829
|
}
|
|
3738
|
-
function
|
|
3830
|
+
function ai(e) {
|
|
3739
3831
|
return e.replace(/<[^>]*>/g, "").substring(0, 200);
|
|
3740
3832
|
}
|
|
3741
|
-
function
|
|
3833
|
+
function oi(e) {
|
|
3742
3834
|
if (!e || typeof e != "string") return !1;
|
|
3743
3835
|
let t = e.trim();
|
|
3744
3836
|
return t.length !== 0 && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t);
|
|
3745
3837
|
}
|
|
3746
|
-
function
|
|
3838
|
+
function si(e) {
|
|
3747
3839
|
if (!e || typeof e != "string") return !1;
|
|
3748
3840
|
let t = e.trim();
|
|
3749
3841
|
return /^\+[1-9]\d{1,14}$/.test(t);
|
|
3750
3842
|
}
|
|
3751
|
-
function
|
|
3843
|
+
function ci(e) {
|
|
3752
3844
|
if (!e || typeof e != "string") return !1;
|
|
3753
3845
|
let t = e.trim();
|
|
3754
3846
|
return t.length < 3 || t.length > 30 ? !1 : /^[a-zA-Z0-9_-]+$/.test(t);
|
|
3755
3847
|
}
|
|
3756
|
-
function
|
|
3848
|
+
function li(e, t = 6) {
|
|
3757
3849
|
return !e || typeof e != "string" ? !1 : (t === 8 ? /^\d{8}$/ : /^\d{6}$/).test(e);
|
|
3758
3850
|
}
|
|
3759
|
-
function
|
|
3851
|
+
function ui(e) {
|
|
3760
3852
|
if (!e || typeof e != "string") return null;
|
|
3761
3853
|
let t = e.toUpperCase().replace(/\s+/g, "");
|
|
3762
|
-
return
|
|
3854
|
+
return t.length > 64 || !/^[A-Z0-9-]+$/.test(t) || t.replace(/-/g, "") === "" ? null : t;
|
|
3763
3855
|
}
|
|
3764
3856
|
// lib/services/auth-service.ts
|
|
3765
|
-
var
|
|
3857
|
+
var di = "passflow_2fa_pkce", fi = 3e5, pi = "passflow_pwless_pending", mi = 3e3, hi = "passflow_federated_pkce", gi = 6e5, _i = "AppId is required for federated auth", vi = 10, yi = "The sign-in answered with a PKCE code, but its verifier is gone", bi = (e, t) => new Promise((n, r) => {
|
|
3766
3858
|
if (t?.aborted) {
|
|
3767
3859
|
r(t.reason);
|
|
3768
3860
|
return;
|
|
@@ -3773,21 +3865,21 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
3773
3865
|
t?.removeEventListener("abort", i), n();
|
|
3774
3866
|
}, e);
|
|
3775
3867
|
t?.addEventListener("abort", i, { once: !0 });
|
|
3776
|
-
}),
|
|
3868
|
+
}), xi = (e) => {
|
|
3777
3869
|
if (!e) return;
|
|
3778
3870
|
let t = new URLSearchParams(e.search).get("token");
|
|
3779
3871
|
if (t) return t;
|
|
3780
3872
|
let n = e.hash.indexOf("?");
|
|
3781
3873
|
return n < 0 ? void 0 : new URLSearchParams(e.hash.slice(n + 1)).get("token") ?? void 0;
|
|
3782
|
-
},
|
|
3874
|
+
}, Si = (e) => {
|
|
3783
3875
|
if (e) try {
|
|
3784
3876
|
return j(e).email;
|
|
3785
3877
|
} catch {
|
|
3786
3878
|
return;
|
|
3787
3879
|
}
|
|
3788
|
-
},
|
|
3789
|
-
constructor(e, t, n, r, i, a, o, s, c, l, u, d = ae, f, p = { coordination:
|
|
3790
|
-
this.authApi = e, this.deviceService = t, this.storageManager = n, this.subscribeStore = r, this.tokenCacheService = i, this.scopes = a, this.createTenantForNewUser = o, this.url = s, this.sessionCallbacks = c, this.appId = l, this.platform = d, this.readPkceEnabled = f, this.readAppSettings = m, this.emailChallenges = /* @__PURE__ */ new Map(), this.tokenExchangeConfig = u, this.tokenDeliveryManager = new P(n), u?.enabled && this.tokenDeliveryManager.setMode(N.BFF), this.refresh =
|
|
3880
|
+
}, Ci = class {
|
|
3881
|
+
constructor(e, t, n, r, i, a, o, s, c, l, u, d = ae, f, p = { coordination: Yn() }, m) {
|
|
3882
|
+
this.authApi = e, this.deviceService = t, this.storageManager = n, this.subscribeStore = r, this.tokenCacheService = i, this.scopes = a, this.createTenantForNewUser = o, this.url = s, this.sessionCallbacks = c, this.appId = l, this.platform = d, this.readPkceEnabled = f, this.readAppSettings = m, this.emailChallenges = /* @__PURE__ */ new Map(), this.tokenExchangeConfig = u, this.tokenDeliveryManager = new P(n), u?.enabled && this.tokenDeliveryManager.setMode(N.BFF), this.refresh = Ar({
|
|
3791
3883
|
emit: this.createRefreshEmit(),
|
|
3792
3884
|
storage: n,
|
|
3793
3885
|
cache: i,
|
|
@@ -3795,7 +3887,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
3795
3887
|
coordination: p.coordination,
|
|
3796
3888
|
platform: d,
|
|
3797
3889
|
...p.strikes === void 0 ? {} : { strikes: p.strikes },
|
|
3798
|
-
logger:
|
|
3890
|
+
logger: Qn()
|
|
3799
3891
|
}), this.initializeSession();
|
|
3800
3892
|
}
|
|
3801
3893
|
setAppId(e) {
|
|
@@ -3812,6 +3904,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
3812
3904
|
(this.tokenDeliveryManager.isCookieMode() || this.tokenDeliveryManager.isBFFMode()) && await this.restoreSession();
|
|
3813
3905
|
}
|
|
3814
3906
|
async restoreSession() {
|
|
3907
|
+
if (this.storageManager.holdsOnlyOtherAppSession()) return !1;
|
|
3815
3908
|
if (this.tokenDeliveryManager.isBFFMode() && this.tokenExchangeConfig?.statusUrl) try {
|
|
3816
3909
|
let e = await fetch(this.tokenExchangeConfig.statusUrl, {
|
|
3817
3910
|
method: "GET",
|
|
@@ -3836,12 +3929,19 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
3836
3929
|
if (e.code && !e.access_token) throw Error("A PKCE authorization code was not exchanged, so there are no tokens to apply");
|
|
3837
3930
|
this.tokenExchangeConfig?.enabled || "token_delivery" in e && e.token_delivery && this.tokenDeliveryManager.setMode(e.token_delivery), this.tokenDeliveryManager.setSessionValid(), this.tokenDeliveryManager.isBFFMode() && this.tokenExchangeConfig?.callbackUrl && await this.forwardTokensToBFF(e), e.scopes = t, this.storageManager.saveTokens(e, this.tokenDeliveryManager.getMode()), this.tokenCacheService.setTokensCache(e), e.csrf_token && this.storageManager.setCsrfToken(e.csrf_token);
|
|
3838
3931
|
}
|
|
3932
|
+
notifyRegisteredAndSignedIn(e) {
|
|
3933
|
+
let t = {
|
|
3934
|
+
tokens: e,
|
|
3935
|
+
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
3936
|
+
};
|
|
3937
|
+
this.subscribeStore.notify(Z.Register, t), this.subscribeStore.notify(Z.SignIn, t);
|
|
3938
|
+
}
|
|
3839
3939
|
handlePendingSecondFactor(e, t, n, r) {
|
|
3840
|
-
return e.
|
|
3940
|
+
return e.tfa_token ? (n ? this.rememberPkceSignIn(n.verifier, r) : this.forgetPkceSignIn(), this.subscribeStore.notify(Z.TwoFactorRequired, {
|
|
3841
3941
|
email: t || "",
|
|
3842
3942
|
challengeId: e.challenge_id || "",
|
|
3843
3943
|
tfaToken: e.tfa_token || ""
|
|
3844
|
-
}), !0);
|
|
3944
|
+
}), !0) : !1;
|
|
3845
3945
|
}
|
|
3846
3946
|
handleEmailVerificationStep(e, t, n, r, i) {
|
|
3847
3947
|
if (!Ae(e)) return !1;
|
|
@@ -3860,7 +3960,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
3860
3960
|
rememberEmailChallenge(e, t) {
|
|
3861
3961
|
this.emailChallenges.delete(e), this.emailChallenges.set(e, t);
|
|
3862
3962
|
for (let e of this.emailChallenges.keys()) {
|
|
3863
|
-
if (this.emailChallenges.size <=
|
|
3963
|
+
if (this.emailChallenges.size <= vi) break;
|
|
3864
3964
|
this.emailChallenges.delete(e);
|
|
3865
3965
|
}
|
|
3866
3966
|
}
|
|
@@ -3868,14 +3968,14 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
3868
3968
|
if (this.pendingPkce = {
|
|
3869
3969
|
verifier: e,
|
|
3870
3970
|
scopes: t,
|
|
3871
|
-
expiresAt: Date.now() +
|
|
3971
|
+
expiresAt: Date.now() + fi
|
|
3872
3972
|
}, typeof sessionStorage < "u") try {
|
|
3873
|
-
sessionStorage.setItem(
|
|
3973
|
+
sessionStorage.setItem(di, JSON.stringify(this.pendingPkce));
|
|
3874
3974
|
} catch {}
|
|
3875
3975
|
}
|
|
3876
3976
|
readPendingPkce() {
|
|
3877
3977
|
if (!this.pendingPkce && typeof sessionStorage < "u") try {
|
|
3878
|
-
let e = sessionStorage.getItem(
|
|
3978
|
+
let e = sessionStorage.getItem(di);
|
|
3879
3979
|
this.pendingPkce = e ? JSON.parse(e) : void 0;
|
|
3880
3980
|
} catch {
|
|
3881
3981
|
this.pendingPkce = void 0;
|
|
@@ -3887,17 +3987,17 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
3887
3987
|
}
|
|
3888
3988
|
forgetPkceSignIn() {
|
|
3889
3989
|
if (this.pendingPkce = void 0, typeof sessionStorage < "u") try {
|
|
3890
|
-
sessionStorage.removeItem(
|
|
3990
|
+
sessionStorage.removeItem(di);
|
|
3891
3991
|
} catch {}
|
|
3892
3992
|
}
|
|
3893
3993
|
rememberPendingPasswordless(e) {
|
|
3894
3994
|
if (this.pendingPasswordless = e, typeof sessionStorage < "u") try {
|
|
3895
|
-
sessionStorage.setItem(
|
|
3995
|
+
sessionStorage.setItem(pi, JSON.stringify(e));
|
|
3896
3996
|
} catch {}
|
|
3897
3997
|
}
|
|
3898
3998
|
readPendingPasswordless() {
|
|
3899
3999
|
if (!this.pendingPasswordless && typeof sessionStorage < "u") try {
|
|
3900
|
-
let e = sessionStorage.getItem(
|
|
4000
|
+
let e = sessionStorage.getItem(pi);
|
|
3901
4001
|
this.pendingPasswordless = e ? JSON.parse(e) : void 0;
|
|
3902
4002
|
} catch {
|
|
3903
4003
|
this.pendingPasswordless = void 0;
|
|
@@ -3906,21 +4006,21 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
3906
4006
|
}
|
|
3907
4007
|
forgetPendingPasswordless() {
|
|
3908
4008
|
if (this.pendingPasswordless = void 0, typeof sessionStorage < "u") try {
|
|
3909
|
-
sessionStorage.removeItem(
|
|
4009
|
+
sessionStorage.removeItem(pi);
|
|
3910
4010
|
} catch {}
|
|
3911
4011
|
}
|
|
3912
4012
|
rememberFederatedSlot(e, t) {
|
|
3913
4013
|
if (this.federatedSlot = {
|
|
3914
4014
|
verifier: e,
|
|
3915
4015
|
scopes: t,
|
|
3916
|
-
expiresAt: Date.now() +
|
|
4016
|
+
expiresAt: Date.now() + gi
|
|
3917
4017
|
}, typeof sessionStorage < "u") try {
|
|
3918
|
-
sessionStorage.setItem(
|
|
4018
|
+
sessionStorage.setItem(hi, JSON.stringify(this.federatedSlot));
|
|
3919
4019
|
} catch {}
|
|
3920
4020
|
}
|
|
3921
4021
|
readFederatedSlot() {
|
|
3922
4022
|
if (!this.federatedSlot && typeof sessionStorage < "u") try {
|
|
3923
|
-
let e = sessionStorage.getItem(
|
|
4023
|
+
let e = sessionStorage.getItem(hi);
|
|
3924
4024
|
this.federatedSlot = e ? JSON.parse(e) : void 0;
|
|
3925
4025
|
} catch {
|
|
3926
4026
|
this.federatedSlot = void 0;
|
|
@@ -3929,7 +4029,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
3929
4029
|
}
|
|
3930
4030
|
forgetFederatedSlot() {
|
|
3931
4031
|
if (this.federatedSlot = void 0, typeof sessionStorage < "u") try {
|
|
3932
|
-
sessionStorage.removeItem(
|
|
4032
|
+
sessionStorage.removeItem(hi);
|
|
3933
4033
|
} catch {}
|
|
3934
4034
|
}
|
|
3935
4035
|
async startPkce() {
|
|
@@ -3937,17 +4037,17 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
3937
4037
|
try {
|
|
3938
4038
|
e = await this.readPkceEnabled?.() ?? !1;
|
|
3939
4039
|
} catch (e) {
|
|
3940
|
-
|
|
4040
|
+
Qn().warn("Passflow: could not read the app settings, so this sign-in sends no PKCE challenge", e);
|
|
3941
4041
|
return;
|
|
3942
4042
|
}
|
|
3943
|
-
return e ?
|
|
4043
|
+
return e ? $t() : void 0;
|
|
3944
4044
|
}
|
|
3945
4045
|
async exchangeCode(e, t) {
|
|
3946
4046
|
return !e.code || !t ? e : await this.authApi.pkceExchange(e.code, t.verifier);
|
|
3947
4047
|
}
|
|
3948
4048
|
async completePkceSignIn(e) {
|
|
3949
4049
|
let t = this.readPendingPkce();
|
|
3950
|
-
if (!t) throw Error(
|
|
4050
|
+
if (!t) throw Error(yi);
|
|
3951
4051
|
let n = await this.authApi.pkceExchange(e, t.verifier);
|
|
3952
4052
|
return await this.processAuthResponse(n, t.scopes ?? this.scopes), n;
|
|
3953
4053
|
}
|
|
@@ -3955,6 +4055,12 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
3955
4055
|
let t = e;
|
|
3956
4056
|
(t.access_token || t.id_token || t.token_delivery) && await this.processAuthResponse(t, t.scopes ?? this.readPendingPkce()?.scopes ?? this.scopes);
|
|
3957
4057
|
}
|
|
4058
|
+
async notifySignedIn(e) {
|
|
4059
|
+
this.subscribeStore.notify(Z.SignIn, {
|
|
4060
|
+
tokens: e,
|
|
4061
|
+
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
4062
|
+
}), await this.submitSessionCheck();
|
|
4063
|
+
}
|
|
3958
4064
|
async forwardTokensToBFF(e) {
|
|
3959
4065
|
if (!this.tokenExchangeConfig?.callbackUrl) return;
|
|
3960
4066
|
let t = await fetch(this.tokenExchangeConfig.callbackUrl, {
|
|
@@ -3971,7 +4077,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
3971
4077
|
if (!t.ok) throw Error(`BFF token storage failed: ${t.status}`);
|
|
3972
4078
|
}
|
|
3973
4079
|
async signIn(e) {
|
|
3974
|
-
if ("email" in e && e.email && !
|
|
4080
|
+
if ("email" in e && e.email && !oi(e.email)) {
|
|
3975
4081
|
let e = /* @__PURE__ */ Error("Invalid email format"), t = {
|
|
3976
4082
|
operation: "sign-in",
|
|
3977
4083
|
message: "Invalid email format",
|
|
@@ -3980,7 +4086,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
3980
4086
|
};
|
|
3981
4087
|
throw W(this.subscribeStore, t), e;
|
|
3982
4088
|
}
|
|
3983
|
-
if ("username" in e && e.username && !
|
|
4089
|
+
if ("username" in e && e.username && !ci(e.username)) {
|
|
3984
4090
|
let e = /* @__PURE__ */ Error("Invalid username format. Username must be 3-30 characters and contain only letters, numbers, underscores, and hyphens"), t = {
|
|
3985
4091
|
operation: "sign-in",
|
|
3986
4092
|
message: "Invalid username format. Username must be 3-30 characters and contain only letters, numbers, underscores, and hyphens",
|
|
@@ -3989,7 +4095,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
3989
4095
|
};
|
|
3990
4096
|
throw W(this.subscribeStore, t), e;
|
|
3991
4097
|
}
|
|
3992
|
-
if ("phone" in e && e.phone && !
|
|
4098
|
+
if ("phone" in e && e.phone && !si(e.phone)) {
|
|
3993
4099
|
let e = /* @__PURE__ */ Error("Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)"), t = {
|
|
3994
4100
|
operation: "sign-in",
|
|
3995
4101
|
message: "Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)",
|
|
@@ -3999,7 +4105,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
3999
4105
|
throw W(this.subscribeStore, t), e;
|
|
4000
4106
|
}
|
|
4001
4107
|
this.subscribeStore.notify(Z.SignInStart, { email: e.email });
|
|
4002
|
-
let t = this.deviceService.getDeviceId(), n =
|
|
4108
|
+
let t = this.deviceService.getDeviceId(), n = Ve(this.platform.getDeviceType());
|
|
4003
4109
|
e.scopes = e.scopes ?? this.scopes;
|
|
4004
4110
|
try {
|
|
4005
4111
|
let r = await this.startPkce(), i = await this.authApi.signIn(r ? {
|
|
@@ -4023,7 +4129,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4023
4129
|
}
|
|
4024
4130
|
}
|
|
4025
4131
|
async signUp(e) {
|
|
4026
|
-
if (e.user.email && !
|
|
4132
|
+
if (e.user.email && !oi(e.user.email)) {
|
|
4027
4133
|
let e = /* @__PURE__ */ Error("Invalid email format"), t = {
|
|
4028
4134
|
operation: "sign-up",
|
|
4029
4135
|
message: "Invalid email format",
|
|
@@ -4032,7 +4138,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4032
4138
|
};
|
|
4033
4139
|
throw W(this.subscribeStore, t), e;
|
|
4034
4140
|
}
|
|
4035
|
-
if (e.user.phone_number && !
|
|
4141
|
+
if (e.user.phone_number && !si(e.user.phone_number)) {
|
|
4036
4142
|
let e = /* @__PURE__ */ Error("Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)"), t = {
|
|
4037
4143
|
operation: "sign-up",
|
|
4038
4144
|
message: "Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)",
|
|
@@ -4049,10 +4155,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4049
4155
|
} : e);
|
|
4050
4156
|
if (this.handleEmailVerificationStep(n, "sign-up", e.user.email, t, e.scopes) || this.handlePendingSecondFactor(n, e.user.email, t, e.scopes)) return n;
|
|
4051
4157
|
let r = await this.exchangeCode(n, t);
|
|
4052
|
-
return this.handlePendingSecondFactor(r, e.user.email) || (await this.processAuthResponse(r, e.scopes), this.
|
|
4053
|
-
tokens: r,
|
|
4054
|
-
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
4055
|
-
}), await this.submitSessionCheck()), r;
|
|
4158
|
+
return this.handlePendingSecondFactor(r, e.user.email) || (await this.processAuthResponse(r, e.scopes), this.notifyRegisteredAndSignedIn(r), await this.submitSessionCheck()), r;
|
|
4056
4159
|
} catch (e) {
|
|
4057
4160
|
let t = {
|
|
4058
4161
|
operation: "sign-up",
|
|
@@ -4064,7 +4167,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4064
4167
|
}
|
|
4065
4168
|
}
|
|
4066
4169
|
async passwordlessSignIn(e) {
|
|
4067
|
-
if (e.email && !
|
|
4170
|
+
if (e.email && !oi(e.email)) {
|
|
4068
4171
|
let e = /* @__PURE__ */ Error("Invalid email format"), t = {
|
|
4069
4172
|
operation: "passwordless.start",
|
|
4070
4173
|
message: "Invalid email format",
|
|
@@ -4073,7 +4176,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4073
4176
|
};
|
|
4074
4177
|
throw W(this.subscribeStore, t), e;
|
|
4075
4178
|
}
|
|
4076
|
-
if (e.phone && !
|
|
4179
|
+
if (e.phone && !si(e.phone)) {
|
|
4077
4180
|
let e = /* @__PURE__ */ Error("Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)"), t = {
|
|
4078
4181
|
operation: "passwordless.start",
|
|
4079
4182
|
message: "Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)",
|
|
@@ -4083,7 +4186,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4083
4186
|
throw W(this.subscribeStore, t), e;
|
|
4084
4187
|
}
|
|
4085
4188
|
this.subscribeStore.notify(Z.SignInStart, { email: e.email });
|
|
4086
|
-
let t = e.scopes ?? this.scopes, n = this.deviceService.getDeviceId(), r =
|
|
4189
|
+
let t = e.scopes ?? this.scopes, n = this.deviceService.getDeviceId(), r = Ve(this.platform.getDeviceType());
|
|
4087
4190
|
try {
|
|
4088
4191
|
let i = await this.startPkce(), a = await this.authApi.passwordlessSignIn({
|
|
4089
4192
|
...e,
|
|
@@ -4117,7 +4220,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4117
4220
|
if (r = !0, this.handlePendingSecondFactor(t, n?.email, n && { verifier: n.verifier }, n?.scopes)) return this.forgetPendingPasswordless(), t;
|
|
4118
4221
|
let i = t;
|
|
4119
4222
|
if (t.code) {
|
|
4120
|
-
if (!n) throw Error(
|
|
4223
|
+
if (!n) throw Error(yi);
|
|
4121
4224
|
if (i = await this.authApi.pkceExchange(t.code, n.verifier), this.handlePendingSecondFactor(i)) return this.forgetPendingPasswordless(), {
|
|
4122
4225
|
...i,
|
|
4123
4226
|
redirect_url: t.redirect_url ?? ""
|
|
@@ -4149,11 +4252,11 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4149
4252
|
let n = t?.signal;
|
|
4150
4253
|
try {
|
|
4151
4254
|
let t = this.readPendingPasswordless();
|
|
4152
|
-
if (t?.challengeId !== e) throw Error(
|
|
4255
|
+
if (t?.challengeId !== e) throw Error(yi);
|
|
4153
4256
|
for (;;) {
|
|
4154
4257
|
if (n?.aborted) throw n.reason;
|
|
4155
4258
|
if (Date.now() >= t.expiresAt) return this.forgetPendingPasswordless(), { status: "expired" };
|
|
4156
|
-
if (this.readPendingPasswordless()?.challengeId !== e) throw Error(
|
|
4259
|
+
if (this.readPendingPasswordless()?.challengeId !== e) throw Error(yi);
|
|
4157
4260
|
let r;
|
|
4158
4261
|
try {
|
|
4159
4262
|
r = await this.authApi.passwordlessStatus({
|
|
@@ -4171,7 +4274,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4171
4274
|
status: "signed-in",
|
|
4172
4275
|
tokens: { redirect_url: r.redirect_url }
|
|
4173
4276
|
};
|
|
4174
|
-
await
|
|
4277
|
+
await bi(mi, n);
|
|
4175
4278
|
}
|
|
4176
4279
|
} catch (e) {
|
|
4177
4280
|
if (n?.aborted && e === n.reason) throw e;
|
|
@@ -4240,21 +4343,21 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4240
4343
|
let t = this.emailChallenges.get(e.challenge_id), n = t?.email;
|
|
4241
4344
|
try {
|
|
4242
4345
|
let r = t?.pkce === !1 ? void 0 : this.readPendingPkce();
|
|
4243
|
-
if (t?.pkce && !r) throw Error(
|
|
4346
|
+
if (t?.pkce && !r) throw Error(yi);
|
|
4244
4347
|
let i = await this.authApi.validateEmailCode(e);
|
|
4245
4348
|
this.emailChallenges.delete(e.challenge_id);
|
|
4246
4349
|
let a = r?.scopes ?? t?.scopes ?? this.scopes;
|
|
4247
4350
|
if (this.handleEmailVerificationStep(i, t?.operation ?? "sign-in", n, r, a) || this.handlePendingSecondFactor(i, n, r, a)) return i;
|
|
4248
4351
|
let o = i;
|
|
4249
4352
|
if (i.code) {
|
|
4250
|
-
if (!r) throw Error(
|
|
4353
|
+
if (!r) throw Error(yi);
|
|
4251
4354
|
if (o = await this.authApi.pkceExchange(i.code, r.verifier), this.handlePendingSecondFactor(o, n)) return o;
|
|
4252
4355
|
}
|
|
4253
4356
|
let s = i.redirect_url ? {
|
|
4254
4357
|
...o,
|
|
4255
4358
|
redirect_url: i.redirect_url
|
|
4256
4359
|
} : o;
|
|
4257
|
-
return await this.processAuthResponse(s, a), this.forgetPkceSignIn(),
|
|
4360
|
+
return await this.processAuthResponse(s, a), this.forgetPkceSignIn(), t?.operation === "sign-up" ? this.notifyRegisteredAndSignedIn(s) : this.subscribeStore.notify(Z.SignIn, {
|
|
4258
4361
|
tokens: s,
|
|
4259
4362
|
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
4260
4363
|
}), await this.submitSessionCheck(), s;
|
|
@@ -4280,6 +4383,14 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4280
4383
|
this.emailChallenges.clear(), this.clearLocalSession();
|
|
4281
4384
|
}), e;
|
|
4282
4385
|
}
|
|
4386
|
+
hostedEndSessionUrl(e) {
|
|
4387
|
+
let t = this.storageManager.getHostedSignIn();
|
|
4388
|
+
if (!t) return;
|
|
4389
|
+
let n = { post_logout_redirect_uri: e ?? t };
|
|
4390
|
+
this.appId && (n.client_id = this.appId);
|
|
4391
|
+
let r = this.storageManager.getToken(M.id_token) ?? this.storageManager.getIdToken();
|
|
4392
|
+
return r && (n.id_token_hint = r), `${this.url.replace(/\/+$/, "")}/oidc/end_session?${new URLSearchParams(n)}`;
|
|
4393
|
+
}
|
|
4283
4394
|
async callLogoutApi(e) {
|
|
4284
4395
|
if (this.tokenDeliveryManager.isBFFMode() && this.tokenExchangeConfig?.logoutUrl) {
|
|
4285
4396
|
try {
|
|
@@ -4296,18 +4407,19 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4296
4407
|
} catch {}
|
|
4297
4408
|
}
|
|
4298
4409
|
clearLocalSession() {
|
|
4299
|
-
|
|
4410
|
+
let e = this.storageManager.holdsOnlyOtherAppSession();
|
|
4411
|
+
this.storageManager.deleteTokens(), this.storageManager.clearIdToken(), this.storageManager.clearCsrfToken(), this.tokenDeliveryManager.reset(e), this.tokenCacheService.setTokensCache(void 0), this.tokenCacheService.stopTokenCheck?.();
|
|
4300
4412
|
}
|
|
4301
4413
|
readSessionPin() {
|
|
4302
4414
|
try {
|
|
4303
4415
|
let e = this.storageManager.getToken(M.access_token);
|
|
4304
|
-
return e ?
|
|
4416
|
+
return e ? ni(j(e)) : void 0;
|
|
4305
4417
|
} catch {
|
|
4306
4418
|
return;
|
|
4307
4419
|
}
|
|
4308
4420
|
}
|
|
4309
4421
|
assertSessionPin(e) {
|
|
4310
|
-
if (e &&
|
|
4422
|
+
if (e && !ri(e, this.readSessionPin())) throw console.warn("[passflow] the session or user changed while a step-up upgrade was in flight; the elevated tokens were discarded and the live session was left untouched."), new ti("The session changed during verification, so the elevated tokens were discarded");
|
|
4311
4423
|
}
|
|
4312
4424
|
refreshMode() {
|
|
4313
4425
|
return this.tokenDeliveryManager.isBFFMode() && this.tokenExchangeConfig?.refreshUrl ? "bff" : this.tokenDeliveryManager.isCookieMode() ? "cookie" : "json";
|
|
@@ -4355,7 +4467,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4355
4467
|
case "signout":
|
|
4356
4468
|
n.notify(Z.SignOut, t);
|
|
4357
4469
|
return;
|
|
4358
|
-
default:
|
|
4470
|
+
default: Qn().warn(`[passflow] Unknown refresh event: ${String(e)}`);
|
|
4359
4471
|
}
|
|
4360
4472
|
};
|
|
4361
4473
|
}
|
|
@@ -4441,10 +4553,10 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4441
4553
|
}
|
|
4442
4554
|
async resetPassword(e, t, n) {
|
|
4443
4555
|
this.subscribeStore.notify(Z.SignInStart, {});
|
|
4444
|
-
let r = n ??
|
|
4556
|
+
let r = n ?? xi(this.platform.getCurrentUrl()), i = t ?? this.scopes;
|
|
4445
4557
|
try {
|
|
4446
4558
|
let t = await this.startPkce(), n = t ? await this.authApi.resetPassword(e, i, r, t.challenge) : await this.authApi.resetPassword(e, i, r);
|
|
4447
|
-
if (this.handleEmailVerificationStep(n, "reset-password",
|
|
4559
|
+
if (this.handleEmailVerificationStep(n, "reset-password", Si(r), t, i) || this.handlePendingSecondFactor(n, void 0, t, i)) return n;
|
|
4448
4560
|
let a = await this.exchangeCode(n, t);
|
|
4449
4561
|
if (this.handlePendingSecondFactor(a)) return a;
|
|
4450
4562
|
let o = n.redirect_url ? {
|
|
@@ -4468,7 +4580,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4468
4580
|
async passkeyRegister(e) {
|
|
4469
4581
|
if (!this.platform.passkeys) throw Error("Passkeys are not supported on this platform");
|
|
4470
4582
|
this.subscribeStore.notify(Z.RegisterStart, {});
|
|
4471
|
-
let t = this.deviceService.getDeviceId(), n =
|
|
4583
|
+
let t = this.deviceService.getDeviceId(), n = Ve(this.platform.getDeviceType());
|
|
4472
4584
|
e.scopes = e.scopes ?? this.scopes, e.create_tenant = this.createTenantForNewUser;
|
|
4473
4585
|
try {
|
|
4474
4586
|
let r = await this.startPkce(), { challenge_id: i, publicKey: a } = await this.authApi.passkeyRegisterStart(r ? {
|
|
@@ -4481,10 +4593,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4481
4593
|
let s = await this.authApi.passkeyRegisterComplete(o, t, i, !this.appId);
|
|
4482
4594
|
if (this.handlePendingSecondFactor(s, void 0, r, e.scopes)) return s;
|
|
4483
4595
|
let c = await this.exchangeCode(s, r);
|
|
4484
|
-
return this.handlePendingSecondFactor(c) || (await this.processAuthResponse(c, e.scopes), this.
|
|
4485
|
-
tokens: c,
|
|
4486
|
-
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
4487
|
-
}), await this.submitSessionCheck()), c;
|
|
4596
|
+
return this.handlePendingSecondFactor(c) || (await this.processAuthResponse(c, e.scopes), this.notifyRegisteredAndSignedIn(c), await this.submitSessionCheck()), c;
|
|
4488
4597
|
} catch (e) {
|
|
4489
4598
|
let t = {
|
|
4490
4599
|
operation: "passkey.register",
|
|
@@ -4498,7 +4607,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4498
4607
|
async passkeyAuthenticate(e) {
|
|
4499
4608
|
if (!this.platform.passkeys) throw Error("Passkeys are not supported on this platform");
|
|
4500
4609
|
this.subscribeStore.notify(Z.SignInStart, {});
|
|
4501
|
-
let t = this.deviceService.getDeviceId(), n =
|
|
4610
|
+
let t = this.deviceService.getDeviceId(), n = Ve(this.platform.getDeviceType());
|
|
4502
4611
|
e.scopes = e.scopes ?? this.scopes;
|
|
4503
4612
|
try {
|
|
4504
4613
|
let r = await this.startPkce(), { challenge_id: i, publicKey: a } = await this.authApi.passkeyAuthenticateStart(r ? {
|
|
@@ -4525,7 +4634,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4525
4634
|
}
|
|
4526
4635
|
createFederatedAuthUrl(e) {
|
|
4527
4636
|
let t = `/auth/federated/start/${e.provider}`;
|
|
4528
|
-
if (!this.appId) throw Error(
|
|
4637
|
+
if (!this.appId) throw Error(_i);
|
|
4529
4638
|
let n = {
|
|
4530
4639
|
scopes: (e.scopes ?? this.scopes).join(" "),
|
|
4531
4640
|
redirect_url: e.redirect_url ?? this.platform.getCurrentUrl()?.origin ?? "",
|
|
@@ -4541,7 +4650,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4541
4650
|
return r.search = new URLSearchParams(n).toString(), r.toString();
|
|
4542
4651
|
}
|
|
4543
4652
|
async federatedAuthWithPopup(e) {
|
|
4544
|
-
if (this.subscribeStore.notify(Z.SignInStart, { provider: e.provider }), !this.appId) throw Error(
|
|
4653
|
+
if (this.subscribeStore.notify(Z.SignInStart, { provider: e.provider }), !this.appId) throw Error(_i);
|
|
4545
4654
|
let t = e.scopes ?? this.scopes, n = this.deviceService.getDeviceId();
|
|
4546
4655
|
try {
|
|
4547
4656
|
this.forgetFederatedSlot();
|
|
@@ -4569,11 +4678,11 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4569
4678
|
scopes: t
|
|
4570
4679
|
};
|
|
4571
4680
|
if (r) {
|
|
4572
|
-
if (!l) throw
|
|
4681
|
+
if (!l) throw an();
|
|
4573
4682
|
if (m = await this.authApi.pkceExchange(l, r.verifier), this.handlePendingSecondFactor(m)) return;
|
|
4574
4683
|
} else {
|
|
4575
|
-
if (!await this.isSimpleModeApp()) throw
|
|
4576
|
-
await
|
|
4684
|
+
if (!await this.isSimpleModeApp()) throw an();
|
|
4685
|
+
await Ir(this.url, this.appId, m);
|
|
4577
4686
|
}
|
|
4578
4687
|
await this.processAuthResponse(m, t), this.subscribeStore.notify(Z.SignIn, {
|
|
4579
4688
|
tokens: m,
|
|
@@ -4599,7 +4708,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4599
4708
|
}
|
|
4600
4709
|
}
|
|
4601
4710
|
federatedAuthWithRedirect(e) {
|
|
4602
|
-
if (this.subscribeStore.notify(Z.SignInStart, { provider: e.provider }), !this.appId) throw Error(
|
|
4711
|
+
if (this.subscribeStore.notify(Z.SignInStart, { provider: e.provider }), !this.appId) throw Error(_i);
|
|
4603
4712
|
let t = e.scopes ?? this.scopes, n = this.deviceService.getDeviceId();
|
|
4604
4713
|
this.startPkce().then((r) => {
|
|
4605
4714
|
let i = this.createFederatedAuthUrl({
|
|
@@ -4663,7 +4772,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4663
4772
|
async authRedirect(e = {}) {
|
|
4664
4773
|
try {
|
|
4665
4774
|
let { url: t, appId: n, redirectUrl: r, scopes: i, state: a } = e;
|
|
4666
|
-
if (t !== void 0 &&
|
|
4775
|
+
if (t !== void 0 && cn(t) !== cn(this.url) || n !== void 0 && n !== (this.appId ?? "")) throw new U("OVERRIDE_NOT_SUPPORTED", "authRedirect() signs in to this instance's url and appId; create a Passflow instance for another server or app");
|
|
4667
4776
|
let o = await this.readAppSettings?.();
|
|
4668
4777
|
if (o?.pkce_enabled !== !0) {
|
|
4669
4778
|
let e = this.authRedirectUrl({
|
|
@@ -4673,8 +4782,8 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4673
4782
|
this.platform.navigateTo(a ? `${e}&${new URLSearchParams({ state: a })}` : e);
|
|
4674
4783
|
return;
|
|
4675
4784
|
}
|
|
4676
|
-
if (o.public_client === !1) throw new U("CONFIDENTIAL_CLIENT",
|
|
4677
|
-
let s = this.platform.getCurrentUrl(), c = await
|
|
4785
|
+
if (o.public_client === !1) throw new U("CONFIDENTIAL_CLIENT", nn(o.type));
|
|
4786
|
+
let s = this.platform.getCurrentUrl(), c = await un({
|
|
4678
4787
|
url: this.url,
|
|
4679
4788
|
clientId: this.appId ?? "",
|
|
4680
4789
|
redirectUri: r ?? (s ? s.origin + s.pathname : ""),
|
|
@@ -4695,9 +4804,9 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4695
4804
|
if (!this.appId) return !1;
|
|
4696
4805
|
let t = new URLSearchParams(e.search), n = t.get("code"), r = t.get("state"), i = t.get("error"), a = t.get("error_description");
|
|
4697
4806
|
if (t.get("user_state") || r === null || !n && !i) return !1;
|
|
4698
|
-
let o =
|
|
4807
|
+
let o = fn();
|
|
4699
4808
|
if (o.status === "none") return !1;
|
|
4700
|
-
|
|
4809
|
+
pn();
|
|
4701
4810
|
for (let e of [
|
|
4702
4811
|
"code",
|
|
4703
4812
|
"state",
|
|
@@ -4709,18 +4818,19 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4709
4818
|
return this.platform.replaceUrl(e.pathname + (s ? `?${s}` : "") + e.hash), this.finishOidcLanding(async () => {
|
|
4710
4819
|
if (o.status === "unusable") throw new U("VERIFIER_MISSING", "This sign-in has expired or its proof key is gone. Sign in again.");
|
|
4711
4820
|
if (o.slot.state !== r) throw new U("STATE_MISMATCH", "The sign-in answer does not belong to this sign-in. Sign in again.");
|
|
4712
|
-
if (i || !n) throw new U(i ?? "TOKEN_EXCHANGE_FAILED",
|
|
4821
|
+
if (i || !n) throw new U(i ?? "TOKEN_EXCHANGE_FAILED", ai(a || i || "Sign in again."));
|
|
4713
4822
|
return {
|
|
4714
|
-
tokens: await
|
|
4715
|
-
scopes: o.slot.scopes
|
|
4823
|
+
tokens: await hn(this.url, n, o.slot),
|
|
4824
|
+
scopes: o.slot.scopes,
|
|
4825
|
+
returnUrl: o.slot.redirectUri
|
|
4716
4826
|
};
|
|
4717
4827
|
}), !0;
|
|
4718
4828
|
}
|
|
4719
4829
|
async finishOidcLanding(e) {
|
|
4720
4830
|
try {
|
|
4721
4831
|
await Promise.resolve();
|
|
4722
|
-
let { tokens: t, scopes: n } = await e();
|
|
4723
|
-
await this.processAuthResponse(t, n), this.subscribeStore.notify(Z.SignIn, {
|
|
4832
|
+
let { tokens: t, scopes: n, returnUrl: r } = await e();
|
|
4833
|
+
await this.processAuthResponse(t, n), this.storageManager.setHostedSignIn(r), this.subscribeStore.notify(Z.SignIn, {
|
|
4724
4834
|
tokens: t,
|
|
4725
4835
|
parsedTokens: this.tokenCacheService.getParsedTokens(),
|
|
4726
4836
|
source: "oidc-landing"
|
|
@@ -4791,7 +4901,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4791
4901
|
return;
|
|
4792
4902
|
}
|
|
4793
4903
|
}
|
|
4794
|
-
},
|
|
4904
|
+
}, wi = class {
|
|
4795
4905
|
constructor(e) {
|
|
4796
4906
|
this.invitationApi = e;
|
|
4797
4907
|
}
|
|
@@ -4810,7 +4920,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4810
4920
|
getInvitationLink(e) {
|
|
4811
4921
|
return this.invitationApi.getInvitationLink(e);
|
|
4812
4922
|
}
|
|
4813
|
-
},
|
|
4923
|
+
}, Ti = class {
|
|
4814
4924
|
constructor(e) {
|
|
4815
4925
|
this.data = this.normalize(e);
|
|
4816
4926
|
}
|
|
@@ -4867,9 +4977,9 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4867
4977
|
getData() {
|
|
4868
4978
|
return this.data;
|
|
4869
4979
|
}
|
|
4870
|
-
},
|
|
4980
|
+
}, Ei = class {
|
|
4871
4981
|
constructor(e, t, n) {
|
|
4872
|
-
this.tenantApi = e, this.scopes = t, this.logger = n ||
|
|
4982
|
+
this.tenantApi = e, this.scopes = t, this.logger = n || Qn();
|
|
4873
4983
|
}
|
|
4874
4984
|
handlePassflowError(t, n) {
|
|
4875
4985
|
if (e.isAxiosError(t) && t.response?.data) {
|
|
@@ -4905,7 +5015,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
4905
5015
|
}
|
|
4906
5016
|
async getTenantUserMembership(e) {
|
|
4907
5017
|
try {
|
|
4908
|
-
return new
|
|
5018
|
+
return new Ti(await this.tenantApi.getTenantDetails(e));
|
|
4909
5019
|
} catch (t) {
|
|
4910
5020
|
this.handlePassflowError(t, `Get tenant user membership failed for tenant ID ${e}`);
|
|
4911
5021
|
}
|
|
@@ -5050,7 +5160,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5050
5160
|
this.handlePassflowError(r, `Invalidate invite by email failed for tenant ID ${e}, group ID ${t}, email ${n}`);
|
|
5051
5161
|
}
|
|
5052
5162
|
}
|
|
5053
|
-
},
|
|
5163
|
+
}, Di = class {
|
|
5054
5164
|
constructor(e, t, n, r = ae) {
|
|
5055
5165
|
this.storageManager = e, this.subscribeStore = n, this.platform = r, this.checkInterval = null, this.CHECK_INTERVAL = 6e4, this.unsubscribeForeground = null, this.unsubscribeUnload = null, this.tokenExpiredFlag = !1, this.storageManager = e, this.setupLifecycleListeners();
|
|
5056
5166
|
}
|
|
@@ -5130,9 +5240,9 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5130
5240
|
isExpired() {
|
|
5131
5241
|
return this.tokensCache ? this.tokensCache.access_token ? A(j(this.tokensCache.access_token)) : !1 : !0;
|
|
5132
5242
|
}
|
|
5133
|
-
},
|
|
5243
|
+
}, Oi = class {
|
|
5134
5244
|
constructor(e, t, n) {
|
|
5135
|
-
this.twoFactorApi = e, this.subscribeStore = t, this.signInCompleter = n, this.PARTIAL_AUTH_TIMEOUT_MS = 3e5, this.SESSION_STORAGE_KEY = "passflow_2fa_challenge", this.
|
|
5245
|
+
this.twoFactorApi = e, this.subscribeStore = t, this.signInCompleter = n, this.PARTIAL_AUTH_TIMEOUT_MS = 3e5, this.SESSION_STORAGE_KEY = "passflow_2fa_challenge", this.subscribeStore.subscribe({ onAuthChange: (e, t) => {
|
|
5136
5246
|
if (e === Z.TwoFactorRequired) {
|
|
5137
5247
|
let e = t;
|
|
5138
5248
|
this.setPartialAuthState(e.email, e.challengeId, e.tfaToken);
|
|
@@ -5156,7 +5266,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5156
5266
|
async getStatus() {
|
|
5157
5267
|
try {
|
|
5158
5268
|
let e = await this.twoFactorApi.getStatus(this.getMagicLinkSessionToken() ?? void 0);
|
|
5159
|
-
return
|
|
5269
|
+
return this.storeTotpDigits(e.totp_digits), e;
|
|
5160
5270
|
} catch (e) {
|
|
5161
5271
|
this.emitErrorAndThrow(e, "2fa.status", "Get 2FA status");
|
|
5162
5272
|
}
|
|
@@ -5179,7 +5289,8 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5179
5289
|
}
|
|
5180
5290
|
async getEnrollment() {
|
|
5181
5291
|
try {
|
|
5182
|
-
|
|
5292
|
+
let e = await this.twoFactorApi.getEnrollment(this.requirePendingTfaToken());
|
|
5293
|
+
return this.storeTotpDigits(e.totp_digits), e;
|
|
5183
5294
|
} catch (e) {
|
|
5184
5295
|
this.emitErrorAndThrow(e, "2fa.enrollment.read", "Read 2FA enrollment");
|
|
5185
5296
|
}
|
|
@@ -5207,27 +5318,33 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5207
5318
|
}
|
|
5208
5319
|
}
|
|
5209
5320
|
assertTotpCode(e) {
|
|
5210
|
-
|
|
5321
|
+
let t = this.totpDigits;
|
|
5322
|
+
if (t) {
|
|
5323
|
+
if (!li(e, t)) throw Error(`Invalid TOTP code format. Code must be exactly ${t} digits.`);
|
|
5324
|
+
} else if (!li(e, 6) && !li(e, 8)) throw Error("Invalid TOTP code format. Code must be 6 or 8 digits.");
|
|
5211
5325
|
}
|
|
5212
5326
|
requirePendingTfaToken() {
|
|
5213
5327
|
let e = this.pendingTfaToken();
|
|
5214
5328
|
if (!e) throw Error("2FA verification expired or not required. User must sign in first.");
|
|
5215
5329
|
return e;
|
|
5216
5330
|
}
|
|
5331
|
+
storeTotpDigits(e) {
|
|
5332
|
+
e && (this.totpDigits = e);
|
|
5333
|
+
}
|
|
5217
5334
|
setupStarted(e) {
|
|
5218
|
-
return
|
|
5335
|
+
return this.storeTotpDigits(e.totp_digits), this.subscribeStore.notify(Z.TwoFactorSetupStarted, { secret: e.secret }), e;
|
|
5219
5336
|
}
|
|
5220
5337
|
setupConfirmed(e) {
|
|
5338
|
+
let t = e.recovery_codes ?? [];
|
|
5221
5339
|
return this.subscribeStore.notify(Z.TwoFactorEnabled, {
|
|
5222
|
-
recoveryCodes:
|
|
5340
|
+
recoveryCodes: t,
|
|
5223
5341
|
clearRecoveryCodes: () => {
|
|
5224
|
-
|
|
5342
|
+
t.length = 0;
|
|
5225
5343
|
}
|
|
5226
5344
|
}), e;
|
|
5227
5345
|
}
|
|
5228
5346
|
async verify(e, t) {
|
|
5229
|
-
if (
|
|
5230
|
-
if (this.recoverPartialAuthState(), !this.isVerificationRequired()) throw Error("2FA verification expired or not required. User must sign in first.");
|
|
5347
|
+
if (this.assertTotpCode(e), this.recoverPartialAuthState(), !this.isVerificationRequired()) throw Error("2FA verification expired or not required. User must sign in first.");
|
|
5231
5348
|
if (!this.partialAuthState?.tfaToken) throw Error("No TFA token found. User must sign in first.");
|
|
5232
5349
|
try {
|
|
5233
5350
|
let n = await this.twoFactorApi.verify({
|
|
@@ -5242,18 +5359,18 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5242
5359
|
}
|
|
5243
5360
|
async useRecoveryCode(e, t) {
|
|
5244
5361
|
try {
|
|
5245
|
-
let n =
|
|
5246
|
-
if (!n) throw Error("Invalid recovery code format. Expected
|
|
5362
|
+
let n = ui(e);
|
|
5363
|
+
if (!n) throw Error("Invalid recovery code format. Expected letters, digits and dashes, such as XXXX-XXXX-XXXX.");
|
|
5247
5364
|
if (this.recoverPartialAuthState(), !this.isVerificationRequired()) throw Error("2FA verification expired or not required. User must sign in first.");
|
|
5248
5365
|
if (!this.partialAuthState?.tfaToken) throw Error("No TFA token found. User must sign in first.");
|
|
5249
5366
|
let r = await this.finishSignIn(await this.twoFactorApi.useRecoveryCode({
|
|
5250
5367
|
recovery_code: n,
|
|
5251
5368
|
tfa_token: this.partialAuthState.tfaToken,
|
|
5252
5369
|
...t?.trustDevice ? { trust_device: !0 } : {}
|
|
5253
|
-
}));
|
|
5254
|
-
return
|
|
5370
|
+
})), i = r.remaining_recovery_codes;
|
|
5371
|
+
return i === 0 ? this.subscribeStore.notify(Z.TwoFactorRecoveryCodesExhausted, { tokens: r }) : typeof i == "number" && i <= 2 && this.subscribeStore.notify(Z.TwoFactorRecoveryCodesLow, {
|
|
5255
5372
|
tokens: r,
|
|
5256
|
-
remainingCodes:
|
|
5373
|
+
remainingCodes: i
|
|
5257
5374
|
}), this.subscribeStore.notify(Z.TwoFactorRecoveryUsed, {
|
|
5258
5375
|
tokens: r,
|
|
5259
5376
|
remainingCodes: r.remaining_recovery_codes
|
|
@@ -5263,7 +5380,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5263
5380
|
}
|
|
5264
5381
|
}
|
|
5265
5382
|
async disable(e) {
|
|
5266
|
-
|
|
5383
|
+
this.assertTotpCode(e);
|
|
5267
5384
|
try {
|
|
5268
5385
|
let t = await this.twoFactorApi.disable({ code: e });
|
|
5269
5386
|
return this.subscribeStore.notify(Z.TwoFactorDisabled, {}), t;
|
|
@@ -5272,7 +5389,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5272
5389
|
}
|
|
5273
5390
|
}
|
|
5274
5391
|
async regenerateRecoveryCodes(e) {
|
|
5275
|
-
|
|
5392
|
+
this.assertTotpCode(e);
|
|
5276
5393
|
try {
|
|
5277
5394
|
let t = await this.twoFactorApi.regenerateRecoveryCodes({ code: e }), n = [...t.recovery_codes];
|
|
5278
5395
|
return t.recovery_codes = [], t.recovery_codes = n, t;
|
|
@@ -5284,7 +5401,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5284
5401
|
return this.recoverPartialAuthState(), this.partialAuthState ? Date.now() > this.partialAuthState.expiresAt ? (this.clearPartialAuthState(), !1) : !0 : !1;
|
|
5285
5402
|
}
|
|
5286
5403
|
setPartialAuthState(e, t, n) {
|
|
5287
|
-
if (this.partialAuthState = {
|
|
5404
|
+
if (this.totpDigits = void 0, this.partialAuthState = {
|
|
5288
5405
|
email: e,
|
|
5289
5406
|
challengeId: t,
|
|
5290
5407
|
tfaToken: n,
|
|
@@ -5295,7 +5412,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5295
5412
|
} catch {}
|
|
5296
5413
|
}
|
|
5297
5414
|
clearPartialAuthState() {
|
|
5298
|
-
if (this.partialAuthState = void 0, this.signInCompleter?.forgetPkceSignIn(), typeof sessionStorage < "u") try {
|
|
5415
|
+
if (this.partialAuthState = void 0, this.totpDigits = void 0, this.signInCompleter?.forgetPkceSignIn(), typeof sessionStorage < "u") try {
|
|
5299
5416
|
sessionStorage.removeItem(this.SESSION_STORAGE_KEY);
|
|
5300
5417
|
} catch {}
|
|
5301
5418
|
}
|
|
@@ -5360,7 +5477,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5360
5477
|
return this.getMagicLinkSession()?.sessionToken || null;
|
|
5361
5478
|
}
|
|
5362
5479
|
getTotpDigits() {
|
|
5363
|
-
return this.totpDigits;
|
|
5480
|
+
return this.totpDigits ?? 6;
|
|
5364
5481
|
}
|
|
5365
5482
|
async getAvailableMethods() {
|
|
5366
5483
|
try {
|
|
@@ -5408,10 +5525,10 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5408
5525
|
async requestChallenge(e) {
|
|
5409
5526
|
try {
|
|
5410
5527
|
let t = await this.twoFactorApi.requestChallenge(e, this.pendingTfaToken());
|
|
5411
|
-
return this.subscribeStore.notify(Z.TwoFactorChallengeReceived, {
|
|
5528
|
+
return this.storeTotpDigits(t.totp_digits), this.subscribeStore.notify(Z.TwoFactorChallengeReceived, {
|
|
5412
5529
|
challengeId: t.challenge_id,
|
|
5413
5530
|
method: t.method,
|
|
5414
|
-
alternativeMethods: t.alternative_methods
|
|
5531
|
+
alternativeMethods: t.alternative_methods ?? []
|
|
5415
5532
|
}), t;
|
|
5416
5533
|
} catch (e) {
|
|
5417
5534
|
this.emitErrorAndThrow(e, "2fa.challenge.request", "Request 2FA challenge");
|
|
@@ -5419,13 +5536,11 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5419
5536
|
}
|
|
5420
5537
|
async verifyV2(e) {
|
|
5421
5538
|
try {
|
|
5422
|
-
let t = await this.twoFactorApi.verifyV2(e, this.pendingTfaToken());
|
|
5423
|
-
if (!t.success) return t;
|
|
5424
|
-
let n = await this.finishSignIn(t);
|
|
5539
|
+
let t = await this.twoFactorApi.verifyV2(e, this.pendingTfaToken()), n = await this.finishSignIn(t);
|
|
5425
5540
|
return this.subscribeStore.notify(Z.TwoFactorVerified, { tokens: {
|
|
5426
5541
|
access_token: n.access_token,
|
|
5427
5542
|
refresh_token: n.refresh_token
|
|
5428
|
-
} }),
|
|
5543
|
+
} }), await this.signInCompleter?.notifySignedIn(n), n;
|
|
5429
5544
|
} catch (e) {
|
|
5430
5545
|
this.emitErrorAndThrow(e, "2fa.challenge.verify", "Verify 2FA challenge");
|
|
5431
5546
|
}
|
|
@@ -5433,10 +5548,10 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5433
5548
|
async switchToAlternative(e) {
|
|
5434
5549
|
try {
|
|
5435
5550
|
let t = await this.twoFactorApi.switchToAlternative(e, this.pendingTfaToken());
|
|
5436
|
-
return this.subscribeStore.notify(Z.TwoFactorMethodSwitched, {
|
|
5551
|
+
return this.storeTotpDigits(t.totp_digits), this.subscribeStore.notify(Z.TwoFactorMethodSwitched, {
|
|
5437
5552
|
challengeId: t.challenge_id,
|
|
5438
5553
|
method: t.method,
|
|
5439
|
-
alternativeMethods: t.alternative_methods
|
|
5554
|
+
alternativeMethods: t.alternative_methods ?? []
|
|
5440
5555
|
}), t;
|
|
5441
5556
|
} catch (e) {
|
|
5442
5557
|
this.emitErrorAndThrow(e, "2fa.method.switch", "Switch to alternative 2FA method");
|
|
@@ -5456,7 +5571,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5456
5571
|
this.emitErrorAndThrow(e, "2fa.trusted-devices.revoke", "Revoke trusted device");
|
|
5457
5572
|
}
|
|
5458
5573
|
}
|
|
5459
|
-
},
|
|
5574
|
+
}, ki = class {
|
|
5460
5575
|
constructor(e, t, n = ae) {
|
|
5461
5576
|
this.userAPI = e, this.deviceService = t, this.platform = n;
|
|
5462
5577
|
}
|
|
@@ -5471,7 +5586,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5471
5586
|
}
|
|
5472
5587
|
async addUserPasskey({ relyingPartyId: e, passkeyUsername: t, passkeyDisplayName: n } = {}) {
|
|
5473
5588
|
if (!this.platform.passkeys) throw Error("Passkeys are not supported on this platform");
|
|
5474
|
-
let r = this.deviceService.getDeviceId(), i =
|
|
5589
|
+
let r = this.deviceService.getDeviceId(), i = Ve(this.platform.getDeviceType()), { challenge_id: a, publicKey: o } = await this.userAPI.addUserPasskeyStart({
|
|
5475
5590
|
relyingPartyId: (e || this.platform.getCurrentUrl()?.hostname) ?? "",
|
|
5476
5591
|
deviceId: r,
|
|
5477
5592
|
os: i,
|
|
@@ -5483,69 +5598,77 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5483
5598
|
if (!s) throw Error("Passkey registration was not completed");
|
|
5484
5599
|
return await this.userAPI.addUserPasskeyComplete(s, r, a);
|
|
5485
5600
|
}
|
|
5486
|
-
},
|
|
5601
|
+
}, Ai = class extends Error {
|
|
5487
5602
|
constructor(e, t, n = !1) {
|
|
5488
5603
|
super(t), this.name = "UpgradeFactorError", this.factor = e, this.cancelled = n;
|
|
5489
5604
|
}
|
|
5490
|
-
},
|
|
5605
|
+
}, ji = (e, t) => {
|
|
5491
5606
|
let n = t?.trim();
|
|
5492
|
-
if (!n) throw new
|
|
5607
|
+
if (!n) throw new Ai(e, "A verification code is required");
|
|
5493
5608
|
return n;
|
|
5494
|
-
},
|
|
5609
|
+
}, Mi = {
|
|
5495
5610
|
type: "totp",
|
|
5496
5611
|
requiresPrepare: !1,
|
|
5497
5612
|
input: "code",
|
|
5498
|
-
assert: async ({ code: e }) => ({ code:
|
|
5499
|
-
},
|
|
5613
|
+
assert: async ({ code: e }) => ({ code: ji("totp", e) })
|
|
5614
|
+
}, Ni = {
|
|
5500
5615
|
type: "recovery_codes",
|
|
5501
5616
|
requiresPrepare: !1,
|
|
5502
5617
|
input: "code",
|
|
5503
|
-
assert: async ({ code: e }) => ({ code:
|
|
5504
|
-
},
|
|
5618
|
+
assert: async ({ code: e }) => ({ code: ji("recovery_codes", e) })
|
|
5619
|
+
}, Pi = {
|
|
5505
5620
|
type: "passkey",
|
|
5506
5621
|
requiresPrepare: !0,
|
|
5507
5622
|
input: "none",
|
|
5508
5623
|
assert: async ({ prepared: e, platform: t }) => {
|
|
5509
|
-
if (!e?.webauthn) throw new
|
|
5624
|
+
if (!e?.webauthn) throw new Ai("passkey", "The upgrade challenge carried no WebAuthn options");
|
|
5510
5625
|
let n = t.passkeys;
|
|
5511
|
-
if (!n) throw new
|
|
5626
|
+
if (!n) throw new Ai("passkey", "This platform does not support passkeys");
|
|
5512
5627
|
let r;
|
|
5513
5628
|
try {
|
|
5514
5629
|
r = await n.startAuthentication(e.webauthn);
|
|
5515
5630
|
} catch (e) {
|
|
5516
|
-
throw new
|
|
5631
|
+
throw new Ai("passkey", e?.message || "Passkey verification was cancelled", !0);
|
|
5517
5632
|
}
|
|
5518
|
-
if (!r) throw new
|
|
5633
|
+
if (!r) throw new Ai("passkey", "Passkey verification was cancelled", !0);
|
|
5519
5634
|
return {
|
|
5520
5635
|
challenge_id: e.challengeId,
|
|
5521
5636
|
credential: r
|
|
5522
5637
|
};
|
|
5523
5638
|
}
|
|
5524
|
-
},
|
|
5525
|
-
|
|
5526
|
-
|
|
5527
|
-
|
|
5528
|
-
]),
|
|
5529
|
-
|
|
5530
|
-
|
|
5639
|
+
}, Fi = Object.freeze([
|
|
5640
|
+
Mi,
|
|
5641
|
+
Pi,
|
|
5642
|
+
Ni
|
|
5643
|
+
]), Ii = (e = Fi) => new Map(e.map((e) => [e.type, e])), Li = 3, Ri = {
|
|
5644
|
+
totp: 0,
|
|
5645
|
+
passkey: 1,
|
|
5531
5646
|
email_otp: 2,
|
|
5532
5647
|
sms_otp: 3,
|
|
5533
5648
|
recovery_codes: 9
|
|
5534
|
-
},
|
|
5535
|
-
let n =
|
|
5649
|
+
}, zi = (e) => e.requiredLevel ?? ce(e.acrValues), Bi = (e, t) => {
|
|
5650
|
+
let n = Ri[e.type] ?? 5, r = t !== void 0 && t >= Li, i = e.type === "passkey";
|
|
5536
5651
|
return (r && !i ? 100 : 0) + n;
|
|
5537
|
-
},
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
|
|
5652
|
+
}, Vi = (e, t) => {
|
|
5653
|
+
if (t.availableFactors) return t.availableFactors.flatMap((t) => e.find((e) => e.type === t) ?? []);
|
|
5654
|
+
let n = zi(t);
|
|
5655
|
+
return [...e].sort((e, t) => Bi(e, n) - Bi(t, n));
|
|
5656
|
+
}, Hi = class extends Error {
|
|
5541
5657
|
constructor(e) {
|
|
5542
5658
|
super("Upgrade authentication was cancelled"), this.code = "upgrade_cancelled", this.name = "UpgradeCancelledError", e !== void 0 && (this.cause = e);
|
|
5543
5659
|
}
|
|
5544
|
-
},
|
|
5660
|
+
}, Ui = class extends Error {
|
|
5661
|
+
constructor(e = "Only a fresh sign-in can meet this challenge") {
|
|
5662
|
+
super(e), this.code = "upgrade_sign_in_required", this.name = "UpgradeSignInRequiredError";
|
|
5663
|
+
}
|
|
5664
|
+
}, Wi = (e) => e?.signInRequired === !0 || e?.signInRequired === void 0 && e?.availableFactors?.length === 0, Gi = (e) => e?.signInRequired === !1 && e.availableFactors?.length === 0, Ki = "This account has no factor that reaches the required level (it may need a device-bound passkey)", qi = (e) => {
|
|
5665
|
+
if (Wi(e)) return new Ui();
|
|
5666
|
+
if (Gi(e)) return new Ji(Ki);
|
|
5667
|
+
}, Ji = class extends Error {
|
|
5545
5668
|
constructor(e = "No available authentication factor can satisfy this challenge") {
|
|
5546
5669
|
super(e), this.code = "upgrade_unsatisfiable", this.name = "UpgradeUnsatisfiableError";
|
|
5547
5670
|
}
|
|
5548
|
-
},
|
|
5671
|
+
}, Yi = 4, Xi = 3e4, Zi = () => {
|
|
5549
5672
|
let e = () => void 0, t = () => void 0;
|
|
5550
5673
|
return {
|
|
5551
5674
|
promise: new Promise((n, r) => {
|
|
@@ -5554,25 +5677,27 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5554
5677
|
resolve: e,
|
|
5555
5678
|
reject: t
|
|
5556
5679
|
};
|
|
5557
|
-
},
|
|
5680
|
+
}, Qi = (e) => ({
|
|
5558
5681
|
acrValues: e.acrValues,
|
|
5559
5682
|
level: e.requiredLevel,
|
|
5560
5683
|
maxAge: e.maxAge
|
|
5561
|
-
}),
|
|
5562
|
-
let n = e.requiredLevel === void 0 ? t.requiredLevel : t.requiredLevel === void 0 ? e.requiredLevel : Math.max(e.requiredLevel, t.requiredLevel), r = n === void 0 ? e.acrValues ?? t.acrValues : n === e.requiredLevel ? e.acrValues : t.acrValues, i = e.maxAge === void 0 ? t.maxAge : t.maxAge === void 0 ? e.maxAge : Math.min(e.maxAge, t.maxAge), a = Array.from(/* @__PURE__ */ new Set([...e.channels ?? [], ...t.channels ?? []]));
|
|
5684
|
+
}), $i = (e, t) => t.level === void 0 || e.level !== void 0 && e.level >= t.level, ea = (e, t) => {
|
|
5685
|
+
let n = e.requiredLevel === void 0 ? t.requiredLevel : t.requiredLevel === void 0 ? e.requiredLevel : Math.max(e.requiredLevel, t.requiredLevel), r = n === void 0 ? e.acrValues ?? t.acrValues : n === e.requiredLevel ? e.acrValues : t.acrValues, i = e.maxAge === void 0 ? t.maxAge : t.maxAge === void 0 ? e.maxAge : Math.min(e.maxAge, t.maxAge), a = Array.from(/* @__PURE__ */ new Set([...e.channels ?? [], ...t.channels ?? []])), { availableFactors: o, signInRequired: s } = ta(t, e) && !ta(e, t) || !t.availableFactors ? e : t;
|
|
5563
5686
|
return {
|
|
5564
5687
|
acrValues: r,
|
|
5565
5688
|
requiredLevel: n,
|
|
5566
5689
|
maxAge: i,
|
|
5567
5690
|
status: e.status,
|
|
5568
|
-
...a.length > 0 ? { channels: a } : {}
|
|
5691
|
+
...a.length > 0 ? { channels: a } : {},
|
|
5692
|
+
...o ? { availableFactors: o } : {},
|
|
5693
|
+
...s === void 0 ? {} : { signInRequired: s }
|
|
5569
5694
|
};
|
|
5570
|
-
},
|
|
5695
|
+
}, ta = (e, t) => {
|
|
5571
5696
|
let n = t.requiredLevel !== void 0 && (e.requiredLevel === void 0 || t.requiredLevel > e.requiredLevel), r = t.maxAge !== void 0 && (e.maxAge === void 0 || t.maxAge < e.maxAge);
|
|
5572
5697
|
return n || r;
|
|
5573
|
-
},
|
|
5698
|
+
}, na = class {
|
|
5574
5699
|
constructor(e) {
|
|
5575
|
-
this.state = "idle", this.inFlight = null, this.requirement = null, this.selected = null, this.rankedRequirement = null, this.registrations = [], this.proof = null, this.pruned = /* @__PURE__ */ new Set(), this.openPrompt = null, this.transport = e.transport, this.prompt = e.prompt, this.platform = e.platform, this.available = e.factors ??
|
|
5700
|
+
this.state = "idle", this.inFlight = null, this.requirement = null, this.selected = null, this.rankedRequirement = null, this.registrations = [], this.proof = null, this.pruned = /* @__PURE__ */ new Set(), this.openPrompt = null, this.transport = e.transport, this.prompt = e.prompt, this.platform = e.platform, this.available = e.factors ?? Fi, this.registry = Ii(this.available), this.maxAttempts = e.maxAttempts ?? Yi, this.readObtainedBar = e.readObtainedBar, this.onFlightSettled = e.onFlightSettled, this.settleTimeoutMs = e.replaySettleTimeoutMs ?? Xi;
|
|
5576
5701
|
}
|
|
5577
5702
|
get currentState() {
|
|
5578
5703
|
return this.state;
|
|
@@ -5592,9 +5717,9 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5592
5717
|
}
|
|
5593
5718
|
register(e, t) {
|
|
5594
5719
|
let n = t.kind === "imperative" && t.requested !== void 0, r = {
|
|
5595
|
-
demanded: t.kind === "imperative" && t.requested ? t.requested :
|
|
5720
|
+
demanded: t.kind === "imperative" && t.requested ? t.requested : Qi(e),
|
|
5596
5721
|
statedBar: n,
|
|
5597
|
-
settlement:
|
|
5722
|
+
settlement: Zi(),
|
|
5598
5723
|
reported: !1,
|
|
5599
5724
|
entry: {
|
|
5600
5725
|
...t,
|
|
@@ -5610,15 +5735,15 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5610
5735
|
this.requirement = e;
|
|
5611
5736
|
return;
|
|
5612
5737
|
}
|
|
5613
|
-
let n =
|
|
5614
|
-
this.requirement =
|
|
5738
|
+
let n = ta(t, e);
|
|
5739
|
+
this.requirement = ea(t, e), qi(this.requirement) ? this.state === "collecting" && this.selected === null && (this.openPrompt?.onClosed?.(), this.closeOpenPrompt?.()) : n && this.state === "collecting" && this.selected === null && this.openPrompt?.onRequirementRaised?.({
|
|
5615
5740
|
challenge: this.requirement,
|
|
5616
5741
|
factors: this.offeredFactors()
|
|
5617
5742
|
});
|
|
5618
5743
|
}
|
|
5619
5744
|
offeredFactors() {
|
|
5620
5745
|
let e = this.available.filter((e) => !this.pruned.has(e.type)), t = this.requirement;
|
|
5621
|
-
return t ?
|
|
5746
|
+
return t ? Vi(e, t) : e;
|
|
5622
5747
|
}
|
|
5623
5748
|
receiveReport(e, t) {
|
|
5624
5749
|
e.reported || (e.reported = !0, e.entry.outcome = t.outcome, t.obtained && (e.entry.obtained = t.obtained), t.required && (e.entry.required = t.required), this.notifyReportsSettled());
|
|
@@ -5653,12 +5778,12 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5653
5778
|
}
|
|
5654
5779
|
release(e, t) {
|
|
5655
5780
|
if (e.entry.kind === "imperative") {
|
|
5656
|
-
if (e.statedBar &&
|
|
5781
|
+
if (e.statedBar && !$i(t, e.demanded)) {
|
|
5657
5782
|
this.receiveReport(e, {
|
|
5658
5783
|
outcome: "insufficient",
|
|
5659
5784
|
obtained: t,
|
|
5660
5785
|
required: e.demanded
|
|
5661
|
-
}), e.settlement.reject(new
|
|
5786
|
+
}), e.settlement.reject(new $r(t, e.demanded));
|
|
5662
5787
|
return;
|
|
5663
5788
|
}
|
|
5664
5789
|
this.receiveReport(e, {
|
|
@@ -5728,42 +5853,52 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5728
5853
|
async prove() {
|
|
5729
5854
|
let e;
|
|
5730
5855
|
for (let t = 0; t < this.maxAttempts; t++) {
|
|
5731
|
-
let t = this.
|
|
5732
|
-
if (t
|
|
5856
|
+
let t = qi(this.requirement);
|
|
5857
|
+
if (t) return {
|
|
5858
|
+
status: "failed",
|
|
5859
|
+
reason: t
|
|
5860
|
+
};
|
|
5861
|
+
let n = this.offeredFactors();
|
|
5862
|
+
if (n.length === 0) return {
|
|
5733
5863
|
status: "failed",
|
|
5734
|
-
reason: new
|
|
5864
|
+
reason: new Ji()
|
|
5735
5865
|
};
|
|
5736
|
-
let
|
|
5866
|
+
let r = this.requirement, i;
|
|
5737
5867
|
try {
|
|
5738
|
-
|
|
5868
|
+
i = await this.collect(r, n, e);
|
|
5739
5869
|
} catch (e) {
|
|
5740
5870
|
return {
|
|
5741
5871
|
status: "failed",
|
|
5742
|
-
reason: new
|
|
5872
|
+
reason: new Hi(e)
|
|
5743
5873
|
};
|
|
5744
5874
|
}
|
|
5745
|
-
|
|
5875
|
+
let a = qi(this.requirement);
|
|
5876
|
+
if (a) return {
|
|
5746
5877
|
status: "failed",
|
|
5747
|
-
reason:
|
|
5878
|
+
reason: a
|
|
5748
5879
|
};
|
|
5749
|
-
|
|
5750
|
-
|
|
5880
|
+
if (i.type === "cancel") return {
|
|
5881
|
+
status: "failed",
|
|
5882
|
+
reason: new Hi()
|
|
5883
|
+
};
|
|
5884
|
+
let o = this.registry.get(i.factor);
|
|
5885
|
+
if (!o) e = new Ji(`Unknown authentication factor: ${i.factor}`), this.state = "collecting", this.selected = null;
|
|
5751
5886
|
else try {
|
|
5752
|
-
return await this.proveAndCommit(
|
|
5887
|
+
return await this.proveAndCommit(o, i.code), {
|
|
5753
5888
|
status: "proven",
|
|
5754
|
-
obtained: this.readObtainedBar?.() ??
|
|
5889
|
+
obtained: this.readObtainedBar?.() ?? Qi(this.rankedRequirement ?? r)
|
|
5755
5890
|
};
|
|
5756
5891
|
} catch (t) {
|
|
5757
|
-
if (t instanceof
|
|
5892
|
+
if (t instanceof Ai && t.cancelled) return {
|
|
5758
5893
|
status: "failed",
|
|
5759
|
-
reason: new
|
|
5894
|
+
reason: new Hi()
|
|
5760
5895
|
};
|
|
5761
5896
|
let n = this.classifyProofFailure(t);
|
|
5762
5897
|
if (n) return {
|
|
5763
5898
|
status: "failed",
|
|
5764
5899
|
reason: n
|
|
5765
5900
|
};
|
|
5766
|
-
t instanceof $ && t.kind === "not_registered" && this.pruned.add(
|
|
5901
|
+
t instanceof $ && t.kind === "not_registered" && this.pruned.add(o.type), e = t, this.state = "collecting", this.selected = null;
|
|
5767
5902
|
}
|
|
5768
5903
|
}
|
|
5769
5904
|
return {
|
|
@@ -5783,18 +5918,25 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5783
5918
|
this.state === "collecting" && (this.state = "proving"), this.selected = e, this.rankedRequirement = this.requirement;
|
|
5784
5919
|
}
|
|
5785
5920
|
};
|
|
5786
|
-
|
|
5921
|
+
this.openPrompt = r;
|
|
5922
|
+
let i = new Promise((e) => {
|
|
5923
|
+
this.closeOpenPrompt = () => e({ type: "cancel" });
|
|
5924
|
+
});
|
|
5925
|
+
return Promise.race([this.prompt(r), i]).finally(() => {
|
|
5926
|
+
this.closeOpenPrompt = void 0;
|
|
5927
|
+
});
|
|
5787
5928
|
}
|
|
5788
5929
|
classifyProofFailure(e) {
|
|
5789
|
-
if (e instanceof
|
|
5930
|
+
if (e instanceof $r || e instanceof ei || e instanceof ti) return e;
|
|
5790
5931
|
if (e instanceof $) switch (e.kind) {
|
|
5791
|
-
case "unavailable": return new
|
|
5932
|
+
case "unavailable": return new ei(e.message);
|
|
5792
5933
|
case "exhausted":
|
|
5793
5934
|
case "attempts_exhausted":
|
|
5935
|
+
case "rate_limited":
|
|
5794
5936
|
case "fatal":
|
|
5795
5937
|
case "protocol":
|
|
5796
5938
|
case "network": return e;
|
|
5797
|
-
case "session_changed": return new
|
|
5939
|
+
case "session_changed": return new ti(e.message);
|
|
5798
5940
|
default: return;
|
|
5799
5941
|
}
|
|
5800
5942
|
}
|
|
@@ -5806,28 +5948,28 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5806
5948
|
});
|
|
5807
5949
|
await this.transport.commit(e.type, r);
|
|
5808
5950
|
}
|
|
5809
|
-
},
|
|
5951
|
+
}, ra = (e) => typeof e == "function" ? e() : e, ia = (e) => {
|
|
5810
5952
|
try {
|
|
5811
5953
|
return new URL(e);
|
|
5812
5954
|
} catch {
|
|
5813
5955
|
return;
|
|
5814
5956
|
}
|
|
5815
|
-
},
|
|
5957
|
+
}, aa = (e, t) => {
|
|
5816
5958
|
if (!t || t === "/") return !0;
|
|
5817
5959
|
let n = t.replace(/\/+$/, "");
|
|
5818
5960
|
return e === n || e.startsWith(`${n}/`);
|
|
5819
|
-
},
|
|
5961
|
+
}, oa = (e, t) => !t || e.origin === void 0 ? !1 : e.origin === t.origin && aa(e.pathname, t.pathPrefix), sa = (e, t) => {
|
|
5820
5962
|
for (let n of t) {
|
|
5821
5963
|
if (n === "") continue;
|
|
5822
5964
|
if (n.startsWith("/")) {
|
|
5823
|
-
if (e.relativeToBase &&
|
|
5965
|
+
if (e.relativeToBase && aa(e.pathname, n)) return !0;
|
|
5824
5966
|
continue;
|
|
5825
5967
|
}
|
|
5826
|
-
let t =
|
|
5827
|
-
if (t && e.origin !== void 0 && e.origin === t.origin &&
|
|
5968
|
+
let t = ia(n) ?? ia(`https://${n}`);
|
|
5969
|
+
if (t && e.origin !== void 0 && e.origin === t.origin && aa(e.pathname, t.pathname)) return !0;
|
|
5828
5970
|
}
|
|
5829
5971
|
return !1;
|
|
5830
|
-
},
|
|
5972
|
+
}, ca = (e, t, n) => oa(e, t.passflow) || sa(e, t.backend) ? !n || n(e.href) !== !1 : !1, la = (e) => {
|
|
5831
5973
|
let t = e.detail, n = t?.message ?? `[passflow] upgrade challenge not actioned: ${e.reason}`;
|
|
5832
5974
|
console.warn(n, {
|
|
5833
5975
|
status: e.status,
|
|
@@ -5835,8 +5977,8 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5835
5977
|
reason: e.reason,
|
|
5836
5978
|
detail: t
|
|
5837
5979
|
});
|
|
5838
|
-
},
|
|
5839
|
-
let n = t.onUpgradeDiagnostic ??
|
|
5980
|
+
}, ua = (e, t) => {
|
|
5981
|
+
let n = t.onUpgradeDiagnostic ?? la;
|
|
5840
5982
|
return (t, r) => {
|
|
5841
5983
|
n({
|
|
5842
5984
|
status: e.status,
|
|
@@ -5848,8 +5990,8 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5848
5990
|
}
|
|
5849
5991
|
});
|
|
5850
5992
|
};
|
|
5851
|
-
},
|
|
5852
|
-
let r = n.onUpgradeDiagnostic ??
|
|
5993
|
+
}, da = (e, t, n) => {
|
|
5994
|
+
let r = n.onUpgradeDiagnostic ?? la;
|
|
5853
5995
|
for (let n of e) r({
|
|
5854
5996
|
...n,
|
|
5855
5997
|
url: t.request.href,
|
|
@@ -5858,8 +6000,8 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5858
6000
|
...n.detail ?? {}
|
|
5859
6001
|
}
|
|
5860
6002
|
});
|
|
5861
|
-
},
|
|
5862
|
-
let n = t.requireChallengeChannel === "header", r = e.getHeader("content-type") ?? "", i = !n &&
|
|
6003
|
+
}, fa = /\bjson\b/i, pa = async (e, t) => {
|
|
6004
|
+
let n = t.requireChallengeChannel === "header", r = e.getHeader("content-type") ?? "", i = !n && fa.test(r), a;
|
|
5863
6005
|
if (i) try {
|
|
5864
6006
|
a = await e.readBody();
|
|
5865
6007
|
} catch {
|
|
@@ -5873,14 +6015,17 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5873
6015
|
status: e.status,
|
|
5874
6016
|
getHeader: (t) => e.getHeader(t) ?? void 0
|
|
5875
6017
|
}, { requireChallengeChannel: t.requireChallengeChannel });
|
|
5876
|
-
},
|
|
6018
|
+
}, ma = (e) => ye({
|
|
5877
6019
|
status: e.status,
|
|
5878
6020
|
getHeader: (t) => e.getHeader(t) ?? void 0
|
|
5879
|
-
}, { requireChallengeChannel: "header" }).challenge,
|
|
6021
|
+
}, { requireChallengeChannel: "header" }).challenge, ha = (e, t) => t.passflow === null ? `[passflow] a 401/403 from ${e} carried an upgrade challenge, but no Passflow endpoint is configured — set \`url\` on the Passflow config.` : `[passflow] a 401/403 from ${e} carried an upgrade challenge, but that URL is not covered by the provider's \`backend\` prop — add it there to enable step-up for this API.`, ga = (e, t) => e instanceof Hi ? { kind: "cancelled" } : e instanceof Ui ? { kind: "sign-in-required" } : e instanceof Ji ? {
|
|
6022
|
+
kind: "unsatisfiable",
|
|
6023
|
+
error: e
|
|
6024
|
+
} : e instanceof ei ? { kind: "unavailable" } : e instanceof ti ? { kind: "session-changed" } : e instanceof $r ? {
|
|
5880
6025
|
kind: "insufficient",
|
|
5881
6026
|
obtained: e.obtained,
|
|
5882
6027
|
required: e.required
|
|
5883
|
-
} : e instanceof $ ? e.kind === "exhausted" || e.kind === "attempts_exhausted" ? {
|
|
6028
|
+
} : e instanceof $ ? e.kind === "exhausted" || e.kind === "attempts_exhausted" || e.kind === "rate_limited" ? {
|
|
5884
6029
|
kind: "exhausted",
|
|
5885
6030
|
error: e
|
|
5886
6031
|
} : e.kind === "unavailable" ? { kind: "unavailable" } : e.kind === "session_changed" ? { kind: "session-changed" } : {
|
|
@@ -5892,17 +6037,26 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5892
6037
|
kind: "transport-failure",
|
|
5893
6038
|
retryable: !1,
|
|
5894
6039
|
error: e instanceof Error ? e : Error(String(e))
|
|
5895
|
-
},
|
|
6040
|
+
}, _a = async (e, t, n, r) => {
|
|
5896
6041
|
if (e.status !== 401 && e.status !== 403) return {
|
|
5897
6042
|
kind: "replayed",
|
|
5898
6043
|
response: e
|
|
5899
6044
|
};
|
|
5900
|
-
let { challenge: i, diagnostics: a } = await
|
|
5901
|
-
if (
|
|
6045
|
+
let { challenge: i, diagnostics: a } = await pa(e, t);
|
|
6046
|
+
if (da(a, e, t), !i) return {
|
|
5902
6047
|
kind: "replayed",
|
|
5903
6048
|
response: e
|
|
5904
6049
|
};
|
|
5905
|
-
|
|
6050
|
+
if (Wi(i)) return {
|
|
6051
|
+
kind: "sign-in-required",
|
|
6052
|
+
response: e
|
|
6053
|
+
};
|
|
6054
|
+
if (Gi(i)) return {
|
|
6055
|
+
kind: "unsatisfiable",
|
|
6056
|
+
error: qi(i),
|
|
6057
|
+
response: e
|
|
6058
|
+
};
|
|
6059
|
+
let o = Qi(i);
|
|
5906
6060
|
return r("elevated-insufficient", {
|
|
5907
6061
|
obtained: n,
|
|
5908
6062
|
required: o
|
|
@@ -5912,7 +6066,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5912
6066
|
required: o,
|
|
5913
6067
|
response: e
|
|
5914
6068
|
};
|
|
5915
|
-
},
|
|
6069
|
+
}, va = async (e, t) => {
|
|
5916
6070
|
if (!t) return {
|
|
5917
6071
|
aborted: !1,
|
|
5918
6072
|
value: await e
|
|
@@ -5939,14 +6093,14 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5939
6093
|
} finally {
|
|
5940
6094
|
n && t.removeEventListener?.("abort", n);
|
|
5941
6095
|
}
|
|
5942
|
-
},
|
|
6096
|
+
}, ya = async (e, t) => {
|
|
5943
6097
|
if (e.status !== 401 && e.status !== 403 || e.markers.upgradeTransaction) return { kind: "not-a-challenge" };
|
|
5944
|
-
let n =
|
|
6098
|
+
let n = ua(e, t);
|
|
5945
6099
|
if (e.markers.replayed) {
|
|
5946
|
-
if (
|
|
5947
|
-
let { challenge: r, diagnostics: i } = await
|
|
5948
|
-
if (
|
|
5949
|
-
let a = t.readObtainedBar?.() ?? {}, o =
|
|
6100
|
+
if (!ca(e.request, t.scope, t.shouldIntercept)) return { kind: "not-a-challenge" };
|
|
6101
|
+
let { challenge: r, diagnostics: i } = await pa(e, t);
|
|
6102
|
+
if (da(i, e, t), !r) return { kind: "not-a-challenge" };
|
|
6103
|
+
let a = t.readObtainedBar?.() ?? {}, o = Qi(r);
|
|
5950
6104
|
return n("elevated-insufficient", {
|
|
5951
6105
|
obtained: a,
|
|
5952
6106
|
required: o
|
|
@@ -5957,12 +6111,12 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5957
6111
|
response: e
|
|
5958
6112
|
};
|
|
5959
6113
|
}
|
|
5960
|
-
if (
|
|
6114
|
+
if (!ca(e.request, t.scope, t.shouldIntercept)) return ma(e) ? (n("challenge-out-of-scope", {
|
|
5961
6115
|
header: e.getHeader("www-authenticate") ?? void 0,
|
|
5962
|
-
message:
|
|
6116
|
+
message: ha(e.request.href, t.scope)
|
|
5963
6117
|
}), { kind: "out-of-scope" }) : { kind: "not-a-challenge" };
|
|
5964
|
-
let { challenge: r, diagnostics: i } = await
|
|
5965
|
-
if (
|
|
6118
|
+
let { challenge: r, diagnostics: i } = await pa(e, t);
|
|
6119
|
+
if (da(i, e, t), !r) {
|
|
5966
6120
|
let r = e.getHeader("www-authenticate");
|
|
5967
6121
|
return t.requireChallengeChannel !== "header" && n("no-channel", {
|
|
5968
6122
|
...r ? { header: r } : {},
|
|
@@ -5976,9 +6130,9 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5976
6130
|
method: e.request.method
|
|
5977
6131
|
}, s, c;
|
|
5978
6132
|
try {
|
|
5979
|
-
s = Promise.resolve(t.elevate(r, o)), c = await
|
|
6133
|
+
s = Promise.resolve(t.elevate(r, o)), c = await va(s, e.signal);
|
|
5980
6134
|
} catch (e) {
|
|
5981
|
-
return
|
|
6135
|
+
return ga(e, void 0);
|
|
5982
6136
|
}
|
|
5983
6137
|
if (c.aborted) return s?.then((e) => e?.waiter.report({ outcome: "failed" }), () => {}), {
|
|
5984
6138
|
kind: "aborted",
|
|
@@ -5989,7 +6143,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5989
6143
|
kind: "aborted",
|
|
5990
6144
|
reason: e.signal.reason
|
|
5991
6145
|
};
|
|
5992
|
-
let u = l?.obtained ?? t.readObtainedBar?.() ??
|
|
6146
|
+
let u = l?.obtained ?? t.readObtainedBar?.() ?? Qi(r), d = t.authorizationSwap?.(), f = d ? {
|
|
5993
6147
|
from: a?.from ?? d.from,
|
|
5994
6148
|
to: d.to
|
|
5995
6149
|
} : void 0;
|
|
@@ -5998,7 +6152,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
5998
6152
|
try {
|
|
5999
6153
|
p = await e.replay(f ? { authorizationSwap: f } : void 0);
|
|
6000
6154
|
} catch (t) {
|
|
6001
|
-
if (t instanceof
|
|
6155
|
+
if (t instanceof $r) return l?.waiter.report({
|
|
6002
6156
|
outcome: "insufficient",
|
|
6003
6157
|
obtained: t.obtained,
|
|
6004
6158
|
required: t.required
|
|
@@ -6016,7 +6170,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6016
6170
|
};
|
|
6017
6171
|
throw t;
|
|
6018
6172
|
}
|
|
6019
|
-
let m = await
|
|
6173
|
+
let m = await _a(p, t, u, n);
|
|
6020
6174
|
return m.kind === "insufficient" ? l?.waiter.report({
|
|
6021
6175
|
outcome: "insufficient",
|
|
6022
6176
|
obtained: m.obtained,
|
|
@@ -6025,18 +6179,19 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6025
6179
|
outcome: "replayed",
|
|
6026
6180
|
obtained: u
|
|
6027
6181
|
}), m;
|
|
6028
|
-
},
|
|
6182
|
+
}, ba = (e) => {
|
|
6029
6183
|
switch (e.kind) {
|
|
6030
|
-
case "cancelled": return new
|
|
6031
|
-
case "unsatisfiable": return new
|
|
6032
|
-
case "
|
|
6033
|
-
case "
|
|
6034
|
-
case "
|
|
6184
|
+
case "cancelled": return new Hi();
|
|
6185
|
+
case "unsatisfiable": return e.error ?? new Ji();
|
|
6186
|
+
case "sign-in-required": return new Ui();
|
|
6187
|
+
case "unavailable": return new ei();
|
|
6188
|
+
case "session-changed": return new ti();
|
|
6189
|
+
case "insufficient": return new $r(e.obtained, e.required);
|
|
6035
6190
|
case "exhausted": return e.error;
|
|
6036
6191
|
case "transport-failure": return e.error;
|
|
6037
6192
|
default: return;
|
|
6038
6193
|
}
|
|
6039
|
-
},
|
|
6194
|
+
}, xa = (e, t, n) => {
|
|
6040
6195
|
switch (e.kind) {
|
|
6041
6196
|
case "replayed": return {
|
|
6042
6197
|
settle: "resolve",
|
|
@@ -6054,21 +6209,26 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6054
6209
|
};
|
|
6055
6210
|
case "cancelled": return n.onCancel === "reject" ? {
|
|
6056
6211
|
settle: "reject",
|
|
6057
|
-
error: new
|
|
6212
|
+
error: new Hi()
|
|
6058
6213
|
} : {
|
|
6059
6214
|
settle: "resolve",
|
|
6060
|
-
value:
|
|
6215
|
+
value: ja(t, e)
|
|
6216
|
+
};
|
|
6217
|
+
case "unsatisfiable":
|
|
6218
|
+
case "sign-in-required": return {
|
|
6219
|
+
settle: "resolve",
|
|
6220
|
+
value: ja(e.response?.raw ?? t, e)
|
|
6061
6221
|
};
|
|
6062
6222
|
case "insufficient": return {
|
|
6063
6223
|
settle: "resolve",
|
|
6064
|
-
value:
|
|
6224
|
+
value: ja(e.response?.raw ?? t, e)
|
|
6065
6225
|
};
|
|
6066
6226
|
default: return {
|
|
6067
6227
|
settle: "resolve",
|
|
6068
|
-
value:
|
|
6228
|
+
value: ja(t, e)
|
|
6069
6229
|
};
|
|
6070
6230
|
}
|
|
6071
|
-
},
|
|
6231
|
+
}, Sa = (e, t) => {
|
|
6072
6232
|
switch (e.kind) {
|
|
6073
6233
|
case "replayed": return e.response.rejected ? {
|
|
6074
6234
|
settle: "reject",
|
|
@@ -6083,39 +6243,42 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6083
6243
|
};
|
|
6084
6244
|
default: return {
|
|
6085
6245
|
settle: "reject",
|
|
6086
|
-
error:
|
|
6246
|
+
error: ba(e) ?? t
|
|
6087
6247
|
};
|
|
6088
6248
|
}
|
|
6089
|
-
},
|
|
6249
|
+
}, Ca = /* @__PURE__ */ new WeakSet(), wa = /* @__PURE__ */ new WeakSet(), Ta = /* @__PURE__ */ new WeakSet(), Ea = /* @__PURE__ */ new WeakSet(), Da = /* @__PURE__ */ new WeakSet(), Oa = /* @__PURE__ */ new WeakSet(), ka = /* @__PURE__ */ new WeakSet(), Aa = /* @__PURE__ */ new WeakSet(), ja = (e, t) => {
|
|
6090
6250
|
switch (t.kind) {
|
|
6091
6251
|
case "cancelled":
|
|
6092
|
-
|
|
6252
|
+
Ca.add(e);
|
|
6093
6253
|
break;
|
|
6094
6254
|
case "exhausted":
|
|
6095
|
-
|
|
6255
|
+
wa.add(e);
|
|
6096
6256
|
break;
|
|
6097
6257
|
case "insufficient":
|
|
6098
|
-
|
|
6258
|
+
Ta.add(e);
|
|
6099
6259
|
break;
|
|
6100
6260
|
case "unsatisfiable":
|
|
6101
|
-
|
|
6261
|
+
Ea.add(e);
|
|
6262
|
+
break;
|
|
6263
|
+
case "sign-in-required":
|
|
6264
|
+
Da.add(e);
|
|
6102
6265
|
break;
|
|
6103
6266
|
case "unavailable":
|
|
6104
|
-
|
|
6267
|
+
Oa.add(e);
|
|
6105
6268
|
break;
|
|
6106
6269
|
case "session-changed":
|
|
6107
|
-
|
|
6270
|
+
ka.add(e);
|
|
6108
6271
|
break;
|
|
6109
|
-
case "transport-failure":
|
|
6272
|
+
case "transport-failure": Aa.add(e);
|
|
6110
6273
|
}
|
|
6111
6274
|
return e;
|
|
6112
|
-
},
|
|
6275
|
+
}, Ma = (e) => Ca.has(e), Na = (e) => wa.has(e), Pa = (e) => Ta.has(e), Fa = (e) => Ea.has(e), Ia = (e) => Da.has(e), La = (e) => Oa.has(e), Ra = (e) => ka.has(e), za = (e) => Aa.has(e), Ba = "https://passflow-relative.invalid", Va = () => {
|
|
6113
6276
|
let e = globalThis, t = e.document?.baseURI;
|
|
6114
6277
|
if (typeof t == "string" && t !== "") return t;
|
|
6115
6278
|
let n = e.location?.href;
|
|
6116
|
-
return typeof n == "string" && n !== "" && n !== "about:blank" ? n :
|
|
6117
|
-
},
|
|
6118
|
-
let n = t ===
|
|
6279
|
+
return typeof n == "string" && n !== "" && n !== "about:blank" ? n : Ba;
|
|
6280
|
+
}, Ha = (e, t = Va()) => {
|
|
6281
|
+
let n = t === Ba, r;
|
|
6119
6282
|
try {
|
|
6120
6283
|
r = new URL(t).origin;
|
|
6121
6284
|
} catch {
|
|
@@ -6141,28 +6304,28 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6141
6304
|
relativeToBase: !1,
|
|
6142
6305
|
sentinelBase: n
|
|
6143
6306
|
};
|
|
6144
|
-
},
|
|
6307
|
+
}, Ua = (e, t) => typeof t == "string" ? [e.toLowerCase(), t] : void 0, Wa = (e) => {
|
|
6145
6308
|
let t = [];
|
|
6146
6309
|
if (e == null) return Object.freeze(t);
|
|
6147
6310
|
let n = e;
|
|
6148
6311
|
if (typeof n.forEach == "function" && typeof n.entries == "function") return e.forEach((e, n) => {
|
|
6149
|
-
let r =
|
|
6312
|
+
let r = Ua(n, e);
|
|
6150
6313
|
r && t.push(r);
|
|
6151
6314
|
}), Object.freeze(t);
|
|
6152
6315
|
if (Array.isArray(e)) {
|
|
6153
6316
|
for (let n of e) if (Array.isArray(n) && n.length >= 2) {
|
|
6154
|
-
let e =
|
|
6317
|
+
let e = Ua(String(n[0]), n[1]);
|
|
6155
6318
|
e && t.push(e);
|
|
6156
6319
|
}
|
|
6157
6320
|
return Object.freeze(t);
|
|
6158
6321
|
}
|
|
6159
6322
|
if (typeof e == "object") for (let [n, r] of Object.entries(e)) {
|
|
6160
|
-
let e =
|
|
6323
|
+
let e = Ua(n, Array.isArray(r) ? r.join(", ") : r);
|
|
6161
6324
|
e && t.push(e);
|
|
6162
6325
|
}
|
|
6163
6326
|
return Object.freeze(t);
|
|
6164
|
-
},
|
|
6165
|
-
let t = e.base === void 0 ?
|
|
6327
|
+
}, Ga = (e) => {
|
|
6328
|
+
let t = e.base === void 0 ? Ha(e.url) : Ha(e.url, e.base), n = {
|
|
6166
6329
|
raw: e.url,
|
|
6167
6330
|
href: t.href,
|
|
6168
6331
|
dispatchUrl: t.sentinelBase || !t.resolved ? e.url : t.href,
|
|
@@ -6171,29 +6334,29 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6171
6334
|
resolved: t.resolved,
|
|
6172
6335
|
relativeToBase: t.relativeToBase,
|
|
6173
6336
|
method: (e.method ?? "GET").toUpperCase(),
|
|
6174
|
-
headers:
|
|
6337
|
+
headers: Wa(e.headers),
|
|
6175
6338
|
bodyKind: e.bodyKind,
|
|
6176
6339
|
..."body" in e ? { body: e.body } : {}
|
|
6177
6340
|
};
|
|
6178
6341
|
return Object.freeze(n);
|
|
6179
|
-
},
|
|
6342
|
+
}, Ka = (e, t) => {
|
|
6180
6343
|
if (!t || t.from === t.to) return e;
|
|
6181
6344
|
let n = !1, r = e.map(([e, r]) => e === "authorization" && r === t.from ? (n = !0, [e, t.to]) : [e, r]);
|
|
6182
6345
|
return n ? Object.freeze(r) : e;
|
|
6183
|
-
},
|
|
6346
|
+
}, qa = (e) => {
|
|
6184
6347
|
let t = {};
|
|
6185
6348
|
for (let [n, r] of e) t[n] = r;
|
|
6186
6349
|
return t;
|
|
6187
|
-
},
|
|
6350
|
+
}, Ja = /* @__PURE__ */ new Set([
|
|
6188
6351
|
"GET",
|
|
6189
6352
|
"HEAD",
|
|
6190
6353
|
"OPTIONS"
|
|
6191
|
-
]),
|
|
6354
|
+
]), Ya = (e) => typeof e == "object" && !!e && typeof e.url == "string" && typeof e.clone == "function" && "method" in e, Xa = (e) => typeof e == "string" ? e : Ya(e) ? e.url : String(e), Za = (e, t) => (t?.method ?? (Ya(e) ? e.method : void 0) ?? "GET").toUpperCase(), Qa = (e) => e == null ? "none" : typeof e == "string" ? "reusable" : typeof e.getReader == "function" ? "one-shot" : "reusable", $a = (e) => {
|
|
6192
6355
|
if (typeof e == "string") return e.length;
|
|
6193
6356
|
let t = e;
|
|
6194
6357
|
if (typeof t?.size == "number") return t.size;
|
|
6195
6358
|
if (typeof t?.byteLength == "number") return t.byteLength;
|
|
6196
|
-
},
|
|
6359
|
+
}, eo = (e, t, n) => e === void 0 || e === "always" ? !0 : e === "idempotent-only" ? Ja.has(t.method) : typeof e == "function" ? e(t) : !(e.maxBodyBytes !== void 0 && n !== void 0 && n > e.maxBodyBytes), to = (e, t, n, r, i) => ({
|
|
6197
6360
|
replayable: !1,
|
|
6198
6361
|
bodyKind: e,
|
|
6199
6362
|
reason: t,
|
|
@@ -6201,11 +6364,11 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6201
6364
|
forwardInit: i,
|
|
6202
6365
|
snapshot: r,
|
|
6203
6366
|
replay: () => Promise.reject(/* @__PURE__ */ Error(`This request cannot be replayed: ${t}`))
|
|
6204
|
-
}),
|
|
6367
|
+
}), no = (e, t) => qa(Ka(e.headers, t?.authorizationSwap)), ro = (e) => {
|
|
6205
6368
|
if (!e || !("headers" in e)) return e;
|
|
6206
6369
|
let { headers: t, ...n } = e;
|
|
6207
6370
|
return n;
|
|
6208
|
-
},
|
|
6371
|
+
}, io = (e, t) => t && "headers" in t && t.headers !== void 0 ? t.headers : Ya(e) ? e.headers : void 0, ao = (e) => {
|
|
6209
6372
|
if (e === null || typeof e == "string") return e;
|
|
6210
6373
|
if (typeof FormData < "u" && e instanceof FormData) {
|
|
6211
6374
|
let t = new FormData();
|
|
@@ -6213,18 +6376,18 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6213
6376
|
return t;
|
|
6214
6377
|
}
|
|
6215
6378
|
return typeof URLSearchParams < "u" && e instanceof URLSearchParams ? new URLSearchParams(e) : e instanceof ArrayBuffer ? e.slice(0) : ArrayBuffer.isView(e) ? new Uint8Array(e.buffer, e.byteOffset, e.byteLength).slice() : e;
|
|
6216
|
-
},
|
|
6217
|
-
let r =
|
|
6379
|
+
}, oo = (e, t, n) => new Request(e, { headers: no(t, n) }), so = (e, t, n) => {
|
|
6380
|
+
let r = Xa(e), i = Za(e, t), a = io(e, t), o = (e, t) => Ga({
|
|
6218
6381
|
url: r,
|
|
6219
6382
|
method: i,
|
|
6220
6383
|
headers: a,
|
|
6221
6384
|
bodyKind: e,
|
|
6222
6385
|
...t === void 0 ? {} : { body: t }
|
|
6223
6386
|
});
|
|
6224
|
-
if (
|
|
6387
|
+
if (Ya(e)) {
|
|
6225
6388
|
if (e.body === null || e.body === void 0) {
|
|
6226
6389
|
let a = o("none");
|
|
6227
|
-
return
|
|
6390
|
+
return eo(n, {
|
|
6228
6391
|
url: r,
|
|
6229
6392
|
method: i,
|
|
6230
6393
|
bodyKind: "none"
|
|
@@ -6234,20 +6397,20 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6234
6397
|
forwardInput: e,
|
|
6235
6398
|
forwardInit: t,
|
|
6236
6399
|
snapshot: a,
|
|
6237
|
-
replay: (n, r) => n(
|
|
6238
|
-
} :
|
|
6400
|
+
replay: (n, r) => n(oo(e, a, r), ro(t))
|
|
6401
|
+
} : to("none", "the replay policy refused this request", e, a, t);
|
|
6239
6402
|
}
|
|
6240
6403
|
let a = o("request-clone");
|
|
6241
|
-
if (!
|
|
6404
|
+
if (!eo(n, {
|
|
6242
6405
|
url: r,
|
|
6243
6406
|
method: i,
|
|
6244
6407
|
bodyKind: "request-clone"
|
|
6245
|
-
})) return
|
|
6408
|
+
})) return to("request-clone", "the replay policy refused this request", e, a, t);
|
|
6246
6409
|
let s;
|
|
6247
6410
|
try {
|
|
6248
6411
|
s = e.clone();
|
|
6249
6412
|
} catch {
|
|
6250
|
-
return
|
|
6413
|
+
return to("one-shot", "the Request body was already consumed and cannot be cloned", e, a, t);
|
|
6251
6414
|
}
|
|
6252
6415
|
return {
|
|
6253
6416
|
replayable: !0,
|
|
@@ -6255,17 +6418,17 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6255
6418
|
forwardInput: e,
|
|
6256
6419
|
forwardInit: t,
|
|
6257
6420
|
snapshot: a,
|
|
6258
|
-
replay: (e, n) => e(
|
|
6421
|
+
replay: (e, n) => e(oo(s, a, n), ro(t))
|
|
6259
6422
|
};
|
|
6260
6423
|
}
|
|
6261
|
-
let s =
|
|
6262
|
-
if (s === "one-shot") return
|
|
6263
|
-
if (!
|
|
6424
|
+
let s = Qa(t?.body);
|
|
6425
|
+
if (s === "one-shot") return to("one-shot", "a streaming request body is consumed by the first send", e, o("one-shot"), t);
|
|
6426
|
+
if (!eo(n, {
|
|
6264
6427
|
url: r,
|
|
6265
6428
|
method: i,
|
|
6266
6429
|
bodyKind: s
|
|
6267
|
-
},
|
|
6268
|
-
let c = t && "body" in t ?
|
|
6430
|
+
}, $a(t?.body))) return to(s, "the replay policy refused this request", e, o(s), t);
|
|
6431
|
+
let c = t && "body" in t ? ao(t.body ?? null) : void 0, l = o(s, c);
|
|
6269
6432
|
return {
|
|
6270
6433
|
replayable: !0,
|
|
6271
6434
|
bodyKind: s,
|
|
@@ -6273,21 +6436,21 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6273
6436
|
forwardInit: t,
|
|
6274
6437
|
snapshot: l,
|
|
6275
6438
|
replay: (e, n) => e(l.dispatchUrl, {
|
|
6276
|
-
...
|
|
6439
|
+
...ro(t),
|
|
6277
6440
|
...c === void 0 ? {} : { body: c },
|
|
6278
|
-
headers:
|
|
6441
|
+
headers: no(l, n),
|
|
6279
6442
|
method: l.method
|
|
6280
6443
|
})
|
|
6281
6444
|
};
|
|
6282
|
-
},
|
|
6283
|
-
if (!
|
|
6445
|
+
}, co = (e) => typeof e == "object" && !!e, lo = (e) => (t) => {
|
|
6446
|
+
if (!co(e)) return;
|
|
6284
6447
|
let n = e[t] ?? e[t.toLowerCase()] ?? (typeof e.get == "function" ? e.get(t) : void 0);
|
|
6285
6448
|
return Array.isArray(n) ? n.join(", ") : typeof n == "string" ? n : void 0;
|
|
6286
|
-
},
|
|
6449
|
+
}, uo = (e) => {
|
|
6287
6450
|
let t = e?.url ?? "", n = e?.baseURL;
|
|
6288
6451
|
return !n || /^([a-z][a-z\d+\-.]*:)?\/\//i.test(t) ? t : `${n.replace(/\/+$/, "")}/${t.replace(/^\/+/, "")}`;
|
|
6289
|
-
},
|
|
6290
|
-
let r =
|
|
6452
|
+
}, fo = (e) => (e?.method ?? "GET").toUpperCase(), po = (e) => e == null ? "none" : co(e) && (typeof e.pipe == "function" || typeof e.getReader == "function") ? "one-shot" : "reusable", mo = (e, t, n) => {
|
|
6453
|
+
let r = qa(Ka(t.headers, n?.authorizationSwap)), i = t.dispatchUrl === t.href && t.resolved;
|
|
6291
6454
|
return {
|
|
6292
6455
|
...e,
|
|
6293
6456
|
...i ? { baseURL: void 0 } : {},
|
|
@@ -6296,10 +6459,10 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6296
6459
|
headers: r,
|
|
6297
6460
|
..."body" in t ? { data: t.body } : {}
|
|
6298
6461
|
};
|
|
6299
|
-
},
|
|
6300
|
-
let o = t ?? e?.config, s =
|
|
6301
|
-
url:
|
|
6302
|
-
method:
|
|
6462
|
+
}, ho = (e, t, n, r, i, a) => {
|
|
6463
|
+
let o = t ?? e?.config, s = po(o?.data), c = a ?? Ga({
|
|
6464
|
+
url: uo(o),
|
|
6465
|
+
method: fo(o),
|
|
6303
6466
|
headers: o?.headers,
|
|
6304
6467
|
bodyKind: s,
|
|
6305
6468
|
body: o?.data
|
|
@@ -6307,22 +6470,22 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6307
6470
|
url: c.href,
|
|
6308
6471
|
method: c.method,
|
|
6309
6472
|
bodyKind: s
|
|
6310
|
-
}, u = s !== "one-shot" &&
|
|
6473
|
+
}, u = s !== "one-shot" && eo(i.replay, l);
|
|
6311
6474
|
return {
|
|
6312
6475
|
status: e?.status ?? 0,
|
|
6313
|
-
getHeader:
|
|
6476
|
+
getHeader: lo(e?.headers),
|
|
6314
6477
|
readBody: async () => e?.data,
|
|
6315
6478
|
request: c,
|
|
6316
6479
|
replay: async (e) => {
|
|
6317
|
-
let t = Ee(
|
|
6480
|
+
let t = Ee(mo(o ?? {}, c, e));
|
|
6318
6481
|
try {
|
|
6319
6482
|
let e = await r(t);
|
|
6320
|
-
return
|
|
6483
|
+
return ho(e, e?.config ?? t, e, r, i, c);
|
|
6321
6484
|
} catch (e) {
|
|
6322
|
-
let n =
|
|
6323
|
-
if (!n.response || typeof n.response.status != "number" ||
|
|
6485
|
+
let n = co(e) ? e : {};
|
|
6486
|
+
if (!n.response || typeof n.response.status != "number" || Ur(e)) throw e;
|
|
6324
6487
|
return {
|
|
6325
|
-
...
|
|
6488
|
+
...ho(n.response, n.config ?? t, e, r, i, c),
|
|
6326
6489
|
rejected: !0
|
|
6327
6490
|
};
|
|
6328
6491
|
}
|
|
@@ -6336,19 +6499,61 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6336
6499
|
replayUnsupportedReason: s === "one-shot" ? "a streaming request body is consumed by the first send" : "the replay policy refused this request",
|
|
6337
6500
|
signal: o?.signal
|
|
6338
6501
|
};
|
|
6339
|
-
},
|
|
6340
|
-
let r =
|
|
6502
|
+
}, go = (e, t) => async (n) => {
|
|
6503
|
+
let r = ra(e), i = co(n) ? n : {}, a = Sa(await ya(ho(i.response, i.config, i.response, t, r), r), n);
|
|
6341
6504
|
if (a.settle === "reject") throw a.error;
|
|
6342
6505
|
return a.value;
|
|
6343
|
-
},
|
|
6344
|
-
let r = e.request, i = n ?? (typeof r == "function" ? (t) => r.call(e, t) : () => Promise.reject(/* @__PURE__ */ Error("Passflow: this client exposes no request() to replay through."))), a = e.interceptors.response.use(void 0,
|
|
6506
|
+
}, _o = (e, t, n) => {
|
|
6507
|
+
let r = e.request, i = n ?? (typeof r == "function" ? (t) => r.call(e, t) : () => Promise.reject(/* @__PURE__ */ Error("Passflow: this client exposes no request() to replay through."))), a = e.interceptors.response.use(void 0, go(t, i)), o = !1;
|
|
6345
6508
|
return () => {
|
|
6346
6509
|
o || (o = !0, e.interceptors.response.eject(a));
|
|
6347
6510
|
};
|
|
6348
|
-
},
|
|
6511
|
+
}, vo = (t, n) => {
|
|
6349
6512
|
let r = e.create(t);
|
|
6350
6513
|
return n(r), r;
|
|
6351
|
-
},
|
|
6514
|
+
}, yo = () => {
|
|
6515
|
+
let e = typeof location > "u" ? void 0 : location.origin;
|
|
6516
|
+
return e && e !== "null" ? e : void 0;
|
|
6517
|
+
}, bo = (e) => {
|
|
6518
|
+
let t = new URL(e).origin;
|
|
6519
|
+
if (t === "null") throw Error(`Passflow: "${e}" has no origin a request can be matched against; list http(s) origins only.`);
|
|
6520
|
+
return t;
|
|
6521
|
+
}, xo = (e, t) => {
|
|
6522
|
+
let n = (t?.origins ?? []).map(bo);
|
|
6523
|
+
return (t, r) => {
|
|
6524
|
+
if (r) return Promise.resolve(void 0);
|
|
6525
|
+
let i = yo(), a;
|
|
6526
|
+
try {
|
|
6527
|
+
a = new URL(t, i).origin;
|
|
6528
|
+
} catch {
|
|
6529
|
+
return Promise.resolve(void 0);
|
|
6530
|
+
}
|
|
6531
|
+
return a !== i && !n.includes(a) ? Promise.resolve(void 0) : e();
|
|
6532
|
+
};
|
|
6533
|
+
}, So = (e) => typeof Request < "u" && e instanceof Request, Co = (e, t) => new Headers(t?.headers === void 0 ? So(e) ? e.headers : void 0 : t.headers), wo = (e, t, n) => {
|
|
6534
|
+
let r = xo(t, n);
|
|
6535
|
+
return async (t, n) => {
|
|
6536
|
+
let i = So(t) ? t.url : t instanceof URL ? t.href : String(t), a = Co(t, n), o = await r(i, a.has("authorization"));
|
|
6537
|
+
return o ? (a.set("authorization", `Bearer ${o}`), e(t, {
|
|
6538
|
+
...n,
|
|
6539
|
+
headers: a
|
|
6540
|
+
})) : e(t, n);
|
|
6541
|
+
};
|
|
6542
|
+
}, To = (e) => {
|
|
6543
|
+
let t = e.url ?? "", n = /^([a-z][a-z\d+\-.]*:)?\/\//i.test(t);
|
|
6544
|
+
return !e.baseURL || n && e.allowAbsoluteUrls !== !1 ? t : t ? `${e.baseURL.replace(/\/?\/$/, "")}/${t.replace(/^\/+/, "")}` : e.baseURL;
|
|
6545
|
+
}, Eo = (e) => e ? typeof e.has == "function" ? e.has("Authorization") : Object.keys(e).some((t) => t.toLowerCase() === "authorization" && e[t] != null) : !1, Do = (e, t) => {
|
|
6546
|
+
let n = xo(e, t);
|
|
6547
|
+
return async (e) => {
|
|
6548
|
+
let t = e.headers, r = await n(To(e), Eo(t));
|
|
6549
|
+
if (!r) return e;
|
|
6550
|
+
let i = `Bearer ${r}`;
|
|
6551
|
+
return t && typeof t.set == "function" ? t.set("Authorization", i) : e.headers = {
|
|
6552
|
+
...t ?? {},
|
|
6553
|
+
Authorization: i
|
|
6554
|
+
}, e;
|
|
6555
|
+
};
|
|
6556
|
+
}, Oo = 0, ko = (e, t) => {
|
|
6352
6557
|
let n = t?.signal ?? (typeof e == "object" && e ? e.signal : void 0) ?? void 0;
|
|
6353
6558
|
if (n) return {
|
|
6354
6559
|
get aborted() {
|
|
@@ -6362,34 +6567,34 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6362
6567
|
removeEventListener: (e, t) => n.removeEventListener(e, t)
|
|
6363
6568
|
} : {}
|
|
6364
6569
|
};
|
|
6365
|
-
},
|
|
6570
|
+
}, Ao = (e) => (t) => e.headers?.get(t), jo = (e, t, n, r, i) => ({
|
|
6366
6571
|
status: e.status,
|
|
6367
|
-
getHeader:
|
|
6572
|
+
getHeader: Ao(e),
|
|
6368
6573
|
readBody: () => e.clone().json(),
|
|
6369
6574
|
request: t.snapshot,
|
|
6370
|
-
replay: async (e) =>
|
|
6575
|
+
replay: async (e) => jo(await t.replay(n, e), t, n, r, i),
|
|
6371
6576
|
markers: r,
|
|
6372
6577
|
raw: e,
|
|
6373
6578
|
replayable: t.replayable,
|
|
6374
6579
|
replayUnsupportedReason: t.reason,
|
|
6375
6580
|
signal: i,
|
|
6376
6581
|
responseType: e.type
|
|
6377
|
-
}),
|
|
6582
|
+
}), Mo = (e, t) => {
|
|
6378
6583
|
let n = (t, n) => {
|
|
6379
|
-
|
|
6584
|
+
Oo += 1;
|
|
6380
6585
|
try {
|
|
6381
6586
|
return e(t, n);
|
|
6382
6587
|
} finally {
|
|
6383
|
-
--
|
|
6588
|
+
--Oo;
|
|
6384
6589
|
}
|
|
6385
6590
|
};
|
|
6386
6591
|
return async (e, r) => {
|
|
6387
|
-
if (
|
|
6388
|
-
let i =
|
|
6592
|
+
if (Oo > 0) return n(e, r);
|
|
6593
|
+
let i = ra(t), a = so(e, r, i.replay), o = await n(a.forwardInput, a.forwardInit), s = xa(await ya(jo(o, a, n, {}, ko(e, r)), i), o, i);
|
|
6389
6594
|
if (s.settle === "reject") throw s.error;
|
|
6390
6595
|
return s.value;
|
|
6391
6596
|
};
|
|
6392
|
-
},
|
|
6597
|
+
}, No = new Set(Fi.filter((e) => !e.requiresPrepare).map((e) => e.type)), Po = (e) => {
|
|
6393
6598
|
if (!e || typeof e != "object" || !e.challenge_id || !e.expires_at) throw new $({
|
|
6394
6599
|
kind: "protocol",
|
|
6395
6600
|
message: "The upgrade start response is missing challenge_id or expires_at"
|
|
@@ -6401,17 +6606,17 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6401
6606
|
webauthn: e.webauthn,
|
|
6402
6607
|
codeSentTo: e.code_sent_to
|
|
6403
6608
|
};
|
|
6404
|
-
},
|
|
6609
|
+
}, Fo = (e) => Ur(e) && !Wr(e), Io = (e) => ({
|
|
6405
6610
|
async prepare(t) {
|
|
6406
|
-
if (!
|
|
6611
|
+
if (!No.has(t)) try {
|
|
6407
6612
|
let n = e.relyingPartyId?.();
|
|
6408
|
-
return
|
|
6613
|
+
return Po(await e.startUpgrade(n ? {
|
|
6409
6614
|
method: t,
|
|
6410
6615
|
relying_party_id: n
|
|
6411
6616
|
} : { method: t }));
|
|
6412
6617
|
} catch (e) {
|
|
6413
|
-
if (
|
|
6414
|
-
let t =
|
|
6618
|
+
if (Fo(e)) throw e;
|
|
6619
|
+
let t = Xr(e, "start");
|
|
6415
6620
|
if (t.kind === "prepare_not_required") return;
|
|
6416
6621
|
throw t;
|
|
6417
6622
|
}
|
|
@@ -6428,28 +6633,28 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6428
6633
|
assertion: n
|
|
6429
6634
|
});
|
|
6430
6635
|
} catch (t) {
|
|
6431
|
-
if (
|
|
6432
|
-
let n =
|
|
6433
|
-
throw n.status === 401 &&
|
|
6636
|
+
if (Fo(t)) throw t;
|
|
6637
|
+
let n = Xr(t, "refresh");
|
|
6638
|
+
throw n.status === 401 && Qr(n) && e.markSessionInvalid?.(), n;
|
|
6434
6639
|
}
|
|
6435
6640
|
}
|
|
6436
|
-
}),
|
|
6641
|
+
}), Lo = (e) => e === void 0 ? [] : (Array.isArray(e) ? e : [e]).filter((e) => e !== ""), Ro = (e) => {
|
|
6437
6642
|
let t, n = (e) => e !== void 0 && t === e, r = (r) => {
|
|
6438
6643
|
let i = () => {
|
|
6439
6644
|
if (!n(r())) throw new $({ kind: "session_changed" });
|
|
6440
6645
|
};
|
|
6441
|
-
return
|
|
6646
|
+
return Io({
|
|
6442
6647
|
...e,
|
|
6443
6648
|
relyingPartyId: () => t?.options.relyingPartyId ?? e.relyingPartyId?.(),
|
|
6444
6649
|
startUpgrade: (t) => (i(), e.startUpgrade(t)),
|
|
6445
|
-
commitRefresh: (t) => (i(), e.commitRefresh(t, r()?.pin)),
|
|
6650
|
+
commitRefresh: (t) => (i(), a = Date.now(), e.commitRefresh(t, r()?.pin)),
|
|
6446
6651
|
...e.markSessionInvalid ? { markSessionInvalid: () => {
|
|
6447
6652
|
n(r()) && e.markSessionInvalid?.();
|
|
6448
6653
|
} } : {}
|
|
6449
6654
|
});
|
|
6450
6655
|
}, i = (t, n) => {
|
|
6451
6656
|
let i = {}, a = {
|
|
6452
|
-
controller: new
|
|
6657
|
+
controller: new na({
|
|
6453
6658
|
transport: r(() => i.current),
|
|
6454
6659
|
prompt: t.prompt,
|
|
6455
6660
|
platform: e.platform,
|
|
@@ -6461,25 +6666,38 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6461
6666
|
options: t,
|
|
6462
6667
|
scope: {
|
|
6463
6668
|
passflow: e.passflowDomain,
|
|
6464
|
-
backend:
|
|
6669
|
+
backend: Lo(t.backend)
|
|
6465
6670
|
},
|
|
6466
6671
|
generation: n
|
|
6467
6672
|
};
|
|
6468
6673
|
return i.current = a, a;
|
|
6469
|
-
}, a =
|
|
6470
|
-
|
|
6471
|
-
|
|
6472
|
-
|
|
6473
|
-
|
|
6474
|
-
if (!
|
|
6475
|
-
|
|
6476
|
-
|
|
6674
|
+
}, a, o = 1e4, s;
|
|
6675
|
+
e.stopRepeatedElevation?.subscribe(() => {
|
|
6676
|
+
s = void 0;
|
|
6677
|
+
});
|
|
6678
|
+
let c = (e) => {
|
|
6679
|
+
if (!s || ta(s.challenge, e)) return;
|
|
6680
|
+
let t = Math.min(o, e.maxAge === void 0 ? o : e.maxAge * 1e3);
|
|
6681
|
+
if (!(Date.now() - s.at > t)) return s.challenge;
|
|
6682
|
+
}, l = async (r, i) => {
|
|
6683
|
+
let o = t;
|
|
6684
|
+
if (!o) throw new ei("Step-up verification is not enabled on this Passflow instance");
|
|
6685
|
+
let l = e.stopRepeatedElevation ? c(r) : void 0;
|
|
6686
|
+
if (l) throw new $r(Qi(l), Qi(r), "This requirement was already proved and the server still refused it: sign the user in again");
|
|
6687
|
+
o.controller.active || (o.pin = e.readSessionPin?.());
|
|
6688
|
+
let u = await o.controller.elevate(r, i);
|
|
6689
|
+
if (!n(o)) throw new ti();
|
|
6690
|
+
return e.stopRepeatedElevation && (s = {
|
|
6691
|
+
challenge: r,
|
|
6692
|
+
at: a ?? Date.now()
|
|
6693
|
+
}), u;
|
|
6694
|
+
}, u = () => {
|
|
6477
6695
|
let n = t, r = n?.scope ?? {
|
|
6478
6696
|
passflow: e.passflowDomain,
|
|
6479
6697
|
backend: []
|
|
6480
6698
|
}, i = n?.options;
|
|
6481
6699
|
return {
|
|
6482
|
-
elevate:
|
|
6700
|
+
elevate: l,
|
|
6483
6701
|
scope: r,
|
|
6484
6702
|
...i?.requireChallengeChannel ? { requireChallengeChannel: i.requireChallengeChannel } : {},
|
|
6485
6703
|
...i?.shouldIntercept ? { shouldIntercept: i.shouldIntercept } : {},
|
|
@@ -6489,7 +6707,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6489
6707
|
...i?.onUpgradeDiagnostic ? { onUpgradeDiagnostic: i.onUpgradeDiagnostic } : {},
|
|
6490
6708
|
...e.readObtainedBar ? { readObtainedBar: e.readObtainedBar } : {}
|
|
6491
6709
|
};
|
|
6492
|
-
},
|
|
6710
|
+
}, d;
|
|
6493
6711
|
return Object.defineProperties(async (e) => {
|
|
6494
6712
|
let t = e?.acrValues === void 0 ? void 0 : L(e.acrValues).level, n = {
|
|
6495
6713
|
status: 401,
|
|
@@ -6500,24 +6718,24 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6500
6718
|
...e?.acrValues === void 0 ? {} : { acrValues: e.acrValues },
|
|
6501
6719
|
...t === void 0 ? {} : { level: t },
|
|
6502
6720
|
...e?.maxAge === void 0 ? {} : { maxAge: e.maxAge }
|
|
6503
|
-
},
|
|
6721
|
+
}, a = (await l(n, {
|
|
6504
6722
|
kind: "imperative",
|
|
6505
6723
|
...r ? { requested: i } : {}
|
|
6506
6724
|
})).obtained.acrValues;
|
|
6507
6725
|
return {
|
|
6508
6726
|
status: "elevated",
|
|
6509
|
-
...
|
|
6727
|
+
...a === void 0 ? {} : { acr: a }
|
|
6510
6728
|
};
|
|
6511
6729
|
}, {
|
|
6512
6730
|
enable: {
|
|
6513
6731
|
value: (n) => {
|
|
6514
|
-
|
|
6732
|
+
d?.(), t = i(n, 0);
|
|
6515
6733
|
let r = [];
|
|
6516
6734
|
if (e.attachInternalSeam) {
|
|
6517
6735
|
let t = e.attachInternalSeam;
|
|
6518
|
-
t((e) =>
|
|
6736
|
+
t((e) => go(u, e)), r.push(() => t(void 0));
|
|
6519
6737
|
}
|
|
6520
|
-
n.interceptFetch && r.push(
|
|
6738
|
+
n.interceptFetch && r.push(Lt((e, t, n) => Mo(e, u)(t, n), {
|
|
6521
6739
|
priority: 20,
|
|
6522
6740
|
name: "passflow-upgrade"
|
|
6523
6741
|
})), e.onSessionChange && r.push(e.onSessionChange(() => {
|
|
@@ -6525,13 +6743,13 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6525
6743
|
e && (t = i(e.options, e.generation + 1));
|
|
6526
6744
|
}));
|
|
6527
6745
|
let a = !1;
|
|
6528
|
-
return
|
|
6746
|
+
return d = () => {
|
|
6529
6747
|
if (!a) {
|
|
6530
6748
|
a = !0;
|
|
6531
6749
|
for (let e of r) e();
|
|
6532
|
-
t = void 0,
|
|
6750
|
+
t = void 0, d = void 0;
|
|
6533
6751
|
}
|
|
6534
|
-
},
|
|
6752
|
+
}, d;
|
|
6535
6753
|
},
|
|
6536
6754
|
enumerable: !0
|
|
6537
6755
|
},
|
|
@@ -6543,23 +6761,32 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6543
6761
|
},
|
|
6544
6762
|
elevate: {
|
|
6545
6763
|
enumerable: !0,
|
|
6546
|
-
value: (e, t) =>
|
|
6764
|
+
value: (e, t) => l(e, t ?? { kind: "imperative" })
|
|
6547
6765
|
},
|
|
6548
6766
|
withAuth: {
|
|
6549
6767
|
enumerable: !0,
|
|
6550
|
-
value: (
|
|
6551
|
-
|
|
6552
|
-
|
|
6553
|
-
|
|
6554
|
-
|
|
6768
|
+
value: (t, n) => {
|
|
6769
|
+
let r = (t) => {
|
|
6770
|
+
let r = Mo(t, u);
|
|
6771
|
+
return e.readAccessToken ? wo(r, e.readAccessToken, n) : r;
|
|
6772
|
+
};
|
|
6773
|
+
if (t) return r(t);
|
|
6774
|
+
let i = typeof globalThis > "u" ? void 0 : globalThis;
|
|
6775
|
+
if (!i || typeof i.fetch != "function") throw Error("Passflow: withAuth() needs a fetch to wrap — this runtime has none.");
|
|
6776
|
+
return r(i.fetch.bind(i));
|
|
6555
6777
|
}
|
|
6556
6778
|
},
|
|
6557
6779
|
attachAuth: {
|
|
6558
6780
|
enumerable: !0,
|
|
6559
|
-
value: (
|
|
6781
|
+
value: (t, n) => {
|
|
6782
|
+
let r = e.readAccessToken ? t.interceptors.request : void 0, i = r?.use(Do(e.readAccessToken, n)), a = _o(t, u);
|
|
6783
|
+
return () => {
|
|
6784
|
+
a(), r && i !== void 0 && r.eject(i);
|
|
6785
|
+
};
|
|
6786
|
+
}
|
|
6560
6787
|
}
|
|
6561
6788
|
});
|
|
6562
|
-
},
|
|
6789
|
+
}, zo, Bo = class {
|
|
6563
6790
|
get origin() {
|
|
6564
6791
|
return this.platform.getCurrentUrl()?.origin ?? "";
|
|
6565
6792
|
}
|
|
@@ -6570,18 +6797,23 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6570
6797
|
let { url: t, appId: n, scopes: r } = e;
|
|
6571
6798
|
this.url = t || "https://auth.passflow.cloud", this.appId = n, this.platform = e.platform ?? ae, this.deferFederatedLanding = e.deferFederatedLanding ?? !1, this.storageManager = new ne({
|
|
6572
6799
|
prefix: e.keyStoragePrefix ?? "",
|
|
6573
|
-
storage: this.platform.storage
|
|
6574
|
-
|
|
6575
|
-
|
|
6576
|
-
|
|
6577
|
-
|
|
6578
|
-
|
|
6800
|
+
storage: this.platform.storage,
|
|
6801
|
+
appId: n
|
|
6802
|
+
}), this.deviceService = new re(this.storageManager), this.authApi = new ft(e, this.storageManager, this.deviceService), this.appApi = new ot(e, this.storageManager, this.deviceService), this.userApi = new Ct(e, this.storageManager, this.deviceService), this.settingApi = new ht(e, this.storageManager, this.deviceService), this.tenantApi = new gt(e, this.storageManager, this.deviceService), this.invitationApi = new mt(e, this.storageManager, this.deviceService), this.twoFactorApi = new xt(e, this.storageManager, this.deviceService), this.upgradeApi = new St(e, this.storageManager, this.deviceService), this.upgradeDomain = ke(e.url), this.subscribeStore = new jr(), this.tokenCacheService = new Di(this.storageManager, this.authApi, this.subscribeStore, this.platform), this.scopes = r ?? d, this.createTenantForNewUser = e.createTenantForNewUser ?? !1;
|
|
6803
|
+
let i = Xn(e.refreshCoordination, this.platform, e.keyStoragePrefix, { tokenKeys: () => this.storageManager.tokenKeys() });
|
|
6804
|
+
this.authService = new Ci(this.authApi, this.deviceService, this.storageManager, this.subscribeStore, this.tokenCacheService, this.scopes, this.createTenantForNewUser, this.url, {
|
|
6805
|
+
createSession: async (e) => {
|
|
6806
|
+
await this.createSessionCallback?.(e);
|
|
6807
|
+
},
|
|
6808
|
+
expiredSession: async () => {
|
|
6809
|
+
await this.expiredSessionCallback?.();
|
|
6810
|
+
}
|
|
6579
6811
|
}, this.appId ?? "", e.tokenExchange, this.platform, () => this.readPkceEnabled(), {
|
|
6580
6812
|
coordination: i,
|
|
6581
6813
|
...e.refreshStrikes === void 0 ? {} : { strikes: e.refreshStrikes }
|
|
6582
6814
|
}, () => this.readAppSettings()), this.tokenCacheService.attachRefreshController(this.authService.refresh);
|
|
6583
6815
|
for (let e of this.axiosClients()) e.setRefreshHandler((e) => this.authService.refresh.ensureFresh(e));
|
|
6584
|
-
this.userService = new
|
|
6816
|
+
this.userService = new ki(this.userApi, this.deviceService, this.platform), this.tenantService = new Ei(this.tenantApi, this.scopes), this.tenant = this.tenantService, this.invitationService = new wi(this.invitationApi), this.twoFactorService = new Oi(this.twoFactorApi, this.subscribeStore, this.authService), this.twoFactor = this.twoFactorService, this.upgrade = Ro({
|
|
6585
6817
|
startUpgrade: (e) => this.upgradeApi.startUpgrade(e),
|
|
6586
6818
|
commitRefresh: async (e, t) => {
|
|
6587
6819
|
await this.authService.refreshToken(e, t);
|
|
@@ -6605,13 +6837,18 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6605
6837
|
} : void 0;
|
|
6606
6838
|
},
|
|
6607
6839
|
attachInternalSeam: (e) => this.attachUpgradeSeam(e),
|
|
6608
|
-
onSessionChange: (e) => this.subscribeToSessionChange(e)
|
|
6609
|
-
|
|
6840
|
+
onSessionChange: (e) => this.subscribeToSessionChange(e),
|
|
6841
|
+
readAccessToken: async () => {
|
|
6842
|
+
let e = (await this.getTokens(!0))?.access_token;
|
|
6843
|
+
return e && !A(j(e)) ? e : void 0;
|
|
6844
|
+
}
|
|
6845
|
+
}), this.hostedUpgrade = Ro({
|
|
6610
6846
|
startUpgrade: (e) => this.upgradeApi.startHostedUpgrade(e),
|
|
6611
6847
|
commitRefresh: (e) => this.upgradeApi.commitHostedUpgrade(e),
|
|
6612
6848
|
canCommit: () => ({ ok: !0 }),
|
|
6613
6849
|
readSessionPin: () => void 0,
|
|
6614
6850
|
readObtainedBar: () => void 0,
|
|
6851
|
+
stopRepeatedElevation: { subscribe: (e) => this.subscribeToSessionChange(e) },
|
|
6615
6852
|
markSessionInvalid: () => {},
|
|
6616
6853
|
platform: this.platform,
|
|
6617
6854
|
passflowDomain: this.upgradeDomain,
|
|
@@ -6633,16 +6870,16 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6633
6870
|
return this.readAppSettings().then((e) => e?.pkce_enabled ?? !1);
|
|
6634
6871
|
}
|
|
6635
6872
|
setAppId(e) {
|
|
6636
|
-
this.appId = e, this.appSettingsRead = void 0, this.authApi.setAppId(e), this.appApi.setAppId(e), this.userApi.setAppId(e), this.settingApi.setAppId(e), this.tenantApi.setAppId(e), this.invitationApi.setAppId(e), this.twoFactorApi.setAppId(e), this.upgradeApi.setAppId(e), this.authService.setAppId(e);
|
|
6873
|
+
this.appId = e, this.storageManager.setAppId(e), this.appSettingsRead = void 0, this.authApi.setAppId(e), this.appApi.setAppId(e), this.userApi.setAppId(e), this.settingApi.setAppId(e), this.tenantApi.setAppId(e), this.invitationApi.setAppId(e), this.twoFactorApi.setAppId(e), this.upgradeApi.setAppId(e), this.authService.setAppId(e);
|
|
6637
6874
|
}
|
|
6638
|
-
withAuth(e) {
|
|
6639
|
-
return this.upgrade.withAuth(e);
|
|
6875
|
+
withAuth(e, t) {
|
|
6876
|
+
return this.upgrade.withAuth(e, t);
|
|
6640
6877
|
}
|
|
6641
|
-
attachAuth(e) {
|
|
6642
|
-
return this.upgrade.attachAuth(e);
|
|
6878
|
+
attachAuth(e, t) {
|
|
6879
|
+
return this.upgrade.attachAuth(e, t);
|
|
6643
6880
|
}
|
|
6644
|
-
createClient(e) {
|
|
6645
|
-
return
|
|
6881
|
+
createClient(e, t) {
|
|
6882
|
+
return vo(e, (e) => this.upgrade.attachAuth(e, t));
|
|
6646
6883
|
}
|
|
6647
6884
|
readAssuranceBar() {
|
|
6648
6885
|
let e = this.storageManager.getToken(M.access_token);
|
|
@@ -6725,7 +6962,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6725
6962
|
}
|
|
6726
6963
|
let n = t.get("access_token"), r = t.get("refresh_token"), i = t.get("id_token"), a = t.get("state") ?? void 0, o = t.get("scopes")?.split(",") ?? this.scopes;
|
|
6727
6964
|
if (n) {
|
|
6728
|
-
if (!
|
|
6965
|
+
if (!ii(n)) {
|
|
6729
6966
|
W(this.subscribeStore, {
|
|
6730
6967
|
operation: "tokens.from-url",
|
|
6731
6968
|
message: "Invalid access token format received",
|
|
@@ -6733,7 +6970,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6733
6970
|
}), this.cleanupUrlParams(e);
|
|
6734
6971
|
return;
|
|
6735
6972
|
}
|
|
6736
|
-
if (r && !
|
|
6973
|
+
if (r && !ii(r)) {
|
|
6737
6974
|
W(this.subscribeStore, {
|
|
6738
6975
|
operation: "tokens.from-url",
|
|
6739
6976
|
message: "Invalid refresh token format received",
|
|
@@ -6741,7 +6978,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6741
6978
|
}), this.cleanupUrlParams(e);
|
|
6742
6979
|
return;
|
|
6743
6980
|
}
|
|
6744
|
-
if (i && !
|
|
6981
|
+
if (i && !ii(i)) {
|
|
6745
6982
|
W(this.subscribeStore, {
|
|
6746
6983
|
operation: "tokens.from-url",
|
|
6747
6984
|
message: "Invalid ID token format received",
|
|
@@ -6756,10 +6993,10 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6756
6993
|
scopes: o
|
|
6757
6994
|
};
|
|
6758
6995
|
this.cleanupUrlParams(e), this.error = void 0, this.readAppSettings().catch(() => void 0).then((e) => {
|
|
6759
|
-
if (e?.pkce_enabled !== !1) throw
|
|
6760
|
-
return
|
|
6996
|
+
if (e?.pkce_enabled !== !1) throw an();
|
|
6997
|
+
return Ir(this.url, this.appId, t);
|
|
6761
6998
|
}).then(() => {
|
|
6762
|
-
this.storageManager.clearDeliveryMode(), this.storageManager.saveTokens(t), this.tokenCacheService.setTokensCache(t), this.authService.refresh.sessionStarted();
|
|
6999
|
+
this.storageManager.clearDeliveryMode(), this.storageManager.saveTokens(t), e && this.storageManager.setHostedSignIn(e.origin + e.pathname), this.tokenCacheService.setTokensCache(t), this.authService.refresh.sessionStarted();
|
|
6763
7000
|
}).then(() => (this.subscribeStore.notify(Z.SignIn, {
|
|
6764
7001
|
tokens: t,
|
|
6765
7002
|
parsedTokens: this.getParsedTokens(),
|
|
@@ -6792,7 +7029,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6792
7029
|
if (!n) return !1;
|
|
6793
7030
|
t.delete("tfa_token");
|
|
6794
7031
|
let r = t.toString();
|
|
6795
|
-
return this.platform.replaceUrl(e.pathname + e.search + (r ? `#${r}` : "")),
|
|
7032
|
+
return this.platform.replaceUrl(e.pathname + e.search + (r ? `#${r}` : "")), ii(n) ? (this.subscribeStore.notify(Z.TwoFactorRequired, {
|
|
6796
7033
|
email: "",
|
|
6797
7034
|
challengeId: "",
|
|
6798
7035
|
tfaToken: n
|
|
@@ -6805,7 +7042,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6805
7042
|
checkErrorsFromURL() {
|
|
6806
7043
|
let e = new URLSearchParams(this.platform.getCurrentUrl()?.search ?? "").get("error");
|
|
6807
7044
|
if (e) {
|
|
6808
|
-
let t =
|
|
7045
|
+
let t = ai(e);
|
|
6809
7046
|
return Error(t);
|
|
6810
7047
|
}
|
|
6811
7048
|
}
|
|
@@ -6912,10 +7149,14 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
6912
7149
|
};
|
|
6913
7150
|
throw W(this.subscribeStore, r), e;
|
|
6914
7151
|
}
|
|
6915
|
-
async logOut() {
|
|
7152
|
+
async logOut(e = {}) {
|
|
6916
7153
|
try {
|
|
6917
|
-
let e = await this.authService.logOut();
|
|
6918
|
-
|
|
7154
|
+
let t = this.authService.hostedEndSessionUrl(e.postLogoutRedirectUri), n = await this.authService.logOut();
|
|
7155
|
+
try {
|
|
7156
|
+
this.twoFactorService.clearPartialAuthState(), this.notifySignedOut(n), await this.submitSessionCheck();
|
|
7157
|
+
} finally {
|
|
7158
|
+
t && this.platform.navigateTo(t);
|
|
7159
|
+
}
|
|
6919
7160
|
} catch (e) {
|
|
6920
7161
|
this.handleError(e, "log-out", "Log out");
|
|
6921
7162
|
}
|
|
@@ -7211,7 +7452,7 @@ var si = "passflow_2fa_pkce", ci = 3e5, li = "passflow_pwless_pending", ui = 3e3
|
|
|
7211
7452
|
this.twoFactorService.clearMagicLinkSession();
|
|
7212
7453
|
}
|
|
7213
7454
|
};
|
|
7214
|
-
|
|
7215
|
-
export { a as APP_ID_HEADER_KEY,
|
|
7455
|
+
zo = Bo, zo.version = l;
|
|
7456
|
+
export { a as APP_ID_HEADER_KEY, Ie as APP_SECRET_NAMES, o as AUTHORIZATION_HEADER_KEY, ot as AppAPI, ft as AuthAPI, Ci as AuthService, pt as CLIAuthAPI, p as DEFAULT_GROUP_NAME, d as DEFAULT_SCOPES, Fi as DEFAULT_UPGRADE_FACTORS, s as DEVICE_ID_HEADER_KEY, c as DEVICE_TYPE_HEADER_KEY, x as ERROR_MESSAGE_MAX_LENGTH, wt as FETCH_PRIORITY_OIDC, Tt as FETCH_PRIORITY_UPGRADE, Et as FetchMiddlewareContractError, le as INSUFFICIENT_USER_AUTHENTICATION, mt as InvitationAPI, wi as InvitationService, Kt as M2MClient, Vt as M2MConfigError, H as M2MError, Ht as M2MErrorCodes, zt as M2MNetworkError, Bt as M2MTokenParseError, Ut as M2M_DEFAULTS, Le as MASKED_SECRET_PREFIX, u as MINIMAL_DEFAULT_SCOPES, Be as OS, f as PASSFLOW_CLOUD_URL, Ne as PASSWORD_CHANGE_REQUIRED_ERROR_ID, h as POPUP_HEIGHT, g as POPUP_POLL_INTERVAL_MS, _ as POPUP_TIMEOUT_MS, m as POPUP_WIDTH, Bo as Passflow, B as PassflowAdminEndpointPaths, z as PassflowEndpointPaths, V as PassflowError, Z as PassflowEvent, U as PassflowOidcError, Pe as PassflowPasswordChangeRequiredError, J as PassflowRefreshError, ie as PopupClosedError, Fe as Providers, Lr as RECOVERABLE_COMMIT_ERROR_IDS, $n as REFRESH_AUTH_FAILURE_IDS, q as RefreshErrorId, Oe as RequestMethod, l as SDK_VERSION, je as SERVICE_UNAVAILABLE_ERROR_ID, Me as SERVICE_UNAVAILABLE_MESSAGE, Rr as SESSION_INVALIDATING_COMMIT_ERROR_IDS, Re as SETTINGS_MASKED_VALUE_UNKNOWN_ERROR_ID, te as SessionState, ht as SettingAPI, v as TOKEN_EXPIRY_BUFFER_SECONDS, gt as TenantAPI, Ei as TenantService, Ti as TenantUserMembership, Di as TokenCacheService, N as TokenDeliveryMode, M as TokenType, xt as TwoFactorApiClient, Ue as TwoFactorPolicy, Oi as TwoFactorService, ue as UPGRADE_REQUIRED, b as USERNAME_MAX_LENGTH, y as USERNAME_MIN_LENGTH, St as UpgradeAPI, Hi as UpgradeCancelledError, dr as UpgradeCommitInterruptedError, na as UpgradeController, Q as UpgradeErrorIds, Ai as UpgradeFactorError, $r as UpgradeInsufficientError, ti as UpgradeSessionChangedError, Ui as UpgradeSignInRequiredError, $ as UpgradeTransportError, ei as UpgradeUnavailableError, Ji as UpgradeUnsatisfiableError, Ct as UserAPI, ki as UserService, F as WebAdapter, Xr as classifyUpgradeError, Ii as factorRegistry, Rt as fetchRegistryState, Ve as getOSFromDeviceType, Qr as invalidatesSessionOnCommit, Ae as isEmailVerificationStep, ze as isMaskedSecret, Zr as isRecoverableCommitFailure, Br as isRetryableUpgradeKind, A as isTokenExpired, Ma as isUpgradeCancelled, Na as isUpgradeExhausted, Pa as isUpgradeInsufficient, Ra as isUpgradeSessionChanged, Ia as isUpgradeSignInRequired, Wr as isUpgradeTransportError, za as isUpgradeTransportFailure, La as isUpgradeUnavailable, Fa as isUpgradeUnsatisfiable, oi as isValidEmail, ii as isValidJWTFormat, si as isValidPhoneNumber, ci as isValidUsername, ge as parseChallengeBody, he as parseChallengeHeader, j as parseToken, be as parseUpgradeChallenge, Pi as passkeyFactor, He as pathWithParams, Ni as recoveryCodesFactor, Lt as registerFetchMiddleware, ce as requiredAcrLevel, ke as resolveUpgradeDomain, ai as sanitizeErrorMessage, Vi as selectFactors, Mi as totpFactor, ae as webAdapter };
|
|
7216
7457
|
|
|
7217
7458
|
//# sourceMappingURL=index.mjs.map
|