@axa-fr/oidc-client 7.27.11 → 7.27.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,48 +1,5 @@
1
- //#region src/location.ts
2
- var e = class {
3
- open(e) {
4
- window.location.href = e;
5
- }
6
- reload() {
7
- window.location.reload();
8
- }
9
- getCurrentHref() {
10
- return window.location.href;
11
- }
12
- getPath() {
13
- let e = window.location;
14
- return e.pathname + (e.search || "") + (e.hash || "");
15
- }
16
- getOrigin() {
17
- return window.origin;
18
- }
19
- }, t = 2e3, n = console, r = class {
20
- constructor(e, n, r, i = t, a = !0) {
21
- this._callback = e, this._client_id = n, this._url = r, this._interval = i || t, this._stopOnError = a;
22
- let o = r.indexOf("/", r.indexOf("//") + 2);
23
- this._frame_origin = r.substring(0, o), this._frame = window.document.createElement("iframe"), this._frame.style.visibility = "hidden", this._frame.style.position = "absolute", this._frame.style.display = "none", this._frame.width = 0, this._frame.height = 0, this._frame.src = r;
24
- }
25
- load() {
26
- return new Promise((e) => {
27
- this._frame.onload = () => {
28
- e();
29
- }, window.document.body.appendChild(this._frame), this._boundMessageEvent = this._message.bind(this), window.addEventListener("message", this._boundMessageEvent, !1);
30
- });
31
- }
32
- _message(e) {
33
- e.origin === this._frame_origin && e.source === this._frame.contentWindow && (e.data === "error" ? (n.error("CheckSessionIFrame: error message from check session op iframe"), this._stopOnError && this.stop()) : e.data === "changed" ? (n.debug(e), n.debug("CheckSessionIFrame: changed message from check session op iframe"), this.stop(), this._callback()) : n.debug("CheckSessionIFrame: " + e.data + " message from check session op iframe"));
34
- }
35
- start(e) {
36
- n.debug("CheckSessionIFrame.start :" + e), this.stop();
37
- let t = () => {
38
- this._frame.contentWindow.postMessage(this._client_id + " " + e, this._frame_origin);
39
- };
40
- t(), this._timer = window.setInterval(t, this._interval);
41
- }
42
- stop() {
43
- this._timer &&= (n.debug("CheckSessionIFrame.stop"), window.clearInterval(this._timer), null);
44
- }
45
- }, i = {
1
+ //#region src/events.ts
2
+ var e = {
46
3
  service_worker_not_supported_by_browser: "service_worker_not_supported_by_browser",
47
4
  token_acquired: "token_acquired",
48
5
  logout_from_another_tab: "logout_from_another_tab",
@@ -70,36 +27,37 @@ var e = class {
70
27
  syncTokensAsync_lock_not_available: "syncTokensAsync_lock_not_available",
71
28
  syncTokensAsync_end: "syncTokensAsync_end",
72
29
  syncTokensAsync_error: "syncTokensAsync_error",
73
- tokensInvalidAndWaitingActionsToRefresh: "tokensInvalidAndWaitingActionsToRefresh"
74
- }, a = (e, t, n) => {
30
+ tokensInvalidAndWaitingActionsToRefresh: "tokensInvalidAndWaitingActionsToRefresh",
31
+ loadingTimeout_error: "loadingTimeout_error"
32
+ }, t = (e, t, n) => {
75
33
  if (n == null) {
76
34
  delete e[t];
77
35
  return;
78
36
  }
79
37
  e[t] = JSON.stringify(n);
80
- }, o = (e, t, n) => {
38
+ }, n = (e, t, n) => {
81
39
  if (n == null) {
82
40
  delete e[t];
83
41
  return;
84
42
  }
85
43
  e[t] = n;
86
- }, s = (e) => {
44
+ }, r = (e) => {
87
45
  if (typeof e != "string" || e === "undefined" || e === "null" || e === "") return null;
88
46
  try {
89
47
  return JSON.parse(e);
90
48
  } catch {
91
49
  return null;
92
50
  }
93
- }, c = (e, t = sessionStorage, n) => {
94
- let r = n ?? t, i = (i) => (a(t, `oidc.${e}`, {
51
+ }, i = (e, i = sessionStorage, a) => {
52
+ let o = a ?? i, s = (n) => (t(i, `oidc.${e}`, {
95
53
  tokens: null,
96
- status: i
97
- }), delete t[`oidc.${e}.userInfo`], n && n !== t && (delete r[`oidc.login.${e}`], delete r[`oidc.state.${e}`], delete r[`oidc.code_verifier.${e}`], delete r[`oidc.nonce.${e}`]), Promise.resolve()), c = async () => {
98
- let n = s(t[`oidc.${e}`]);
54
+ status: n
55
+ }), delete i[`oidc.${e}.userInfo`], a && a !== i && (delete o[`oidc.login.${e}`], delete o[`oidc.state.${e}`], delete o[`oidc.code_verifier.${e}`], delete o[`oidc.nonce.${e}`]), Promise.resolve()), c = async () => {
56
+ let n = r(i[`oidc.${e}`]);
99
57
  return n ? Promise.resolve({
100
58
  tokens: n.tokens,
101
59
  status: n.status
102
- }) : (a(t, `oidc.${e}`, {
60
+ }) : (t(i, `oidc.${e}`, {
103
61
  tokens: null,
104
62
  status: null
105
63
  }), {
@@ -107,21 +65,21 @@ var e = class {
107
65
  status: null
108
66
  });
109
67
  }, l = (n) => {
110
- a(t, `oidc.${e}`, { tokens: n });
111
- }, u = async (n) => {
112
- o(t, `oidc.session_state.${e}`, n);
113
- }, d = async () => t[`oidc.session_state.${e}`], f = (t) => {
114
- o(r, `oidc.nonce.${e}`, t?.nonce);
68
+ t(i, `oidc.${e}`, { tokens: n });
69
+ }, u = async (t) => {
70
+ n(i, `oidc.session_state.${e}`, t);
71
+ }, d = async () => i[`oidc.session_state.${e}`], f = (t) => {
72
+ n(o, `oidc.nonce.${e}`, t?.nonce);
115
73
  }, p = (n) => {
116
- a(t, `oidc.jwk.${e}`, n);
117
- }, m = () => s(t[`oidc.jwk.${e}`]), h = async () => ({ nonce: r[`oidc.nonce.${e}`] }), g = async (n) => {
118
- o(t, `oidc.dpop_nonce.${e}`, n);
119
- }, _ = () => t[`oidc.dpop_nonce.${e}`], v = () => {
120
- let n = s(t[`oidc.${e}`]);
121
- return n ? JSON.stringify({ tokens: n.tokens }) : null;
74
+ t(i, `oidc.jwk.${e}`, n);
75
+ }, m = () => r(i[`oidc.jwk.${e}`]), h = async () => ({ nonce: o[`oidc.nonce.${e}`] }), g = async (t) => {
76
+ n(i, `oidc.dpop_nonce.${e}`, t);
77
+ }, _ = () => i[`oidc.dpop_nonce.${e}`], v = () => {
78
+ let t = r(i[`oidc.${e}`]);
79
+ return t ? JSON.stringify({ tokens: t.tokens }) : null;
122
80
  }, y = {};
123
81
  return {
124
- clearAsync: i,
82
+ clearAsync: s,
125
83
  initAsync: c,
126
84
  setTokens: l,
127
85
  getTokens: v,
@@ -129,133 +87,58 @@ var e = class {
129
87
  getSessionStateAsync: d,
130
88
  setNonceAsync: f,
131
89
  getNonceAsync: h,
132
- setLoginParams: (t) => {
133
- if (t == null) {
134
- delete y[e], delete r[`oidc.login.${e}`];
90
+ setLoginParams: (n) => {
91
+ if (n == null) {
92
+ delete y[e], delete o[`oidc.login.${e}`];
135
93
  return;
136
94
  }
137
- y[e] = t, a(r, `oidc.login.${e}`, t);
95
+ y[e] = n, t(o, `oidc.login.${e}`, n);
138
96
  },
139
97
  getLoginParams: () => {
140
98
  if (y[e]) return y[e];
141
- let t = s(r[`oidc.login.${e}`]);
99
+ let t = r(o[`oidc.login.${e}`]);
142
100
  return t === null ? (console.warn(`storage[oidc.login.${e}] is empty, you should have an bad OIDC or code configuration somewhere.`), null) : (y[e] = t, t);
143
101
  },
144
- getStateAsync: async () => r[`oidc.state.${e}`],
102
+ getStateAsync: async () => o[`oidc.state.${e}`],
145
103
  setStateAsync: async (t) => {
146
- o(r, `oidc.state.${e}`, t);
104
+ n(o, `oidc.state.${e}`, t);
147
105
  },
148
- getCodeVerifierAsync: async () => r[`oidc.code_verifier.${e}`],
106
+ getCodeVerifierAsync: async () => o[`oidc.code_verifier.${e}`],
149
107
  setCodeVerifierAsync: async (t) => {
150
- o(r, `oidc.code_verifier.${e}`, t);
108
+ n(o, `oidc.code_verifier.${e}`, t);
151
109
  },
152
110
  setDemonstratingProofOfPossessionNonce: g,
153
111
  getDemonstratingProofOfPossessionNonce: _,
154
112
  setDemonstratingProofOfPossessionJwkAsync: p,
155
113
  getDemonstratingProofOfPossessionJwkAsync: m
156
114
  };
157
- }, l = /* @__PURE__ */ function(e) {
158
- return e.AutomaticBeforeTokenExpiration = "AutomaticBeforeTokensExpiration", e.AutomaticOnlyWhenFetchExecuted = "AutomaticOnlyWhenFetchExecuted", e;
159
- }({}), u = (e) => decodeURIComponent(Array.prototype.map.call(atob(e), (e) => "%" + ("00" + e.charCodeAt(0).toString(16)).slice(-2)).join("")), d = (e) => JSON.parse(u(e.replaceAll(/-/g, "+").replaceAll(/_/g, "/"))), f = (e) => {
160
- try {
161
- return e && p(e, ".") === 2 ? d(e.split(".")[1]) : null;
162
- } catch (e) {
163
- console.warn(e);
115
+ }, a = 2e3, o = console, s = class {
116
+ constructor(e, t, n, r = a, i = !0) {
117
+ this._callback = e, this._client_id = t, this._url = n, this._interval = r || a, this._stopOnError = i;
118
+ let o = n.indexOf("/", n.indexOf("//") + 2);
119
+ this._frame_origin = n.substring(0, o), this._frame = window.document.createElement("iframe"), this._frame.style.visibility = "hidden", this._frame.style.position = "absolute", this._frame.style.display = "none", this._frame.width = 0, this._frame.height = 0, this._frame.src = n;
164
120
  }
165
- return null;
166
- }, p = (e, t) => e.split(t).length - 1, m = {
167
- access_token_or_id_token_invalid: "access_token_or_id_token_invalid",
168
- access_token_invalid: "access_token_invalid",
169
- id_token_invalid: "id_token_invalid"
170
- };
171
- function h(e, t, n) {
172
- return e.issuedAt ? typeof e.issuedAt == "string" ? parseInt(e.issuedAt, 10) : e.issuedAt : t && t.iat ? t.iat : n && n.iat ? n.iat : (/* @__PURE__ */ new Date()).getTime() / 1e3;
173
- }
174
- var g = (e, t = null, n) => {
175
- if (!e) return null;
176
- let r, i = typeof e.expiresIn == "string" ? parseInt(e.expiresIn, 10) : e.expiresIn;
177
- r = e.accessTokenPayload === void 0 ? f(e.accessToken) : e.accessTokenPayload;
178
- let a;
179
- a = t != null && "idToken" in t && !("idToken" in e) ? t.idToken : e.idToken;
180
- let o = e.idTokenPayload ? e.idTokenPayload : f(a), s = o && o.exp ? o.exp : Number.MAX_VALUE, c = r && r.exp ? r.exp : e.issuedAt + i;
181
- e.issuedAt = h(e, r, o);
182
- let l;
183
- l = e.expiresAt ? e.expiresAt : n === m.access_token_invalid ? c : n === m.id_token_invalid || s < c ? s : c;
184
- let u = {
185
- ...e,
186
- idTokenPayload: o,
187
- accessTokenPayload: r,
188
- expiresAt: l,
189
- idToken: a
190
- };
191
- if (t != null && "refreshToken" in t && !("refreshToken" in e)) {
192
- let e = t.refreshToken;
193
- return {
194
- ...u,
195
- refreshToken: e
196
- };
121
+ load() {
122
+ return new Promise((e) => {
123
+ this._frame.onload = () => {
124
+ e();
125
+ }, window.document.body.appendChild(this._frame), this._boundMessageEvent = this._message.bind(this), window.addEventListener("message", this._boundMessageEvent, !1);
126
+ });
197
127
  }
198
- return u;
199
- }, _ = (e, t, n) => {
200
- if (!e) return null;
201
- e.issued_at ||= (/* @__PURE__ */ new Date()).getTime() / 1e3;
202
- let r = {
203
- accessToken: e.access_token,
204
- expiresIn: e.expires_in,
205
- idToken: e.id_token,
206
- scope: e.scope,
207
- tokenType: e.token_type,
208
- issuedAt: e.issued_at
209
- };
210
- return "refresh_token" in e && (r.refreshToken = e.refresh_token), e.accessTokenPayload !== void 0 && (r.accessTokenPayload = e.accessTokenPayload), e.idTokenPayload !== void 0 && (r.idTokenPayload = e.idTokenPayload), g(r, t, n);
211
- }, v = (e, t) => {
212
- let n = t - (/* @__PURE__ */ new Date()).getTime() / 1e3;
213
- return Math.round(n - e);
214
- }, y = (e, t = 0) => e ? v(t, e.expiresAt) > 0 : !1, b = async (e, t = 200, n = 50) => {
215
- let r = n, i = await e.syncTokensInfoAsync();
216
- for (; [
217
- G.REQUIRE_SYNC_TOKENS,
218
- G.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID,
219
- G.TOKENS_INVALID
220
- ].includes(i) && r > 0;) {
221
- if (e.configuration.token_automatic_renew_mode == l.AutomaticOnlyWhenFetchExecuted) {
222
- await e.renewTokensAsync({});
223
- break;
224
- } else await E({ milliseconds: t });
225
- --r, i = await e.syncTokensInfoAsync();
128
+ _message(e) {
129
+ e.origin === this._frame_origin && e.source === this._frame.contentWindow && (e.data === "error" ? (o.error("CheckSessionIFrame: error message from check session op iframe"), this._stopOnError && this.stop()) : e.data === "changed" ? (o.debug(e), o.debug("CheckSessionIFrame: changed message from check session op iframe"), this.stop(), this._callback()) : o.debug("CheckSessionIFrame: " + e.data + " message from check session op iframe"));
226
130
  }
227
- return {
228
- isTokensValid: y(e.getTokens()),
229
- tokens: e.getTokens(),
230
- numberWaited: r - n
231
- };
232
- }, x = (e, t, n) => {
233
- if (e.idTokenPayload) {
234
- let r = e.idTokenPayload;
235
- if (n.issuer !== r.iss) return {
236
- isValid: !1,
237
- reason: `Issuer does not match (oidcServerConfiguration issuer) ${n.issuer} !== (idTokenPayload issuer) ${r.iss}`
238
- };
239
- let i = (/* @__PURE__ */ new Date()).getTime() / 1e3;
240
- if (r.exp && r.exp < i) return {
241
- isValid: !1,
242
- reason: `Token expired (idTokenPayload exp) ${r.exp} < (currentTimeUnixSecond) ${i}`
243
- };
244
- let a = 3600 * 24 * 7;
245
- if (r.iat && r.iat + a < i) return {
246
- isValid: !1,
247
- reason: `Token is used from too long time (idTokenPayload iat + timeInSevenDays) ${r.iat + a} < (currentTimeUnixSecond) ${i}`
248
- };
249
- if (r.nonce && r.nonce !== t) return {
250
- isValid: !1,
251
- reason: `Nonce does not match (idTokenPayload nonce) ${r.nonce} !== (nonce) ${t}`
131
+ start(e) {
132
+ o.debug("CheckSessionIFrame.start :" + e), this.stop();
133
+ let t = () => {
134
+ this._frame.contentWindow.postMessage(this._client_id + " " + e, this._frame_origin);
252
135
  };
136
+ t(), this._timer = window.setInterval(t, this._interval);
253
137
  }
254
- return {
255
- isValid: !0,
256
- reason: ""
257
- };
258
- }, S = (function() {
138
+ stop() {
139
+ this._timer &&= (o.debug("CheckSessionIFrame.stop"), window.clearInterval(this._timer), null);
140
+ }
141
+ }, c = (function() {
259
142
  let e = typeof window > "u" ? global : window;
260
143
  return {
261
144
  setTimeout: setTimeout.bind(e),
@@ -263,328 +146,123 @@ var g = (e, t = null, n) => {
263
146
  setInterval: setInterval.bind(e),
264
147
  clearInterval: clearInterval.bind(e)
265
148
  };
266
- })(), C = "7.27.11", w = null, T, E = ({ milliseconds: e }) => new Promise((t) => S.setTimeout(t, e)), D = (e = "/") => {
149
+ })(), l = (t, n, r) => (i = null, a = null, o = null) => {
150
+ if (!n.silent_redirect_uri || !n.silent_login_uri) return Promise.resolve(null);
267
151
  try {
268
- T = new AbortController(), fetch(`${e}OidcKeepAliveServiceWorker.json?minSleepSeconds=150`, { signal: T.signal }).catch((e) => {
269
- console.log(e);
270
- }), E({ milliseconds: 150 * 1e3 }).then(() => D(e));
271
- } catch (e) {
272
- console.log(e);
273
- }
274
- }, O = () => {
275
- T && T.abort();
276
- }, k = (e) => {
277
- let t = `oidc.tabId.${e}`, n = sessionStorage.getItem(t);
278
- if (n) return n;
279
- let r = globalThis.crypto.randomUUID();
280
- return sessionStorage.setItem(t, r), r;
281
- }, ee = 5e3, A = (e) => navigator.serviceWorker.controller ?? e.active ?? e.waiting ?? e.installing ?? null, j = (e, t) => (n) => {
282
- let r = t?.timeoutMs ?? ee;
283
- return new Promise((t, i) => {
284
- let a = A(e);
285
- if (!a) {
286
- i(/* @__PURE__ */ Error("Service worker target not available (controller/active/waiting/installing missing)"));
287
- return;
288
- }
289
- let o = new MessageChannel(), s = null, c = () => {
152
+ r(e.silentLoginAsync_begin, {});
153
+ let s = "";
154
+ if (a && (i ??= {}, i.state = a), o != null && (i ??= {}, i.scope = o), i != null) for (let [e, t] of Object.entries(i)) t != null && (s === "" ? s = `?${encodeURIComponent(e)}=${encodeURIComponent(t)}` : s += `&${encodeURIComponent(e)}=${encodeURIComponent(t)}`);
155
+ let c = n.silent_login_uri + s, l = c.indexOf("/", c.indexOf("//") + 2), u = c.substring(0, l), d = document.createElement("iframe");
156
+ return d.width = "0px", d.height = "0px", d.id = `${t}_oidc_iframe`, d.setAttribute("src", c), d.style.display = "none", document.body.appendChild(d), new Promise((i, a) => {
157
+ let o = !1, s = () => {
158
+ window.removeEventListener("message", c), d.remove(), o = !0;
159
+ }, c = (n) => {
160
+ if (n.origin === u && n.source === d.contentWindow) {
161
+ let c = `${t}_oidc_tokens:`, l = `${t}_oidc_error:`, u = `${t}_oidc_exception:`, d = n.data;
162
+ if (d && typeof d == "string" && !o) {
163
+ if (d.startsWith(c)) {
164
+ let t = JSON.parse(n.data.replace(c, ""));
165
+ r(e.silentLoginAsync_end, {}), i(t), s();
166
+ } else if (d.startsWith(l)) {
167
+ let t = JSON.parse(n.data.replace(l, ""));
168
+ r(e.silentLoginAsync_error, t), i({
169
+ error: "oidc_" + t.error,
170
+ tokens: null,
171
+ sessionState: null
172
+ }), s();
173
+ } else if (d.startsWith(u)) {
174
+ let t = JSON.parse(n.data.replace(u, ""));
175
+ r(e.silentLoginAsync_error, t), a(Error(t.error)), s();
176
+ }
177
+ }
178
+ }
179
+ };
290
180
  try {
291
- s != null && (S.clearTimeout(s), s = null), o.port1.onmessage = null, o.port1.close(), o.port2.close();
292
- } catch (e) {
293
- console.error(e);
181
+ window.addEventListener("message", c);
182
+ let t = n.silent_login_timeout;
183
+ setTimeout(() => {
184
+ o || (s(), r(e.silentLoginAsync_error, { reason: "timeout" }), a(/* @__PURE__ */ Error("timeout")));
185
+ }, t);
186
+ } catch (t) {
187
+ s(), r(e.silentLoginAsync_error, t), a(t);
294
188
  }
295
- };
296
- s = S.setTimeout(() => {
297
- c(), i(/* @__PURE__ */ Error(`Service worker did not respond within ${r}ms (type=${n?.type})`));
298
- }, r), o.port1.onmessage = (e) => {
299
- c(), e?.data?.error ? i(e.data.error) : t(e.data);
300
- };
301
- try {
302
- let e = n?.configurationName;
303
- a.postMessage({
304
- ...n,
305
- tabId: k(e ?? "default")
306
- }, [o.port2]);
307
- } catch (e) {
308
- c(), i(e);
309
- }
310
- });
311
- }, te = async (e) => navigator.serviceWorker.controller ? navigator.serviceWorker.controller : new Promise((t) => {
312
- let n = !1, r = () => {
313
- n || (n = !0, navigator.serviceWorker.removeEventListener("controllerchange", r), t(navigator.serviceWorker.controller ?? null));
314
- };
315
- navigator.serviceWorker.addEventListener("controllerchange", r), S.setTimeout(() => {
316
- n || (n = !0, navigator.serviceWorker.removeEventListener("controllerchange", r), t(navigator.serviceWorker.controller ?? null));
317
- }, e);
318
- }), ne = !1, M = !1, N = /* @__PURE__ */ new Map(), P = "oidc.sw.controllerchange_reload_count", F = 3, I = () => {
319
- try {
320
- return parseInt(sessionStorage.getItem(P) ?? "0", 10);
321
- } catch {
322
- return 0;
189
+ });
190
+ } catch (t) {
191
+ throw r(e.silentLoginAsync_error, t), t;
323
192
  }
324
- }, re = () => {
325
- let e = I() + 1;
326
- try {
327
- sessionStorage.setItem(P, String(e));
328
- } catch {}
329
- return e;
330
- }, ie = () => {
331
- try {
332
- sessionStorage.removeItem(P);
333
- } catch {}
334
- }, L = async (e, t) => {
335
- let n = e.service_worker_relative_url;
336
- if (typeof window > "u" || typeof navigator > "u" || !navigator.serviceWorker || !n || e.service_worker_activate() === !1) return null;
337
- let r = `${n}?v=${C}`, i = null;
338
- e.service_worker_register ? (N.has(n) || N.set(n, e.service_worker_register(n)), i = await N.get(n)) : (N.has(r) || N.set(r, navigator.serviceWorker.register(r, { updateViaCache: "none" })), i = await N.get(r));
339
- let a = `oidc.sw.version_mismatch_reload.${t}`, o = async (e) => {
340
- O(), console.log("New SW waiting – SKIP_WAITING");
193
+ }, u = (t, n, r, i, a) => (t = null, o = void 0) => {
194
+ t = { ...t };
195
+ let s = (e, t, o) => l(n, r, i.bind(a))(e, t, o);
196
+ return (async () => {
197
+ a.timeoutId && c.clearTimeout(a.timeoutId);
198
+ let n;
199
+ t && "state" in t && (n = t.state, delete t.state);
341
200
  try {
342
- await new Promise((n, r) => {
343
- let i = new MessageChannel(), a = null, o = () => {
344
- try {
345
- a != null && (S.clearTimeout(a), a = null), i.port1.onmessage = null, i.port1.close(), i.port2.close();
346
- } catch (e) {
347
- console.error(e);
348
- }
349
- };
350
- a = S.setTimeout(() => {
351
- o(), r(/* @__PURE__ */ Error("SKIP_WAITING did not respond within 8000ms"));
352
- }, 8e3), i.port1.onmessage = (e) => {
353
- o(), e?.data?.error ? r(e.data.error) : n();
354
- };
355
- try {
356
- e.postMessage({
357
- type: "SKIP_WAITING",
358
- configurationName: t,
359
- data: null,
360
- tabId: k(t ?? "default")
361
- }, [i.port2]);
362
- } catch (e) {
363
- o(), r(e);
364
- }
365
- });
201
+ let c = await s({
202
+ ...r.extras ? {
203
+ ...r.extras,
204
+ ...t
205
+ } : t,
206
+ prompt: "none"
207
+ }, n, o);
208
+ if (c) return a.tokens = c.tokens, i(e.token_acquired, {}), a.timeoutId = z(a, a.tokens.expiresAt, t, o), {};
366
209
  } catch (e) {
367
- console.warn("SKIP_WAITING failed", e);
210
+ return e;
368
211
  }
369
- }, s = async () => {
370
- let e = i.waiting;
371
- e ? await o(e) : console.warn("sendSkipWaiting called but no waiting service worker found");
372
- }, c = (e) => {
373
- O(), e.addEventListener("statechange", async () => {
374
- if (e.state === "installed" && navigator.serviceWorker.controller) {
375
- if (I() >= F) {
376
- console.warn("SW trackInstallingWorker: skipping SKIP_WAITING because the reload budget is exhausted");
377
- return;
378
- }
379
- await o(e);
380
- }
381
- });
382
- };
383
- i.addEventListener("updatefound", () => {
384
- let e = i.installing;
385
- e && c(e);
386
- }), i.installing ? c(i.installing) : i.waiting && navigator.serviceWorker.controller && (I() < F ? s() : console.warn("SW: a waiting worker exists but reload budget is exhausted – skipping activation")), i.update().catch((e) => {
387
- console.error(e);
212
+ })();
213
+ }, d = (e, t, n) => (r, i, a, o = !1) => {
214
+ let c = (t, r = void 0, i = void 0) => l(e.configurationName, n, e.publishEvent.bind(e))(t, r, i);
215
+ return new Promise((l, u) => {
216
+ n.silent_login_uri && n.silent_redirect_uri && n.monitor_session && r && a && !o ? (e.checkSessionIFrame = new s(() => {
217
+ e.checkSessionIFrame.stop();
218
+ let r = e.tokens;
219
+ if (r === null) return;
220
+ let i = r.idToken, a = r.idTokenPayload;
221
+ return c({
222
+ prompt: "none",
223
+ id_token_hint: i,
224
+ scope: n.scope || "openid"
225
+ }).then((t) => {
226
+ if (t.error) throw Error(t.error);
227
+ let n = t.tokens.idTokenPayload;
228
+ if (a.sub === n.sub) {
229
+ let r = t.sessionState;
230
+ e.checkSessionIFrame.start(t.sessionState), a.sid === n.sid ? console.debug("SessionMonitor._callback: Same sub still logged in at OP, restarting check session iframe; session_state:", r) : console.debug("SessionMonitor._callback: Same sub still logged in at OP, session state has changed, restarting check session iframe; session_state:", r);
231
+ } else console.debug("SessionMonitor._callback: Different subject signed into OP:", n.sub);
232
+ }).catch(async (e) => {
233
+ console.warn("SessionMonitor._callback: Silent login failed, logging out other tabs:", e);
234
+ for (let [, e] of Object.entries(t)) await e.logoutOtherTabAsync(n.client_id, a.sub);
235
+ });
236
+ }, i, r), e.checkSessionIFrame.load().then(() => {
237
+ e.checkSessionIFrame.start(a), l(e.checkSessionIFrame);
238
+ }).catch((e) => {
239
+ u(e);
240
+ })) : l(null);
388
241
  });
389
- try {
390
- await navigator.serviceWorker.ready, navigator.serviceWorker.controller || (await j(i, { timeoutMs: 8e3 })({
391
- type: "claim",
392
- configurationName: t,
393
- data: null
394
- }), await te(2e3));
395
- } catch (e) {
396
- return console.warn(`Failed init ServiceWorker ${e?.toString?.() ?? String(e)}`), null;
397
- }
398
- ne || (ne = !0, navigator.serviceWorker.addEventListener("controllerchange", () => {
399
- if (M) return;
400
- let e = re();
401
- if (e > F) {
402
- console.warn(`SW controllerchange: reload budget exhausted (${e - 1} reloads). Skipping reload to avoid infinite loop.`);
403
- return;
404
- }
405
- M = !0, console.log("SW controller changed – reloading page"), O(), window.location.reload();
406
- }));
407
- let l = async (e) => j(i)({
408
- type: "clear",
409
- data: { status: e },
410
- configurationName: t
411
- }), u = async (e, n, r) => {
412
- let o = await j(i)({
413
- type: "init",
414
- data: {
415
- oidcServerConfiguration: e,
416
- where: n,
417
- oidcConfiguration: {
418
- token_renew_mode: r.token_renew_mode,
419
- service_worker_convert_all_requests_to_cors: r.service_worker_convert_all_requests_to_cors
420
- }
421
- },
422
- configurationName: t
423
- }), c = o.version;
424
- if (c !== "7.27.11") {
425
- console.warn(`Service worker ${c} version mismatch with js client version ${C}, unregistering and reloading`);
426
- let e = parseInt(sessionStorage.getItem(a) ?? "0", 10);
427
- if (e < 3) {
428
- if (sessionStorage.setItem(a, String(e + 1)), i.waiting) return await s(), await E({ milliseconds: 500 }), M || (M = !0, window.location.reload()), new Promise(() => {});
429
- {
430
- O();
431
- try {
432
- await i.update();
433
- } catch (e) {
434
- console.error(e);
435
- }
436
- let e = await i.unregister();
437
- return console.log(`Service worker unregistering ${e}`), await E({ milliseconds: 500 }), M || (M = !0, window.location.reload()), new Promise(() => {});
438
- }
439
- } else console.error(`Service worker version mismatch persists after ${e} attempt(s). Continuing with mismatched version.`);
440
- } else sessionStorage.removeItem(a), ie();
441
- return {
442
- tokens: _(o.tokens, null, r.token_renew_mode),
443
- status: o.status
444
- };
445
- }, d = (e = "/") => {
446
- w ?? (w = "not_null", D(e));
447
- }, f = (e) => j(i)({
448
- type: "setSessionState",
449
- data: { sessionState: e },
450
- configurationName: t
451
- }), p = async () => (await j(i)({
452
- type: "getSessionState",
453
- data: null,
454
- configurationName: t
455
- })).sessionState, m = (e) => (sessionStorage[`oidc.nonce.${t}`] = e.nonce, j(i)({
456
- type: "setNonce",
457
- data: { nonce: e },
458
- configurationName: t
459
- })), h = async (e = !0) => {
460
- let n = (await j(i)({
461
- type: "getNonce",
462
- data: null,
463
- configurationName: t
464
- })).nonce;
465
- return n || (n = sessionStorage[`oidc.nonce.${t}`], console.warn("nonce not found in service worker, using sessionStorage"), e && (await m(n), n = (await h(!1)).nonce)), { nonce: n };
466
- }, g = {}, v = (e) => {
467
- if (e == null) {
468
- delete g[t], delete localStorage[`oidc.login.${t}`];
469
- return;
470
- }
471
- g[t] = e, localStorage[`oidc.login.${t}`] = JSON.stringify(e);
472
- }, y = () => {
473
- if (g[t]) return g[t];
474
- let e = localStorage[`oidc.login.${t}`];
475
- if (typeof e != "string" || e === "" || e === "undefined" || e === "null") return null;
476
- try {
477
- g[t] = JSON.parse(e);
478
- } catch {
479
- return null;
480
- }
481
- return g[t];
482
- }, b = async (e) => {
483
- await j(i)({
484
- type: "setDemonstratingProofOfPossessionNonce",
485
- data: { demonstratingProofOfPossessionNonce: e },
486
- configurationName: t
487
- });
488
- }, x = async () => (await j(i)({
489
- type: "getDemonstratingProofOfPossessionNonce",
490
- data: null,
491
- configurationName: t
492
- })).demonstratingProofOfPossessionNonce, T = async (e) => {
493
- let n = JSON.stringify(e);
494
- await j(i)({
495
- type: "setDemonstratingProofOfPossessionJwk",
496
- data: { demonstratingProofOfPossessionJwkJson: n },
497
- configurationName: t
498
- });
499
- }, ee = async () => {
500
- let e = await j(i)({
501
- type: "getDemonstratingProofOfPossessionJwk",
502
- data: null,
503
- configurationName: t
504
- });
505
- return e.demonstratingProofOfPossessionJwkJson ? JSON.parse(e.demonstratingProofOfPossessionJwkJson) : null;
506
- }, A = async (e = !0) => {
507
- let n = (await j(i)({
508
- type: "getState",
509
- data: null,
510
- configurationName: t
511
- })).state;
512
- return n || (n = sessionStorage[`oidc.state.${t}`], console.warn("state not found in service worker, using sessionStorage"), e && (await P(n), n = await A(!1))), n;
513
- }, P = async (e) => (sessionStorage[`oidc.state.${t}`] = e, j(i)({
514
- type: "setState",
515
- data: { state: e },
516
- configurationName: t
517
- })), L = async (e = !0) => {
518
- let n = (await j(i)({
519
- type: "getCodeVerifier",
520
- data: null,
521
- configurationName: t
522
- })).codeVerifier;
523
- return n || (n = sessionStorage[`oidc.code_verifier.${t}`], console.warn("codeVerifier not found in service worker, using sessionStorage"), e && (await R(n), n = await L(!1))), n;
524
- }, R = async (e) => (sessionStorage[`oidc.code_verifier.${t}`] = e, j(i)({
525
- type: "setCodeVerifier",
526
- data: { codeVerifier: e },
527
- configurationName: t
528
- }));
529
- return {
530
- clearAsync: l,
531
- initAsync: u,
532
- startKeepAliveServiceWorker: () => d(e.service_worker_keep_alive_path),
533
- setSessionStateAsync: f,
534
- getSessionStateAsync: p,
535
- setNonceAsync: m,
536
- getNonceAsync: h,
537
- setLoginParams: v,
538
- getLoginParams: y,
539
- getStateAsync: A,
540
- setStateAsync: P,
541
- getCodeVerifierAsync: L,
542
- setCodeVerifierAsync: R,
543
- setDemonstratingProofOfPossessionNonce: b,
544
- getDemonstratingProofOfPossessionNonce: x,
545
- setDemonstratingProofOfPossessionJwkAsync: T,
546
- getDemonstratingProofOfPossessionJwkAsync: ee
547
- };
548
- }, R = {}, ae = (e, t = window.sessionStorage, n) => {
549
- if (!R[e] && t) {
550
- let n = t.getItem(e);
551
- n && (R[e] = JSON.parse(n));
552
- }
553
- let r = 1e3 * n;
554
- return R[e] && R[e].timestamp + r > Date.now() ? R[e].result : null;
555
- }, oe = (e, t, n = window.sessionStorage) => {
556
- let r = Date.now();
557
- R[e] = {
558
- result: t,
559
- timestamp: r
560
- }, n && n.setItem(e, JSON.stringify({
561
- result: t,
562
- timestamp: r
563
- }));
564
242
  };
565
243
  //#endregion
566
244
  //#region src/jwt.ts
567
- function se(e) {
245
+ function f(e) {
568
246
  return new TextEncoder().encode(e);
569
247
  }
570
- function ce(e) {
248
+ function p(e) {
571
249
  return btoa(e).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+/g, "");
572
250
  }
573
- function le(e) {
251
+ function m(e) {
574
252
  return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g, function(e, t) {
575
253
  return String.fromCharCode(parseInt(t, 16));
576
254
  });
577
255
  }
578
- var z = (e) => {
256
+ var h = (e) => {
579
257
  let t = "";
580
258
  return e.forEach(function(e) {
581
259
  t += String.fromCharCode(e);
582
- }), ce(t);
260
+ }), p(t);
583
261
  };
584
- function ue(e) {
585
- return ce(le(e));
262
+ function g(e) {
263
+ return p(m(e));
586
264
  }
587
- var de = {
265
+ var _ = {
588
266
  importKeyAlgorithm: {
589
267
  name: "ECDSA",
590
268
  namedCurve: "P-256",
@@ -600,7 +278,7 @@ var de = {
600
278
  },
601
279
  digestAlgorithm: { name: "SHA-256" },
602
280
  jwtHeaderAlgorithm: "ES256"
603
- }, fe = { sign: (e) => async (t, n, r, i, a = "dpop+jwt") => {
281
+ }, v = { sign: (e) => async (t, n, r, i, a = "dpop+jwt") => {
604
282
  switch (t = Object.assign({}, t), n.typ = a, n.alg = i.jwtHeaderAlgorithm, n.alg) {
605
283
  case "ES256":
606
284
  n.jwk = {
@@ -621,11 +299,11 @@ var de = {
621
299
  default: throw Error("Unknown or not implemented JWS algorithm");
622
300
  }
623
301
  let o = {
624
- protected: ue(JSON.stringify(n)),
625
- payload: ue(JSON.stringify(r))
626
- }, s = i.importKeyAlgorithm, c = await e.crypto.subtle.importKey("jwk", t, s, !0, ["sign"]), l = se(`${o.protected}.${o.payload}`), u = i.signAlgorithm, d = await e.crypto.subtle.sign(u, c, l);
627
- return o.signature = z(new Uint8Array(d)), `${o.protected}.${o.payload}.${o.signature}`;
628
- } }, pe = {
302
+ protected: g(JSON.stringify(n)),
303
+ payload: g(JSON.stringify(r))
304
+ }, s = i.importKeyAlgorithm, c = await e.crypto.subtle.importKey("jwk", t, s, !0, ["sign"]), l = f(`${o.protected}.${o.payload}`), u = i.signAlgorithm, d = await e.crypto.subtle.sign(u, c, l);
305
+ return o.signature = h(new Uint8Array(d)), `${o.protected}.${o.payload}.${o.signature}`;
306
+ } }, y = {
629
307
  generate: (e) => async (t) => {
630
308
  let n = t, r = await e.crypto.subtle.generateKey(n, !0, ["sign", "verify"]);
631
309
  return await e.crypto.subtle.exportKey("jwk", r.privateKey);
@@ -634,7 +312,7 @@ var de = {
634
312
  let t = Object.assign({}, e);
635
313
  return delete t.d, t.key_ops = ["verify"], t;
636
314
  }
637
- }, me = { thumbprint: (e) => async (t, n) => {
315
+ }, b = { thumbprint: (e) => async (t, n) => {
638
316
  let r;
639
317
  switch (t.kty) {
640
318
  case "EC":
@@ -645,483 +323,63 @@ var de = {
645
323
  break;
646
324
  default: throw Error("Unknown or not implemented JWK type");
647
325
  }
648
- let i = await e.crypto.subtle.digest(n, se(r));
649
- return z(new Uint8Array(i));
650
- } }, he = (e) => async (t) => await pe.generate(e)(t), ge = (e) => (t) => async (n, r = "POST", i, a = {}) => {
326
+ let i = await e.crypto.subtle.digest(n, f(r));
327
+ return h(new Uint8Array(i));
328
+ } }, x = (e) => async (t) => await y.generate(e)(t), S = (e) => (t) => async (n, r = "POST", i, a = {}) => {
651
329
  let o = {
652
- jti: btoa(_e()),
330
+ jti: btoa(C()),
653
331
  htm: r,
654
332
  htu: i,
655
333
  iat: Math.round(Date.now() / 1e3),
656
334
  ...a
657
- }, s = await me.thumbprint(e)(n, t.digestAlgorithm);
658
- return await fe.sign(e)(n, { kid: s }, o, t);
659
- }, _e = () => {
335
+ }, s = await b.thumbprint(e)(n, t.digestAlgorithm);
336
+ return await v.sign(e)(n, { kid: s }, o, t);
337
+ }, C = () => {
660
338
  let e = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx", t = "0123456789abcdef", n = 0, r = "";
661
339
  for (let i = 0; i < 36; i++) e[i] !== "-" && e[i] !== "4" && (n = Math.random() * 16 | 0), e[i] === "x" ? r += t[n] : e[i] === "y" ? (n &= 3, n |= 8, r += t[n]) : r += e[i];
662
340
  return r;
663
- }, ve = () => {
341
+ }, w = () => {
664
342
  let e = typeof window < "u" && !!window.crypto;
665
343
  return {
666
344
  hasCrypto: e,
667
345
  hasSubtleCrypto: e && !!window.crypto.subtle
668
346
  };
669
- }, ye = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", be = (e) => {
347
+ }, T = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", E = (e) => {
670
348
  let t = [];
671
349
  for (let n = 0; n < e.byteLength; n += 1) {
672
350
  let r = e[n] % 62;
673
- t.push(ye[r]);
351
+ t.push(T[r]);
674
352
  }
675
353
  return t.join("");
676
- }, B = (e) => {
677
- let t = new Uint8Array(e), { hasCrypto: n } = ve();
354
+ }, D = (e) => {
355
+ let t = new Uint8Array(e), { hasCrypto: n } = w();
678
356
  if (n) window.crypto.getRandomValues(t);
679
357
  else for (let n = 0; n < e; n += 1) t[n] = Math.random() * 62 | 0;
680
- return be(t);
358
+ return E(t);
681
359
  };
682
- function xe(e) {
360
+ function ee(e) {
683
361
  let t = new ArrayBuffer(e.length), n = new Uint8Array(t);
684
362
  for (let t = 0; t < e.length; t++) n[t] = e.charCodeAt(t);
685
363
  return n;
686
364
  }
687
- function Se(e) {
365
+ function te(e) {
688
366
  return new Promise((t, n) => {
689
- crypto.subtle.digest("SHA-256", xe(e)).then((e) => t(z(new Uint8Array(e))), (e) => n(e));
367
+ crypto.subtle.digest("SHA-256", ee(e)).then((e) => t(h(new Uint8Array(e))), (e) => n(e));
690
368
  });
691
369
  }
692
- var Ce = (e) => {
370
+ var ne = (e) => {
693
371
  if (e.length < 43 || e.length > 128) return Promise.reject(/* @__PURE__ */ Error("Invalid code length."));
694
- let { hasSubtleCrypto: t } = ve();
695
- return t ? Se(e) : Promise.reject(/* @__PURE__ */ Error("window.crypto.subtle is unavailable."));
696
- }, we = 3600, Te = (e) => async (t, n = we, r = window.sessionStorage, i = 1e4) => {
697
- let a = `${t}/.well-known/openid-configuration`, o = `oidc.server:${t}`, s = ae(o, r, n);
698
- if (s) return new Z(s);
699
- let c = await V(e)(a, {}, i);
700
- if (c.status !== 200) return null;
701
- let l = await c.json();
702
- return oe(o, l, r), new Z(l);
703
- }, V = (e) => async (t, n = {}, r = 1e4, i = 0) => {
704
- let a;
705
- try {
706
- let i = new AbortController();
707
- setTimeout(() => i.abort(), r), a = await e(t, {
708
- ...n,
709
- signal: i.signal
710
- });
711
- } catch (a) {
712
- if (a.name === "AbortError" || a.message === "Network request failed") {
713
- if (i <= 1) return await V(e)(t, n, r, i + 1);
714
- throw a;
715
- } else throw console.error(a.message), a;
716
- }
717
- return a;
718
- }, H = {
719
- refresh_token: "refresh_token",
720
- access_token: "access_token"
721
- }, Ee = (e) => async (t, n, r = H.refresh_token, i, a = {}, o = 1e4) => {
722
- let s = {
723
- token: n,
724
- token_type_hint: r,
725
- client_id: i
726
- };
727
- for (let [e, t] of Object.entries(a)) s[e] === void 0 && (s[e] = t);
728
- let c = [];
729
- for (let e in s) {
730
- let t = encodeURIComponent(e), n = encodeURIComponent(s[e]);
731
- c.push(`${t}=${n}`);
732
- }
733
- let l = c.join("&");
734
- return (await V(e)(t, {
735
- method: "POST",
736
- headers: { "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8" },
737
- body: l
738
- }, o)).status === 200 ? { success: !0 } : { success: !1 };
739
- }, De = (e) => async (t, n, r, i, a = {}, o, s = 1e4) => {
740
- for (let [e, t] of Object.entries(r)) n[e] === void 0 && (n[e] = t);
741
- let c = [];
742
- for (let e in n) {
743
- let t = encodeURIComponent(e), r = encodeURIComponent(n[e]);
744
- c.push(`${t}=${r}`);
745
- }
746
- let l = c.join("&"), u = await V(e)(t, {
747
- method: "POST",
748
- headers: {
749
- "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
750
- ...a
372
+ let { hasSubtleCrypto: t } = w();
373
+ return t ? te(e) : Promise.reject(/* @__PURE__ */ Error("window.crypto.subtle is unavailable."));
374
+ }, re = (e) => !!(e.os === "iOS" && e.osVersion.startsWith("12") || e.os === "Mac OS X" && e.osVersion.startsWith("10_15_6")), ie = (e) => {
375
+ let t = e.appVersion, n = e.userAgent, r = "-", i = [
376
+ {
377
+ s: "Windows 10",
378
+ r: /(Windows 10.0|Windows NT 10.0)/
751
379
  },
752
- body: l
753
- }, s);
754
- if (u.status !== 200) return {
755
- success: !1,
756
- status: u.status,
757
- demonstratingProofOfPossessionNonce: null
758
- };
759
- let d = await u.json(), f = null;
760
- return u.headers.has(U) && (f = u.headers.get(U)), {
761
- success: !0,
762
- status: u.status,
763
- data: _(d, i, o),
764
- demonstratingProofOfPossessionNonce: f
765
- };
766
- }, Oe = (e, t) => async (n, r) => {
767
- r = r ? { ...r } : {};
768
- let i = B(128), a = await Ce(i);
769
- await e.setCodeVerifierAsync(i), await e.setStateAsync(r.state), r.code_challenge = a, r.code_challenge_method = "S256";
770
- let o = "";
771
- if (r) for (let [e, t] of Object.entries(r)) o === "" ? o += "?" : o += "&", o += `${e}=${encodeURIComponent(t)}`;
772
- t.open(`${n}${o}`);
773
- }, U = "DPoP-Nonce", ke = (e) => async (t, n, r, i, a = 1e4) => {
774
- n = n ? { ...n } : {}, n.code_verifier = await e.getCodeVerifierAsync();
775
- let o = [];
776
- for (let e in n) {
777
- let t = encodeURIComponent(e), r = encodeURIComponent(n[e]);
778
- o.push(`${t}=${r}`);
779
- }
780
- let s = o.join("&"), c = await V(fetch)(t, {
781
- method: "POST",
782
- headers: {
783
- "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
784
- ...r
785
- },
786
- body: s
787
- }, a);
788
- if (await Promise.all([e.setCodeVerifierAsync(null), e.setStateAsync(null)]), c.status !== 200) return {
789
- success: !1,
790
- status: c.status
791
- };
792
- let l = null;
793
- c.headers.has(U) && (l = c.headers.get(U));
794
- let u = await c.json();
795
- return {
796
- success: !0,
797
- data: {
798
- state: n.state,
799
- tokens: _(u, null, i),
800
- demonstratingProofOfPossessionNonce: l
801
- }
802
- };
803
- };
804
- //#endregion
805
- //#region src/renewTokens.ts
806
- async function Ae(e, t, n, r = null) {
807
- let { tokens: i, status: a } = await q(e)((t) => {
808
- e.tokens = t;
809
- }, 0, 0, t, n, r);
810
- return await L(e.configuration, e.configurationName) || c(e.configurationName, e.configuration.storage, e.configuration.login_state_storage ?? e.configuration.storage).setTokens(e.tokens), e.tokens ? i : (await e.destroyAsync(a), null);
811
- }
812
- async function je(e, t = !1, n = null, r = null) {
813
- let i = e.configuration, a = `${i.client_id}_${e.configurationName}_${i.authority}`, o, s = await L(e.configuration, e.configurationName);
814
- if (i?.storage === window?.sessionStorage && !s || !navigator.locks) o = await Ae(e, t, n, r);
815
- else {
816
- let i = "retry";
817
- for (; i === "retry";) i = await navigator.locks.request(a, { ifAvailable: !0 }, async (i) => i ? await Ae(e, t, n, r) : (e.publishEvent($.eventNames.syncTokensAsync_lock_not_available, { lock: "lock not available" }), "retry"));
818
- o = i;
819
- }
820
- return o ? (e.timeoutId &&= W(e, e.tokens.expiresAt, n, r), e.tokens) : null;
821
- }
822
- var W = (e, t, n = null, r = null) => {
823
- let i = e.configuration.refresh_time_before_tokens_expiration_in_second;
824
- return e.timeoutId && S.clearTimeout(e.timeoutId), S.setTimeout(async () => {
825
- let a = { timeLeft: v(i, t) };
826
- e.publishEvent($.eventNames.token_timer, a), await je(e, !1, n, r);
827
- }, 1e3);
828
- }, G = {
829
- FORCE_REFRESH: "FORCE_REFRESH",
830
- SESSION_LOST: "SESSION_LOST",
831
- NOT_CONNECTED: "NOT_CONNECTED",
832
- TOKENS_VALID: "TOKENS_VALID",
833
- TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID: "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID",
834
- TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID: "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID",
835
- LOGOUT_FROM_ANOTHER_TAB: "LOGOUT_FROM_ANOTHER_TAB",
836
- REQUIRE_SYNC_TOKENS: "REQUIRE_SYNC_TOKENS",
837
- TOKENS_INVALID: "TOKENS_INVALID"
838
- }, K = (e) => async (t, n, r, i = !1) => {
839
- let a = { nonce: null };
840
- if (!r) return {
841
- tokens: null,
842
- status: G.NOT_CONNECTED,
843
- nonce: a
844
- };
845
- let o, s = await e.initAsync(t.authority, t.authority_configuration), l = await L(t, n);
846
- if (l) {
847
- let { status: e, tokens: n } = await l.initAsync(s, "syncTokensAsync", t);
848
- if (e === "LOGGED_OUT") return {
849
- tokens: null,
850
- status: G.LOGOUT_FROM_ANOTHER_TAB,
851
- nonce: a
852
- };
853
- if (e === "SESSIONS_LOST") return {
854
- tokens: null,
855
- status: G.SESSION_LOST,
856
- nonce: a
857
- };
858
- if (!e || !n) return {
859
- tokens: null,
860
- status: G.REQUIRE_SYNC_TOKENS,
861
- nonce: a
862
- };
863
- if (n.issuedAt !== r.issuedAt) return {
864
- tokens: n,
865
- status: v(t.refresh_time_before_tokens_expiration_in_second, n.expiresAt) > 0 ? G.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID : G.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID,
866
- nonce: await l.getNonceAsync()
867
- };
868
- o = await l.getNonceAsync();
869
- } else {
870
- let i = c(n, t.storage ?? sessionStorage, t.login_state_storage ?? t.storage ?? sessionStorage), s = await i.initAsync(), { tokens: l } = s, { status: u } = s;
871
- if (l &&= g(l, e.tokens, t.token_renew_mode), !l) return {
872
- tokens: null,
873
- status: G.LOGOUT_FROM_ANOTHER_TAB,
874
- nonce: a
875
- };
876
- if (u === "SESSIONS_LOST") return {
877
- tokens: null,
878
- status: G.SESSION_LOST,
879
- nonce: a
880
- };
881
- if (l.issuedAt !== r.issuedAt) {
882
- let e = v(t.refresh_time_before_tokens_expiration_in_second, l.expiresAt) > 0 ? G.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID : G.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID, n = await i.getNonceAsync();
883
- return {
884
- tokens: l,
885
- status: e,
886
- nonce: n
887
- };
888
- }
889
- o = await i.getNonceAsync();
890
- }
891
- let u = v(t.refresh_time_before_tokens_expiration_in_second, r.expiresAt) > 0 ? "TOKENS_VALID" : "TOKENS_INVALID";
892
- return i ? {
893
- tokens: r,
894
- status: "FORCE_REFRESH",
895
- nonce: o
896
- } : {
897
- tokens: r,
898
- status: u,
899
- nonce: o
900
- };
901
- }, q = (e) => async (t, n = 0, r = 0, a = !1, o = null, s = null) => {
902
- if (!navigator.onLine && document.hidden) return {
903
- tokens: e.tokens,
904
- status: "GIVE_UP"
905
- };
906
- let u = 6, d = a ? 2 : 5;
907
- for (; !navigator.onLine && u > 0;) await E({ milliseconds: 1e3 }), u--, e.publishEvent(i.refreshTokensAsync, { message: `wait because navigator is offline try ${u}` });
908
- let f = document.hidden, p = f ? n : n + 1, m = f ? r + 1 : r;
909
- if (n >= d || r >= 5) return t(null), e.publishEvent(i.refreshTokensAsync_error, { message: "refresh token" }), {
910
- tokens: null,
911
- status: "SESSION_LOST"
912
- };
913
- o ||= {};
914
- let h = e.configuration, g = (t, n = null, r = null) => J(e.configurationName, e.configuration, e.publishEvent.bind(e))(t, n, r), _ = async () => {
915
- try {
916
- let n, r = await L(h, e.configurationName);
917
- n = r ? r.getLoginParams() : c(e.configurationName, h.storage, h.login_state_storage ?? h.storage).getLoginParams();
918
- let a = {};
919
- if (n && n.extras) for (let [e, t] of Object.entries(n.extras)) t != null && (a[e] = t);
920
- if (o) for (let [e, t] of Object.entries(o)) t != null && (a[e] = t);
921
- a.prompt = "none", s && (a.scope = s);
922
- let l = await g(a);
923
- return l ? l.error ? (t(null), e.publishEvent(i.refreshTokensAsync_error, { message: "refresh token silent" }), {
924
- tokens: null,
925
- status: "SESSION_LOST"
926
- }) : (t(l.tokens), e.publishEvent($.eventNames.token_renewed, {}), {
927
- tokens: l.tokens,
928
- status: "LOGGED"
929
- }) : (t(null), e.publishEvent(i.refreshTokensAsync_error, { message: "refresh token silent not active" }), {
930
- tokens: null,
931
- status: "SESSION_LOST"
932
- });
933
- } catch (n) {
934
- return console.error(n), e.publishEvent(i.refreshTokensAsync_silent_error, {
935
- message: "exceptionSilent",
936
- exception: n.message
937
- }), await q(e)(t, p, m, a, o, s);
938
- }
939
- };
940
- try {
941
- let { status: u, tokens: d, nonce: f } = await K(e)(h, e.configurationName, e.tokens, a);
942
- switch (u) {
943
- case G.SESSION_LOST: return t(null), e.publishEvent(i.refreshTokensAsync_error, { message: "refresh token session lost" }), {
944
- tokens: null,
945
- status: "SESSION_LOST"
946
- };
947
- case G.NOT_CONNECTED: return t(null), {
948
- tokens: null,
949
- status: null
950
- };
951
- case G.TOKENS_VALID: return t(d), {
952
- tokens: d,
953
- status: "LOGGED_IN"
954
- };
955
- case G.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID: return t(d), e.publishEvent($.eventNames.token_renewed, { reason: "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID" }), {
956
- tokens: d,
957
- status: "LOGGED_IN"
958
- };
959
- case G.LOGOUT_FROM_ANOTHER_TAB: return t(null), e.publishEvent(i.logout_from_another_tab, { status: "session syncTokensAsync" }), {
960
- tokens: null,
961
- status: "LOGGED_OUT"
962
- };
963
- case G.REQUIRE_SYNC_TOKENS: return h.token_automatic_renew_mode == l.AutomaticOnlyWhenFetchExecuted && !a ? (e.publishEvent(i.tokensInvalidAndWaitingActionsToRefresh, {}), {
964
- tokens: e.tokens,
965
- status: "GIVE_UP"
966
- }) : (e.publishEvent(i.refreshTokensAsync_begin, { tryNumber: n }), await _());
967
- default: {
968
- if (h.token_automatic_renew_mode == l.AutomaticOnlyWhenFetchExecuted && G.FORCE_REFRESH !== u) return e.publishEvent(i.tokensInvalidAndWaitingActionsToRefresh, {}), {
969
- tokens: e.tokens,
970
- status: "GIVE_UP"
971
- };
972
- if (e.publishEvent(i.refreshTokensAsync_begin, {
973
- refreshToken: d.refreshToken,
974
- status: u,
975
- tryNumber: n,
976
- backgroundTry: r
977
- }), !d.refreshToken) return await _();
978
- let g = h.client_id, v = h.redirect_uri, y = h.authority, b = { ...h.token_request_extras ? h.token_request_extras : {} };
979
- for (let [e, t] of Object.entries(o)) e.endsWith(":token_request") && (b[e.replace(":token_request", "")] = t);
980
- return await (async () => {
981
- let n = {
982
- client_id: g,
983
- redirect_uri: v,
984
- grant_type: "refresh_token",
985
- refresh_token: d.refreshToken
986
- }, r = await e.initAsync(y, h.authority_configuration), l = document.hidden ? 1e4 : 3e4 * 10, u = r.tokenEndpoint, _ = {};
987
- h.demonstrating_proof_of_possession && (_.DPoP = await e.generateDemonstrationOfProofOfPossessionAsync(d.accessToken, u, "POST"));
988
- let S = await De(e.getFetch())(u, n, b, d, _, h.token_renew_mode, l);
989
- if (S.success) {
990
- let { isValid: n, reason: a } = x(S.data, f.nonce, r);
991
- if (!n) return t(null), e.publishEvent(i.refreshTokensAsync_error, { message: `refresh token return not valid tokens, reason: ${a}` }), {
992
- tokens: null,
993
- status: "SESSION_LOST"
994
- };
995
- if (t(S.data), S.demonstratingProofOfPossessionNonce) {
996
- let t = await L(h, e.configurationName);
997
- t ? await t.setDemonstratingProofOfPossessionNonce(S.demonstratingProofOfPossessionNonce) : await c(e.configurationName, h.storage, h.login_state_storage ?? h.storage).setDemonstratingProofOfPossessionNonce(S.demonstratingProofOfPossessionNonce);
998
- }
999
- return e.publishEvent(i.refreshTokensAsync_end, { success: S.success }), e.publishEvent($.eventNames.token_renewed, { reason: "REFRESH_TOKEN" }), {
1000
- tokens: S.data,
1001
- status: "LOGGED_IN"
1002
- };
1003
- } else return e.publishEvent(i.refreshTokensAsync_silent_error, {
1004
- message: "bad request",
1005
- tokenResponse: S
1006
- }), S.status >= 400 && S.status < 500 ? (t(null), e.publishEvent(i.refreshTokensAsync_error, { message: `session lost: ${S.status}` }), {
1007
- tokens: null,
1008
- status: "SESSION_LOST"
1009
- }) : await q(e)(t, p, m, a, o, s);
1010
- })();
1011
- }
1012
- }
1013
- } catch (n) {
1014
- return console.error(n), e.publishEvent(i.refreshTokensAsync_silent_error, {
1015
- message: "exception",
1016
- exception: n.message
1017
- }), new Promise((n, r) => {
1018
- setTimeout(() => {
1019
- q(e)(t, p, m, a, o, s).then(n).catch(r);
1020
- }, 1e3);
1021
- });
1022
- }
1023
- }, J = (e, t, n) => (r = null, a = null, o = null) => {
1024
- if (!t.silent_redirect_uri || !t.silent_login_uri) return Promise.resolve(null);
1025
- try {
1026
- n(i.silentLoginAsync_begin, {});
1027
- let s = "";
1028
- if (a && (r ??= {}, r.state = a), o != null && (r ??= {}, r.scope = o), r != null) for (let [e, t] of Object.entries(r)) t != null && (s === "" ? s = `?${encodeURIComponent(e)}=${encodeURIComponent(t)}` : s += `&${encodeURIComponent(e)}=${encodeURIComponent(t)}`);
1029
- let c = t.silent_login_uri + s, l = c.indexOf("/", c.indexOf("//") + 2), u = c.substring(0, l), d = document.createElement("iframe");
1030
- return d.width = "0px", d.height = "0px", d.id = `${e}_oidc_iframe`, d.setAttribute("src", c), d.style.display = "none", document.body.appendChild(d), new Promise((r, a) => {
1031
- let o = !1, s = () => {
1032
- window.removeEventListener("message", c), d.remove(), o = !0;
1033
- }, c = (t) => {
1034
- if (t.origin === u && t.source === d.contentWindow) {
1035
- let c = `${e}_oidc_tokens:`, l = `${e}_oidc_error:`, u = `${e}_oidc_exception:`, d = t.data;
1036
- if (d && typeof d == "string" && !o) {
1037
- if (d.startsWith(c)) {
1038
- let e = JSON.parse(t.data.replace(c, ""));
1039
- n(i.silentLoginAsync_end, {}), r(e), s();
1040
- } else if (d.startsWith(l)) {
1041
- let e = JSON.parse(t.data.replace(l, ""));
1042
- n(i.silentLoginAsync_error, e), r({
1043
- error: "oidc_" + e.error,
1044
- tokens: null,
1045
- sessionState: null
1046
- }), s();
1047
- } else if (d.startsWith(u)) {
1048
- let e = JSON.parse(t.data.replace(u, ""));
1049
- n(i.silentLoginAsync_error, e), a(Error(e.error)), s();
1050
- }
1051
- }
1052
- }
1053
- };
1054
- try {
1055
- window.addEventListener("message", c);
1056
- let e = t.silent_login_timeout;
1057
- setTimeout(() => {
1058
- o || (s(), n(i.silentLoginAsync_error, { reason: "timeout" }), a(/* @__PURE__ */ Error("timeout")));
1059
- }, e);
1060
- } catch (e) {
1061
- s(), n(i.silentLoginAsync_error, e), a(e);
1062
- }
1063
- });
1064
- } catch (e) {
1065
- throw n(i.silentLoginAsync_error, e), e;
1066
- }
1067
- }, Me = (e, t, n, r, a) => (e = null, o = void 0) => {
1068
- e = { ...e };
1069
- let s = (e, i, o) => J(t, n, r.bind(a))(e, i, o);
1070
- return (async () => {
1071
- a.timeoutId && S.clearTimeout(a.timeoutId);
1072
- let t;
1073
- e && "state" in e && (t = e.state, delete e.state);
1074
- try {
1075
- let c = await s({
1076
- ...n.extras ? {
1077
- ...n.extras,
1078
- ...e
1079
- } : e,
1080
- prompt: "none"
1081
- }, t, o);
1082
- if (c) return a.tokens = c.tokens, r(i.token_acquired, {}), a.timeoutId = W(a, a.tokens.expiresAt, e, o), {};
1083
- } catch (e) {
1084
- return e;
1085
- }
1086
- })();
1087
- }, Ne = (e, t, n) => (i, a, o, s = !1) => {
1088
- let c = (t, r = void 0, i = void 0) => J(e.configurationName, n, e.publishEvent.bind(e))(t, r, i);
1089
- return new Promise((l, u) => {
1090
- n.silent_login_uri && n.silent_redirect_uri && n.monitor_session && i && o && !s ? (e.checkSessionIFrame = new r(() => {
1091
- e.checkSessionIFrame.stop();
1092
- let r = e.tokens;
1093
- if (r === null) return;
1094
- let i = r.idToken, a = r.idTokenPayload;
1095
- return c({
1096
- prompt: "none",
1097
- id_token_hint: i,
1098
- scope: n.scope || "openid"
1099
- }).then((t) => {
1100
- if (t.error) throw Error(t.error);
1101
- let n = t.tokens.idTokenPayload;
1102
- if (a.sub === n.sub) {
1103
- let r = t.sessionState;
1104
- e.checkSessionIFrame.start(t.sessionState), a.sid === n.sid ? console.debug("SessionMonitor._callback: Same sub still logged in at OP, restarting check session iframe; session_state:", r) : console.debug("SessionMonitor._callback: Same sub still logged in at OP, session state has changed, restarting check session iframe; session_state:", r);
1105
- } else console.debug("SessionMonitor._callback: Different subject signed into OP:", n.sub);
1106
- }).catch(async (e) => {
1107
- console.warn("SessionMonitor._callback: Silent login failed, logging out other tabs:", e);
1108
- for (let [, e] of Object.entries(t)) await e.logoutOtherTabAsync(n.client_id, a.sub);
1109
- });
1110
- }, a, i), e.checkSessionIFrame.load().then(() => {
1111
- e.checkSessionIFrame.start(o), l(e.checkSessionIFrame);
1112
- }).catch((e) => {
1113
- u(e);
1114
- })) : l(null);
1115
- });
1116
- }, Pe = (e) => !!(e.os === "iOS" && e.osVersion.startsWith("12") || e.os === "Mac OS X" && e.osVersion.startsWith("10_15_6")), Fe = (e) => {
1117
- let t = e.appVersion, n = e.userAgent, r = "-", i = [
1118
- {
1119
- s: "Windows 10",
1120
- r: /(Windows 10.0|Windows NT 10.0)/
1121
- },
1122
- {
1123
- s: "Windows 8.1",
1124
- r: /(Windows 8.1|Windows NT 6.3)/
380
+ {
381
+ s: "Windows 8.1",
382
+ r: /(Windows 8.1|Windows NT 6.3)/
1125
383
  },
1126
384
  {
1127
385
  s: "Windows 8",
@@ -1249,7 +507,7 @@ var W = (e, t, n = null, r = null) => {
1249
507
  osVersion: a
1250
508
  };
1251
509
  };
1252
- function Ie() {
510
+ function ae() {
1253
511
  let e = navigator.userAgent, t, n = e.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
1254
512
  if (/trident/i.test(n[1])) return t = /\brv[ :]+(\d+)/g.exec(e) || [], {
1255
513
  name: "ie",
@@ -1275,53 +533,193 @@ function Ie() {
1275
533
  version: n[1]
1276
534
  };
1277
535
  }
1278
- var Le = () => {
1279
- let { name: e, version: t } = Ie();
1280
- return e === "chrome" && parseInt(t) <= 70 || e === "opera" && (!t || parseInt(t.split(".")[0]) < 80) || e === "ie" ? !1 : !Pe(Fe(navigator));
1281
- }, Re = async (e) => {
1282
- let t;
1283
- if (e.tokens != null) return !1;
1284
- e.publishEvent(i.tryKeepExistingSessionAsync_begin, {});
536
+ var oe = () => {
537
+ let { name: e, version: t } = ae();
538
+ return e === "chrome" && parseInt(t) <= 70 || e === "opera" && (!t || parseInt(t.split(".")[0]) < 80) || e === "ie" ? !1 : !re(ie(navigator));
539
+ }, se = async (t) => {
540
+ let n;
541
+ if (t.tokens != null) return !1;
542
+ t.publishEvent(e.tryKeepExistingSessionAsync_begin, {});
1285
543
  try {
1286
- let n = e.configuration, r = await e.initAsync(n.authority, n.authority_configuration);
1287
- if (t = await L(n, e.configurationName), t) {
1288
- let { tokens: a } = await t.initAsync(r, "tryKeepExistingSessionAsync", n);
1289
- if (a) {
1290
- t.startKeepAliveServiceWorker(), e.tokens = a;
1291
- let o = t.getLoginParams(e.configurationName);
1292
- e.timeoutId = W(e, e.tokens.expiresAt, o.extras, o.scope);
1293
- let s = await t.getSessionStateAsync();
1294
- return await e.startCheckSessionAsync(r.checkSessionIframe, n.client_id, s), n.preload_user_info && await e.userInfoAsync(), e.publishEvent(i.tryKeepExistingSessionAsync_end, {
544
+ let r = t.configuration, a = await t.initAsync(r.authority, r.authority_configuration);
545
+ if (n = await $(r, t.configurationName), n) {
546
+ let { tokens: i } = await n.initAsync(a, "tryKeepExistingSessionAsync", r);
547
+ if (i) {
548
+ n.startKeepAliveServiceWorker(), t.tokens = i;
549
+ let o = n.getLoginParams(t.configurationName);
550
+ t.timeoutId = z(t, t.tokens.expiresAt, o.extras, o.scope);
551
+ let s = await n.getSessionStateAsync();
552
+ return await t.startCheckSessionAsync(a.checkSessionIframe, r.client_id, s), r.preload_user_info && await t.userInfoAsync(), t.publishEvent(e.tryKeepExistingSessionAsync_end, {
1295
553
  success: !0,
1296
554
  message: "tokens inside ServiceWorker are valid"
1297
555
  }), !0;
1298
556
  }
1299
- e.publishEvent(i.tryKeepExistingSessionAsync_end, {
557
+ t.publishEvent(e.tryKeepExistingSessionAsync_end, {
1300
558
  success: !1,
1301
559
  message: "no exiting session found"
1302
560
  });
1303
561
  } else {
1304
- n.service_worker_relative_url && e.publishEvent(i.service_worker_not_supported_by_browser, { message: "service worker is not supported by this browser" });
1305
- let t = c(e.configurationName, n.storage ?? sessionStorage, n.login_state_storage ?? n.storage ?? sessionStorage), { tokens: a } = await t.initAsync();
1306
- if (a) {
1307
- e.tokens = g(a, null, n.token_renew_mode);
1308
- let o = t.getLoginParams();
1309
- e.timeoutId = W(e, e.tokens.expiresAt, o.extras, o.scope);
1310
- let s = await t.getSessionStateAsync();
1311
- return await e.startCheckSessionAsync(r.checkSessionIframe, n.client_id, s), n.preload_user_info && await e.userInfoAsync(), e.publishEvent(i.tryKeepExistingSessionAsync_end, {
562
+ r.service_worker_relative_url && t.publishEvent(e.service_worker_not_supported_by_browser, { message: "service worker is not supported by this browser" });
563
+ let n = i(t.configurationName, r.storage ?? sessionStorage, r.login_state_storage ?? r.storage ?? sessionStorage), { tokens: o } = await n.initAsync();
564
+ if (o) {
565
+ t.tokens = W(o, null, r.token_renew_mode);
566
+ let i = n.getLoginParams();
567
+ t.timeoutId = z(t, t.tokens.expiresAt, i.extras, i.scope);
568
+ let s = await n.getSessionStateAsync();
569
+ return await t.startCheckSessionAsync(a.checkSessionIframe, r.client_id, s), r.preload_user_info && await t.userInfoAsync(), t.publishEvent(e.tryKeepExistingSessionAsync_end, {
1312
570
  success: !0,
1313
571
  message: "tokens inside storage are valid"
1314
572
  }), !0;
1315
573
  }
1316
574
  }
1317
- return e.publishEvent(i.tryKeepExistingSessionAsync_end, {
575
+ return t.publishEvent(e.tryKeepExistingSessionAsync_end, {
1318
576
  success: !1,
1319
- message: t ? "service worker sessions not retrieved" : "session storage sessions not retrieved"
577
+ message: n ? "service worker sessions not retrieved" : "session storage sessions not retrieved"
1320
578
  }), !1;
1321
- } catch (n) {
1322
- return console.error(n), t && await t.clearAsync(), e.publishEvent(i.tryKeepExistingSessionAsync_error, "tokens inside ServiceWorker are invalid"), !1;
579
+ } catch (r) {
580
+ return console.error(r), n && await n.clearAsync(), t.publishEvent(e.tryKeepExistingSessionAsync_error, "tokens inside ServiceWorker are invalid"), !1;
581
+ }
582
+ }, O = class {
583
+ open(e) {
584
+ window.location.href = e;
585
+ }
586
+ reload() {
587
+ window.location.reload();
588
+ }
589
+ getCurrentHref() {
590
+ return window.location.href;
1323
591
  }
1324
- }, ze = (e) => {
592
+ getPath() {
593
+ let e = window.location;
594
+ return e.pathname + (e.search || "") + (e.hash || "");
595
+ }
596
+ getOrigin() {
597
+ return window.origin;
598
+ }
599
+ }, k = {}, ce = (e, t = window.sessionStorage, n) => {
600
+ if (!k[e] && t) {
601
+ let n = t.getItem(e);
602
+ n && (k[e] = JSON.parse(n));
603
+ }
604
+ let r = 1e3 * n;
605
+ return k[e] && k[e].timestamp + r > Date.now() ? k[e].result : null;
606
+ }, le = (e, t, n = window.sessionStorage) => {
607
+ let r = Date.now();
608
+ k[e] = {
609
+ result: t,
610
+ timestamp: r
611
+ }, n && n.setItem(e, JSON.stringify({
612
+ result: t,
613
+ timestamp: r
614
+ }));
615
+ }, ue = 3600, de = (e) => async (t, n = ue, r = window.sessionStorage, i = 1e4) => {
616
+ let a = `${t}/.well-known/openid-configuration`, o = `oidc.server:${t}`, s = ce(o, r, n);
617
+ if (s) return new I(s);
618
+ let c = await A(e)(a, {}, i);
619
+ if (c.status !== 200) return null;
620
+ let l = await c.json();
621
+ return le(o, l, r), new I(l);
622
+ }, A = (e) => async (t, n = {}, r = 1e4, i = 0) => {
623
+ let a;
624
+ try {
625
+ let i = new AbortController();
626
+ setTimeout(() => i.abort(), r), a = await e(t, {
627
+ ...n,
628
+ signal: i.signal
629
+ });
630
+ } catch (a) {
631
+ if (a.name === "AbortError" || a.message === "Network request failed") {
632
+ if (i <= 1) return await A(e)(t, n, r, i + 1);
633
+ throw a;
634
+ } else throw console.error(a.message), a;
635
+ }
636
+ return a;
637
+ }, j = {
638
+ refresh_token: "refresh_token",
639
+ access_token: "access_token"
640
+ }, fe = (e) => async (t, n, r = j.refresh_token, i, a = {}, o = 1e4) => {
641
+ let s = {
642
+ token: n,
643
+ token_type_hint: r,
644
+ client_id: i
645
+ };
646
+ for (let [e, t] of Object.entries(a)) s[e] === void 0 && (s[e] = t);
647
+ let c = [];
648
+ for (let e in s) {
649
+ let t = encodeURIComponent(e), n = encodeURIComponent(s[e]);
650
+ c.push(`${t}=${n}`);
651
+ }
652
+ let l = c.join("&");
653
+ return (await A(e)(t, {
654
+ method: "POST",
655
+ headers: { "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8" },
656
+ body: l
657
+ }, o)).status === 200 ? { success: !0 } : { success: !1 };
658
+ }, pe = (e) => async (t, n, r, i, a = {}, o, s = 1e4) => {
659
+ for (let [e, t] of Object.entries(r)) n[e] === void 0 && (n[e] = t);
660
+ let c = [];
661
+ for (let e in n) {
662
+ let t = encodeURIComponent(e), r = encodeURIComponent(n[e]);
663
+ c.push(`${t}=${r}`);
664
+ }
665
+ let l = c.join("&"), u = await A(e)(t, {
666
+ method: "POST",
667
+ headers: {
668
+ "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
669
+ ...a
670
+ },
671
+ body: l
672
+ }, s);
673
+ if (u.status !== 200) return {
674
+ success: !1,
675
+ status: u.status,
676
+ demonstratingProofOfPossessionNonce: null
677
+ };
678
+ let d = await u.json(), f = null;
679
+ return u.headers.has(M) && (f = u.headers.get(M)), {
680
+ success: !0,
681
+ status: u.status,
682
+ data: G(d, i, o),
683
+ demonstratingProofOfPossessionNonce: f
684
+ };
685
+ }, me = (e, t) => async (n, r) => {
686
+ r = r ? { ...r } : {};
687
+ let i = D(128), a = await ne(i);
688
+ await e.setCodeVerifierAsync(i), await e.setStateAsync(r.state), r.code_challenge = a, r.code_challenge_method = "S256";
689
+ let o = "";
690
+ if (r) for (let [e, t] of Object.entries(r)) o === "" ? o += "?" : o += "&", o += `${e}=${encodeURIComponent(t)}`;
691
+ t.open(`${n}${o}`);
692
+ }, M = "DPoP-Nonce", he = (e) => async (t, n, r, i, a = 1e4) => {
693
+ n = n ? { ...n } : {}, n.code_verifier = await e.getCodeVerifierAsync();
694
+ let o = [];
695
+ for (let e in n) {
696
+ let t = encodeURIComponent(e), r = encodeURIComponent(n[e]);
697
+ o.push(`${t}=${r}`);
698
+ }
699
+ let s = o.join("&"), c = await A(fetch)(t, {
700
+ method: "POST",
701
+ headers: {
702
+ "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
703
+ ...r
704
+ },
705
+ body: s
706
+ }, a);
707
+ if (await Promise.all([e.setCodeVerifierAsync(null), e.setStateAsync(null)]), c.status !== 200) return {
708
+ success: !1,
709
+ status: c.status
710
+ };
711
+ let l = null;
712
+ c.headers.has(M) && (l = c.headers.get(M));
713
+ let u = await c.json();
714
+ return {
715
+ success: !0,
716
+ data: {
717
+ state: n.state,
718
+ tokens: G(u, null, i),
719
+ demonstratingProofOfPossessionNonce: l
720
+ }
721
+ };
722
+ }, ge = (e) => {
1325
723
  let t = e.match(/^([a-z][\w-]+\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
1326
724
  if (!t) throw Error("Invalid URL");
1327
725
  let n = t[6], r = t[7];
@@ -1339,65 +737,65 @@ var Le = () => {
1339
737
  search: n,
1340
738
  hash: r
1341
739
  };
1342
- }, Be = (e) => {
1343
- let t = ze(e), { path: n } = t;
740
+ }, _e = (e) => {
741
+ let t = ge(e), { path: n } = t;
1344
742
  n.endsWith("/") && (n = n.slice(0, -1));
1345
743
  let { hash: r } = t;
1346
744
  return r === "#_=_" && (r = ""), r && (n += r), n;
1347
- }, Y = (e) => {
1348
- let { search: t } = ze(e);
1349
- return Ve(t);
1350
- }, Ve = (e) => {
745
+ }, N = (e) => {
746
+ let { search: t } = ge(e);
747
+ return ve(t);
748
+ }, ve = (e) => {
1351
749
  let t = {}, n, r, i, a = e.split("&");
1352
750
  for (r = 0, i = a.length; r < i; r++) n = a[r].split("="), t[decodeURIComponent(n[0])] = decodeURIComponent(n[1]);
1353
751
  return t;
1354
- }, He = (e, t, n, r, a) => (o = void 0, s = null, l = !1, u = void 0) => {
1355
- let d = s;
1356
- return s = { ...s }, (async () => {
1357
- let f = o || a.getPath();
1358
- if ("state" in s || (s.state = B(16)), n(i.loginAsync_begin, {}), s) for (let e of Object.keys(s)) e.endsWith(":token_request") && delete s[e];
752
+ }, ye = (t, n, r, a, o) => (s = void 0, c = null, l = !1, u = void 0) => {
753
+ let d = c;
754
+ return c = { ...c }, (async () => {
755
+ let f = s || o.getPath();
756
+ if ("state" in c || (c.state = D(16)), r(e.loginAsync_begin, {}), c) for (let e of Object.keys(c)) e.endsWith(":token_request") && delete c[e];
1359
757
  try {
1360
- let n = l ? t.silent_redirect_uri : t.redirect_uri;
1361
- u ||= t.scope;
1362
- let i = t.extras ? {
1363
- ...t.extras,
1364
- ...s
1365
- } : s;
1366
- i.nonce ||= B(12);
1367
- let o = { nonce: i.nonce }, p = await L(t, e), m = await r(t.authority, t.authority_configuration), h;
758
+ let e = l ? n.silent_redirect_uri : n.redirect_uri;
759
+ u ||= n.scope;
760
+ let r = n.extras ? {
761
+ ...n.extras,
762
+ ...c
763
+ } : c;
764
+ r.nonce ||= D(12);
765
+ let s = { nonce: r.nonce }, p = await $(n, t), m = await a(n.authority, n.authority_configuration), h;
1368
766
  if (p) p.setLoginParams({
1369
767
  callbackPath: f,
1370
768
  extras: d,
1371
769
  scope: u
1372
- }), await p.initAsync(m, "loginAsync", t), await p.setNonceAsync(o), p.startKeepAliveServiceWorker(), h = p;
770
+ }), await p.initAsync(m, "loginAsync", n), await p.setNonceAsync(s), p.startKeepAliveServiceWorker(), h = p;
1373
771
  else {
1374
- let n = c(e, t.storage ?? sessionStorage, t.login_state_storage ?? t.storage ?? sessionStorage);
1375
- n.setLoginParams({
772
+ let e = i(t, n.storage ?? sessionStorage, n.login_state_storage ?? n.storage ?? sessionStorage);
773
+ e.setLoginParams({
1376
774
  callbackPath: f,
1377
775
  extras: d,
1378
776
  scope: u
1379
- }), await n.setNonceAsync(o), h = n;
777
+ }), await e.setNonceAsync(s), h = e;
1380
778
  }
1381
779
  let g = {
1382
- client_id: t.client_id,
1383
- redirect_uri: n,
780
+ client_id: n.client_id,
781
+ redirect_uri: e,
1384
782
  scope: u,
1385
783
  response_type: "code",
1386
- ...i
784
+ ...r
1387
785
  };
1388
- await Oe(h, a)(m.authorizationEndpoint, g);
1389
- } catch (e) {
1390
- throw n(i.loginAsync_error, e), e;
786
+ await me(h, o)(m.authorizationEndpoint, g);
787
+ } catch (t) {
788
+ throw r(e.loginAsync_error, t), t;
1391
789
  }
1392
790
  })();
1393
- }, Ue = (e) => async (t = !1) => {
791
+ }, be = (t) => async (n = !1) => {
1394
792
  try {
1395
- e.publishEvent(i.loginCallbackAsync_begin, {});
1396
- let n = e.configuration, r = n.client_id, a = t ? n.silent_redirect_uri : n.redirect_uri, o = n.authority, s = n.token_request_timeout, l = await e.initAsync(o, n.authority_configuration), u = Y(e.location.getCurrentHref()), d = u.session_state, f = await L(n, e.configurationName), p, m, h, g;
1397
- if (f) await f.initAsync(l, "loginCallbackAsync", n), await f.setSessionStateAsync(d), m = await f.getNonceAsync(), h = f.getLoginParams(), g = await f.getStateAsync(), f.startKeepAliveServiceWorker(), p = f;
793
+ t.publishEvent(e.loginCallbackAsync_begin, {});
794
+ let r = t.configuration, a = r.client_id, o = n ? r.silent_redirect_uri : r.redirect_uri, s = r.authority, c = r.token_request_timeout, l = await t.initAsync(s, r.authority_configuration), u = N(t.location.getCurrentHref()), d = u.session_state, f = await $(r, t.configurationName), p, m, h, g;
795
+ if (f) await f.initAsync(l, "loginCallbackAsync", r), await f.setSessionStateAsync(d), m = await f.getNonceAsync(), h = f.getLoginParams(), g = await f.getStateAsync(), f.startKeepAliveServiceWorker(), p = f;
1398
796
  else {
1399
- let t = c(e.configurationName, n.storage ?? sessionStorage, n.login_state_storage ?? n.storage ?? sessionStorage);
1400
- await t.setSessionStateAsync(d), m = await t.getNonceAsync(), h = t.getLoginParams(), g = await t.getStateAsync(), p = t;
797
+ let e = i(t.configurationName, r.storage ?? sessionStorage, r.login_state_storage ?? r.storage ?? sessionStorage);
798
+ await e.setSessionStateAsync(d), m = await e.getNonceAsync(), h = e.getLoginParams(), g = await e.getStateAsync(), p = e;
1401
799
  }
1402
800
  if (u.error || u.error_description) throw Error(`Error from OIDC server: ${u.error} - ${u.error_description}`);
1403
801
  if (u.iss && u.iss !== l.issuer) throw console.error(), Error(`Issuer not valid (expected: ${l.issuer}, received: ${u.iss})`);
@@ -1405,49 +803,49 @@ var Le = () => {
1405
803
  let _ = {
1406
804
  code: u.code,
1407
805
  grant_type: "authorization_code",
1408
- client_id: n.client_id,
1409
- redirect_uri: a
806
+ client_id: r.client_id,
807
+ redirect_uri: o
1410
808
  }, v = {};
1411
- if (n.token_request_extras) for (let [e, t] of Object.entries(n.token_request_extras)) v[e] = t;
809
+ if (r.token_request_extras) for (let [e, t] of Object.entries(r.token_request_extras)) v[e] = t;
1412
810
  if (h?.extras) for (let [e, t] of Object.entries(h.extras)) e.endsWith(":token_request") && (v[e.replace(":token_request", "")] = t);
1413
811
  let y = l.tokenEndpoint, b = {};
1414
- if (n.demonstrating_proof_of_possession) if (f) b.DPoP = `DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${e.configurationName}`;
812
+ if (r.demonstrating_proof_of_possession) if (f) b.DPoP = `DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${t.configurationName}`;
1415
813
  else {
1416
- let t = await he(window)(n.demonstrating_proof_of_possession_configuration.generateKeyAlgorithm);
1417
- await c(e.configurationName, n.storage, n.login_state_storage ?? n.storage).setDemonstratingProofOfPossessionJwkAsync(t), b.DPoP = await ge(window)(n.demonstrating_proof_of_possession_configuration)(t, "POST", y);
814
+ let e = await x(window)(r.demonstrating_proof_of_possession_configuration.generateKeyAlgorithm);
815
+ await i(t.configurationName, r.storage, r.login_state_storage ?? r.storage).setDemonstratingProofOfPossessionJwkAsync(e), b.DPoP = await S(window)(r.demonstrating_proof_of_possession_configuration)(e, "POST", y);
1418
816
  }
1419
- let S = await ke(p)(y, {
817
+ let C = await he(p)(y, {
1420
818
  ..._,
1421
819
  ...v
1422
- }, b, e.configuration.token_renew_mode, s);
1423
- if (!S.success) throw Error("Token request failed");
1424
- let C, w = S.data.tokens, T = S.data.demonstratingProofOfPossessionNonce;
1425
- if (S.data.state !== v.state) throw Error("state is not valid");
1426
- let { isValid: E, reason: D } = x(w, m.nonce, l);
1427
- if (!E) throw Error(`Tokens are not OpenID valid, reason: ${D}`);
820
+ }, b, t.configuration.token_renew_mode, c);
821
+ if (!C.success) throw Error("Token request failed");
822
+ let w, T = C.data.tokens, E = C.data.demonstratingProofOfPossessionNonce;
823
+ if (C.data.state !== v.state) throw Error("state is not valid");
824
+ let { isValid: D, reason: ee } = Be(T, m.nonce, l);
825
+ if (!D) throw Error(`Tokens are not OpenID valid, reason: ${ee}`);
1428
826
  if (f) {
1429
- if (w.refreshToken && !w.refreshToken.includes("SECURED_BY_OIDC_SERVICE_WORKER")) throw Error("Refresh token should be hidden by service worker");
1430
- if (T && w?.accessToken.includes("SECURED_BY_OIDC_SERVICE_WORKER")) throw Error("Demonstration of proof of possession require Access token not hidden by service worker");
827
+ if (T.refreshToken && !T.refreshToken.includes("SECURED_BY_OIDC_SERVICE_WORKER")) throw Error("Refresh token should be hidden by service worker");
828
+ if (E && T?.accessToken.includes("SECURED_BY_OIDC_SERVICE_WORKER")) throw Error("Demonstration of proof of possession require Access token not hidden by service worker");
1431
829
  }
1432
- if (f) await f.initAsync(l, "syncTokensAsync", n), C = f.getLoginParams(), T && await f.setDemonstratingProofOfPossessionNonce(T);
830
+ if (f) await f.initAsync(l, "syncTokensAsync", r), w = f.getLoginParams(), E && await f.setDemonstratingProofOfPossessionNonce(E);
1433
831
  else {
1434
- let t = c(e.configurationName, n.storage, n.login_state_storage ?? n.storage);
1435
- C = t.getLoginParams(), T && await t.setDemonstratingProofOfPossessionNonce(T);
832
+ let e = i(t.configurationName, r.storage, r.login_state_storage ?? r.storage);
833
+ w = e.getLoginParams(), E && await e.setDemonstratingProofOfPossessionNonce(E);
1436
834
  }
1437
- return await e.startCheckSessionAsync(l.checkSessionIframe, r, d, t), e.publishEvent(i.loginCallbackAsync_end, {}), {
1438
- tokens: w,
835
+ return await t.startCheckSessionAsync(l.checkSessionIframe, a, d, n), t.publishEvent(e.loginCallbackAsync_end, {}), {
836
+ tokens: T,
1439
837
  state: "request.state",
1440
- callbackPath: C.callbackPath,
838
+ callbackPath: w.callbackPath,
1441
839
  scope: u.scope,
1442
- extras: C.extras
840
+ extras: w.extras
1443
841
  };
1444
- } catch (t) {
1445
- throw console.error(t), e.publishEvent(i.loginCallbackAsync_error, t), t;
842
+ } catch (n) {
843
+ throw console.error(n), t.publishEvent(e.loginCallbackAsync_error, n), n;
1446
844
  }
1447
- }, We = {
845
+ }, xe = {
1448
846
  access_token: "access_token",
1449
847
  refresh_token: "refresh_token"
1450
- }, X = (e, t) => {
848
+ }, P = (e, t) => {
1451
849
  let n = {};
1452
850
  if (e) {
1453
851
  for (let [r, i] of Object.entries(e)) if (r.endsWith(t)) {
@@ -1457,64 +855,66 @@ var Le = () => {
1457
855
  return n;
1458
856
  }
1459
857
  return n;
1460
- }, Ge = (e) => {
858
+ }, Se = (e) => {
1461
859
  let t = {};
1462
860
  if (e) {
1463
861
  for (let [n, r] of Object.entries(e)) n.includes(":") || (t[n] = r);
1464
862
  return t;
1465
863
  }
1466
864
  return t;
1467
- }, Ke = (e) => async (t) => {
1468
- S.clearTimeout(e.timeoutId), e.timeoutId = null, e.checkSessionIFrame && e.checkSessionIFrame.stop();
1469
- let n = await L(e.configuration, e.configurationName);
1470
- n ? await n.clearAsync(t) : await c(e.configurationName, e.configuration.storage, e.configuration.login_state_storage ?? e.configuration.storage).clearAsync(t), e.tokens = null, e.userInfo = null;
1471
- }, qe = (e, t, n, r, a) => async (o = void 0, s = null) => {
1472
- let c = e.configuration, l = await e.initAsync(c.authority, c.authority_configuration);
1473
- o && typeof o != "string" && (o = void 0, r.warn("callbackPathOrUrl path is not a string"));
865
+ }, Ce = (e) => async (t) => {
866
+ c.clearTimeout(e.timeoutId), e.timeoutId = null, e.checkSessionIFrame && e.checkSessionIFrame.stop();
867
+ let n = await $(e.configuration, e.configurationName);
868
+ n ? await n.clearAsync(t) : await i(e.configurationName, e.configuration.storage, e.configuration.login_state_storage ?? e.configuration.storage).clearAsync(t), e.tokens = null, e.userInfo = null;
869
+ }, we = (t, n, r, i, a) => async (o = void 0, s = null) => {
870
+ let c = t.configuration, l = await t.initAsync(c.authority, c.authority_configuration);
871
+ o && typeof o != "string" && (o = void 0, i.warn("callbackPathOrUrl path is not a string"));
1474
872
  let u = o ?? a.getPath(), d = !1;
1475
873
  o && (d = o.includes("https://") || o.includes("http://"));
1476
- let f = d ? o : a.getOrigin() + u, p = e.tokens ? e.tokens.idToken : "";
874
+ let f = d ? o : a.getOrigin() + u, p = t.tokens ? t.tokens.idToken : "";
1477
875
  try {
1478
- let t = l.revocationEndpoint;
1479
- if (t) {
1480
- let r = [], i = e.tokens ? e.tokens.accessToken : null;
1481
- if (i && c.logout_tokens_to_invalidate.includes(We.access_token)) {
1482
- let e = X(s, ":revoke_access_token"), a = Ee(n)(t, i, H.access_token, c.client_id, e);
1483
- r.push(a);
876
+ let e = l.revocationEndpoint;
877
+ if (e) {
878
+ let n = [], i = t.tokens ? t.tokens.accessToken : null;
879
+ if (i && c.logout_tokens_to_invalidate.includes(xe.access_token)) {
880
+ let t = P(s, ":revoke_access_token"), a = fe(r)(e, i, j.access_token, c.client_id, t);
881
+ n.push(a);
1484
882
  }
1485
- let a = e.tokens ? e.tokens.refreshToken : null;
1486
- if (a && c.logout_tokens_to_invalidate.includes(We.refresh_token)) {
1487
- let e = X(s, ":revoke_refresh_token"), i = Ee(n)(t, a, H.refresh_token, c.client_id, e);
1488
- r.push(i);
883
+ let a = t.tokens ? t.tokens.refreshToken : null;
884
+ if (a && c.logout_tokens_to_invalidate.includes(xe.refresh_token)) {
885
+ let t = P(s, ":revoke_refresh_token"), i = fe(r)(e, a, j.refresh_token, c.client_id, t);
886
+ n.push(i);
1489
887
  }
1490
- r.length > 0 && await Promise.all(r);
888
+ n.length > 0 && await Promise.all(n);
1491
889
  }
1492
890
  } catch (e) {
1493
- r.warn("logoutAsync: error when revoking tokens, if the error persist, you ay configure property logout_tokens_to_invalidate from configuration to avoid this error"), r.warn(e);
891
+ i.warn("logoutAsync: error when revoking tokens, if the error persist, you ay configure property logout_tokens_to_invalidate from configuration to avoid this error"), i.warn(e);
1494
892
  }
1495
- let m = e.tokens?.idTokenPayload?.sub ?? null;
1496
- await e.destroyAsync("LOGGED_OUT");
1497
- for (let [, n] of Object.entries(t)) n === e ? e.publishEvent(i.logout_from_same_tab, {}) : await e.logoutSameTabAsync(e.configuration.client_id, m);
1498
- let h = X(s, ":oidc");
893
+ let m = t.tokens?.idTokenPayload?.sub ?? null;
894
+ await t.destroyAsync("LOGGED_OUT");
895
+ for (let [, r] of Object.entries(n)) r === t ? t.publishEvent(e.logout_from_same_tab, {}) : await t.logoutSameTabAsync(t.configuration.client_id, m);
896
+ let h = P(s, ":oidc");
1499
897
  if (h && h.no_reload === "true") return;
1500
- let g = Ge(s);
898
+ let g = Se(s);
1501
899
  if (l.endSessionEndpoint) {
1502
900
  "id_token_hint" in g || (g.id_token_hint = p), !("post_logout_redirect_uri" in g) && o !== null && (g.post_logout_redirect_uri = f);
1503
901
  let e = "";
1504
902
  for (let [t, n] of Object.entries(g)) n != null && (e === "" ? e += "?" : e += "&", e += `${t}=${encodeURIComponent(n)}`);
1505
903
  a.open(`${l.endSessionEndpoint}${e}`);
1506
904
  } else a.reload();
1507
- }, Je = (e, t, n = !1) => async (...r) => {
905
+ }, F = /* @__PURE__ */ function(e) {
906
+ return e.AutomaticBeforeTokenExpiration = "AutomaticBeforeTokensExpiration", e.AutomaticOnlyWhenFetchExecuted = "AutomaticOnlyWhenFetchExecuted", e;
907
+ }({}), Te = (e, t, n = !1) => async (...r) => {
1508
908
  let [i, a, ...o] = r, s = a ? { ...a } : { method: "GET" }, c = new Headers();
1509
909
  s.headers && (c = s.headers instanceof Headers ? s.headers : new Headers(s.headers));
1510
- let l = (await b({
910
+ let l = (await ze({
1511
911
  getTokens: () => t.tokens,
1512
912
  configuration: {
1513
913
  token_automatic_renew_mode: t.configuration.token_automatic_renew_mode,
1514
914
  refresh_time_before_tokens_expiration_in_second: t.configuration.refresh_time_before_tokens_expiration_in_second
1515
915
  },
1516
916
  syncTokensInfoAsync: async () => {
1517
- let { status: e } = await K(t)(t.configuration, t.configurationName, t.tokens, !1);
917
+ let { status: e } = await V(t)(t.configuration, t.configurationName, t.tokens, !1);
1518
918
  return e;
1519
919
  },
1520
920
  renewTokensAsync: t.renewTokensAsync.bind(t)
@@ -1530,46 +930,46 @@ var Le = () => {
1530
930
  ...s,
1531
931
  headers: c
1532
932
  }, ...o);
1533
- }, Ye = (e) => async (t = !1, n = !1) => {
933
+ }, Ee = (e) => async (t = !1, n = !1) => {
1534
934
  if (e.userInfo != null && !t) return e.userInfo;
1535
935
  let r = !t && e.configuration.storage?.getItem(`oidc.${e.configurationName}.userInfo`);
1536
936
  if (r) return e.userInfo = JSON.parse(r), e.userInfo;
1537
937
  let i = e.configuration, a = (await e.initAsync(i.authority, i.authority_configuration)).userInfoEndpoint, o = await (async () => {
1538
- let t = await Je(fetch, e, n)(a);
938
+ let t = await Te(fetch, e, n)(a);
1539
939
  return t.status === 200 ? t.json() : null;
1540
940
  })();
1541
941
  return e.userInfo = o, o && e.configuration.storage?.setItem(`oidc.${e.configurationName}.userInfo`, JSON.stringify(o)), o;
1542
- }, Xe = () => fetch, Z = class {
942
+ }, De = () => fetch, I = class {
1543
943
  constructor(e) {
1544
944
  this.authorizationEndpoint = e.authorization_endpoint, this.tokenEndpoint = e.token_endpoint, this.revocationEndpoint = e.revocation_endpoint, this.userInfoEndpoint = e.userinfo_endpoint, this.checkSessionIframe = e.check_session_iframe, this.issuer = e.issuer, this.endSessionEndpoint = e.end_session_endpoint;
1545
945
  }
1546
- }, Q = {}, Ze = (t, n = new e()) => (e, r = "default") => (Q[r] || (Q[r] = new $(e, r, t, n)), Q[r]), Qe = async (e) => {
946
+ }, L = {}, Oe = (e, t = new O()) => (n, r = "default") => (L[r] || (L[r] = new R(n, r, e, t)), L[r]), ke = async (e) => {
1547
947
  let { parsedTokens: t, callbackPath: n, extras: r, scope: i } = await e.loginCallbackAsync();
1548
- return e.timeoutId = W(e, t.expiresAt, r, i), { callbackPath: n };
1549
- }, $e = (e) => Math.floor(Math.random() * e), $ = class t {
1550
- constructor(t, n = "default", r, i = new e()) {
948
+ return e.timeoutId = z(e, t.expiresAt, r, i), { callbackPath: n };
949
+ }, Ae = (e) => Math.floor(Math.random() * e), R = class t {
950
+ constructor(e, t = "default", n, r = new O()) {
1551
951
  this.initPromise = null, this.tryKeepExistingSessionPromise = null, this.loginPromise = null, this.loginCallbackPromise = null, this.loginCallbackWithAutoTokensRenewPromise = null, this.userInfoPromise = null, this.renewTokensPromise = null, this.logoutPromise = null;
1552
- let a = t.silent_login_uri;
1553
- t.silent_redirect_uri && !t.silent_login_uri && (a = `${t.silent_redirect_uri.replace("-callback", "").replace("callback", "")}-login`);
1554
- let o = t.refresh_time_before_tokens_expiration_in_second ?? 120;
1555
- o > 60 && (o -= Math.floor(Math.random() * 40)), this.location = i ?? new e(), this.configuration = {
1556
- ...t,
1557
- silent_login_uri: a,
1558
- token_automatic_renew_mode: t.token_automatic_renew_mode ?? l.AutomaticBeforeTokenExpiration,
1559
- monitor_session: t.monitor_session ?? !1,
1560
- refresh_time_before_tokens_expiration_in_second: o,
1561
- silent_login_timeout: t.silent_login_timeout ?? 12e3,
1562
- token_renew_mode: t.token_renew_mode ?? m.access_token_or_id_token_invalid,
1563
- demonstrating_proof_of_possession: t.demonstrating_proof_of_possession ?? !1,
1564
- authority_timeout_wellknowurl_in_millisecond: t.authority_timeout_wellknowurl_in_millisecond ?? 1e4,
1565
- logout_tokens_to_invalidate: t.logout_tokens_to_invalidate ?? ["access_token", "refresh_token"],
1566
- service_worker_activate: t.service_worker_activate ?? Le,
1567
- demonstrating_proof_of_possession_configuration: t.demonstrating_proof_of_possession_configuration ?? de,
1568
- preload_user_info: t.preload_user_info ?? !1
1569
- }, this.getFetch = r ?? Xe, this.configurationName = n, this.tokens = null, this.userInfo = null, this.events = [], this.timeoutId = null, this.loginCallbackWithAutoTokensRenewAsync.bind(this), this.initAsync.bind(this), this.loginCallbackAsync.bind(this), this.subscribeEvents.bind(this), this.removeEventSubscription.bind(this), this.publishEvent.bind(this), this.destroyAsync.bind(this), this.logoutAsync.bind(this), this.renewTokensAsync.bind(this), this.initAsync(this.configuration.authority, this.configuration.authority_configuration);
952
+ let i = e.silent_login_uri;
953
+ e.silent_redirect_uri && !e.silent_login_uri && (i = `${e.silent_redirect_uri.replace("-callback", "").replace("callback", "")}-login`);
954
+ let a = e.refresh_time_before_tokens_expiration_in_second ?? 120;
955
+ a > 60 && (a -= Math.floor(Math.random() * 40)), this.location = r ?? new O(), this.configuration = {
956
+ ...e,
957
+ silent_login_uri: i,
958
+ token_automatic_renew_mode: e.token_automatic_renew_mode ?? F.AutomaticBeforeTokenExpiration,
959
+ monitor_session: e.monitor_session ?? !1,
960
+ refresh_time_before_tokens_expiration_in_second: a,
961
+ silent_login_timeout: e.silent_login_timeout ?? 12e3,
962
+ token_renew_mode: e.token_renew_mode ?? U.access_token_or_id_token_invalid,
963
+ demonstrating_proof_of_possession: e.demonstrating_proof_of_possession ?? !1,
964
+ authority_timeout_wellknowurl_in_millisecond: e.authority_timeout_wellknowurl_in_millisecond ?? 1e4,
965
+ logout_tokens_to_invalidate: e.logout_tokens_to_invalidate ?? ["access_token", "refresh_token"],
966
+ service_worker_activate: e.service_worker_activate ?? oe,
967
+ demonstrating_proof_of_possession_configuration: e.demonstrating_proof_of_possession_configuration ?? _,
968
+ preload_user_info: e.preload_user_info ?? !1
969
+ }, this.getFetch = n ?? De, this.configurationName = t, this.tokens = null, this.userInfo = null, this.events = [], this.timeoutId = null, this.loginCallbackWithAutoTokensRenewAsync.bind(this), this.initAsync.bind(this), this.loginCallbackAsync.bind(this), this.subscribeEvents.bind(this), this.removeEventSubscription.bind(this), this.publishEvent.bind(this), this.destroyAsync.bind(this), this.logoutAsync.bind(this), this.renewTokensAsync.bind(this), this.initAsync(this.configuration.authority, this.configuration.authority_configuration);
1570
970
  }
1571
971
  subscribeEvents(e) {
1572
- let t = $e(9999999999999).toString();
972
+ let t = Ae(9999999999999).toString();
1573
973
  return this.events.push({
1574
974
  id: t,
1575
975
  func: e
@@ -1585,20 +985,20 @@ var Le = () => {
1585
985
  });
1586
986
  }
1587
987
  static {
1588
- this.getOrCreate = (e, t) => (n, r = "default") => Ze(e, t)(n, r);
988
+ this.getOrCreate = (e, t) => (n, r = "default") => Oe(e, t)(n, r);
1589
989
  }
1590
990
  static get(e = "default") {
1591
991
  let t = typeof process > "u";
1592
- if (!Object.prototype.hasOwnProperty.call(Q, e) && t) throw Error(`OIDC library does seem initialized.
992
+ if (!Object.prototype.hasOwnProperty.call(L, e) && t) throw Error(`OIDC library does seem initialized.
1593
993
  Please checkout that you are using OIDC hook inside a <OidcProvider configurationName="${e}"></OidcProvider> component.`);
1594
- return Q[e];
994
+ return L[e];
1595
995
  }
1596
996
  static {
1597
- this.eventNames = i;
997
+ this.eventNames = e;
1598
998
  }
1599
999
  _silentLoginCallbackFromIFrame() {
1600
1000
  if (this.configuration.silent_redirect_uri && this.configuration.silent_login_uri) {
1601
- let e = this.location, t = Y(e.getCurrentHref());
1001
+ let e = this.location, t = N(e.getCurrentHref());
1602
1002
  window.parent.postMessage(`${this.configurationName}_oidc_tokens:${JSON.stringify({
1603
1003
  tokens: this.tokens,
1604
1004
  sessionState: t.session_state
@@ -1607,7 +1007,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
1607
1007
  }
1608
1008
  _silentLoginErrorCallbackFromIFrame(e = null) {
1609
1009
  if (this.configuration.silent_redirect_uri && this.configuration.silent_login_uri) {
1610
- let t = this.location, n = Y(t.getCurrentHref());
1010
+ let t = this.location, n = N(t.getCurrentHref());
1611
1011
  n.error ? window.parent.postMessage(`${this.configurationName}_oidc_error:${JSON.stringify({ error: n.error })}`, t.getOrigin()) : window.parent.postMessage(`${this.configurationName}_oidc_exception:${JSON.stringify({ error: e == null ? "" : e.toString() })}`, t.getOrigin());
1612
1012
  }
1613
1013
  }
@@ -1621,7 +1021,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
1621
1021
  async initAsync(e, t) {
1622
1022
  if (this.initPromise !== null) return this.initPromise;
1623
1023
  let n = async () => {
1624
- if (t != null) return new Z({
1024
+ if (t != null) return new I({
1625
1025
  authorization_endpoint: t.authorization_endpoint,
1626
1026
  end_session_endpoint: t.end_session_endpoint,
1627
1027
  revocation_endpoint: t.revocation_endpoint,
@@ -1630,31 +1030,31 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
1630
1030
  check_session_iframe: t.check_session_iframe,
1631
1031
  issuer: t.issuer
1632
1032
  });
1633
- let n = await L(this.configuration, this.configurationName) ? this.configuration.storage || window.sessionStorage : this.configuration.storage;
1634
- return await Te(this.getFetch())(e, this.configuration.authority_time_cache_wellknowurl_in_second ?? 3600, n, this.configuration.authority_timeout_wellknowurl_in_millisecond);
1033
+ let n = await $(this.configuration, this.configurationName) ? this.configuration.storage || window.sessionStorage : this.configuration.storage;
1034
+ return await de(this.getFetch())(e, this.configuration.authority_time_cache_wellknowurl_in_second ?? 3600, n, this.configuration.authority_timeout_wellknowurl_in_millisecond);
1635
1035
  };
1636
1036
  return this.initPromise = n(), this.initPromise.finally(() => {
1637
1037
  this.initPromise = null;
1638
1038
  });
1639
1039
  }
1640
1040
  async tryKeepExistingSessionAsync() {
1641
- return this.tryKeepExistingSessionPromise === null ? (this.tryKeepExistingSessionPromise = Re(this), this.tryKeepExistingSessionPromise.finally(() => {
1041
+ return this.tryKeepExistingSessionPromise === null ? (this.tryKeepExistingSessionPromise = se(this), this.tryKeepExistingSessionPromise.finally(() => {
1642
1042
  this.tryKeepExistingSessionPromise = null;
1643
1043
  })) : this.tryKeepExistingSessionPromise;
1644
1044
  }
1645
1045
  async startCheckSessionAsync(e, t, n, r = !1) {
1646
- await Ne(this, Q, this.configuration)(e, t, n, r);
1046
+ await d(this, L, this.configuration)(e, t, n, r);
1647
1047
  }
1648
1048
  async loginAsync(e = void 0, t = null, n = !1, r = void 0, i = !1) {
1649
- return this.logoutPromise && await this.logoutPromise, this.loginPromise === null ? (i ? this.loginPromise = Me(window, this.configurationName, this.configuration, this.publishEvent.bind(this), this)(t, r) : this.loginPromise = He(this.configurationName, this.configuration, this.publishEvent.bind(this), this.initAsync.bind(this), this.location)(e, t, n, r), this.loginPromise.finally(() => {
1049
+ return this.logoutPromise && await this.logoutPromise, this.loginPromise === null ? (i ? this.loginPromise = u(window, this.configurationName, this.configuration, this.publishEvent.bind(this), this)(t, r) : this.loginPromise = ye(this.configurationName, this.configuration, this.publishEvent.bind(this), this.initAsync.bind(this), this.location)(e, t, n, r), this.loginPromise.finally(() => {
1650
1050
  this.loginPromise = null;
1651
1051
  })) : this.loginPromise;
1652
1052
  }
1653
1053
  async loginCallbackAsync(e = !1) {
1654
1054
  if (this.loginCallbackPromise !== null) return this.loginCallbackPromise;
1655
1055
  let n = async () => {
1656
- let n = await Ue(this)(e), r = n.tokens;
1657
- return this.tokens = r, await L(this.configuration, this.configurationName) || c(this.configurationName, this.configuration.storage, this.configuration.login_state_storage ?? this.configuration.storage).setTokens(r), this.publishEvent(t.eventNames.token_acquired, r), this.configuration.preload_user_info && await this.userInfoAsync(), {
1056
+ let n = await be(this)(e), r = n.tokens;
1057
+ return this.tokens = r, await $(this.configuration, this.configurationName) || i(this.configurationName, this.configuration.storage, this.configuration.login_state_storage ?? this.configuration.storage).setTokens(r), this.publishEvent(t.eventNames.token_acquired, r), this.configuration.preload_user_info && await this.userInfoAsync(), {
1658
1058
  parsedTokens: r,
1659
1059
  state: n.state,
1660
1060
  callbackPath: n.callbackPath,
@@ -1667,71 +1067,680 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
1667
1067
  });
1668
1068
  }
1669
1069
  async generateDemonstrationOfProofOfPossessionAsync(e, t, n, r = {}) {
1670
- let i = this.configuration, a = {
1671
- ath: await Se(e),
1070
+ let a = this.configuration, o = {
1071
+ ath: await te(e),
1672
1072
  ...r
1673
1073
  };
1674
- if (await L(i, this.configurationName)) return `DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${this.configurationName}#tabId=${k(this.configurationName)}`;
1675
- let o = c(this.configurationName, i.storage, i.login_state_storage ?? i.storage), s = await o.getDemonstratingProofOfPossessionJwkAsync(), l = o.getDemonstratingProofOfPossessionNonce();
1676
- return l && (a.nonce = l), await ge(window)(i.demonstrating_proof_of_possession_configuration)(s, n, t, a);
1074
+ if (await $(a, this.configurationName)) return `DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${this.configurationName}#tabId=${We(this.configurationName)}`;
1075
+ let s = i(this.configurationName, a.storage, a.login_state_storage ?? a.storage), c = await s.getDemonstratingProofOfPossessionJwkAsync(), l = s.getDemonstratingProofOfPossessionNonce();
1076
+ return l && (o.nonce = l), await S(window)(a.demonstrating_proof_of_possession_configuration)(c, n, t, o);
1677
1077
  }
1678
1078
  loginCallbackWithAutoTokensRenewAsync() {
1679
- return this.loginCallbackWithAutoTokensRenewPromise === null ? (this.loginCallbackWithAutoTokensRenewPromise = Qe(this), this.loginCallbackWithAutoTokensRenewPromise.finally(() => {
1079
+ return this.loginCallbackWithAutoTokensRenewPromise === null ? (this.loginCallbackWithAutoTokensRenewPromise = ke(this), this.loginCallbackWithAutoTokensRenewPromise.finally(() => {
1680
1080
  this.loginCallbackWithAutoTokensRenewPromise = null;
1681
1081
  })) : this.loginCallbackWithAutoTokensRenewPromise;
1682
1082
  }
1683
1083
  userInfoAsync(e = !1, t = !1) {
1684
- return this.userInfoPromise === null ? (this.userInfoPromise = Ye(this)(e, t), this.userInfoPromise.finally(() => {
1084
+ return this.userInfoPromise === null ? (this.userInfoPromise = Ee(this)(e, t), this.userInfoPromise.finally(() => {
1685
1085
  this.userInfoPromise = null;
1686
1086
  })) : this.userInfoPromise;
1687
1087
  }
1688
1088
  async renewTokensAsync(e = null, t = null) {
1689
1089
  if (this.renewTokensPromise !== null) return this.renewTokensPromise;
1690
- if (this.timeoutId) return S.clearTimeout(this.timeoutId), this.renewTokensPromise = je(this, !0, e, t), this.renewTokensPromise.finally(() => {
1090
+ if (this.timeoutId) return c.clearTimeout(this.timeoutId), this.renewTokensPromise = Me(this, !0, e, t), this.renewTokensPromise.finally(() => {
1691
1091
  this.renewTokensPromise = null;
1692
1092
  });
1693
1093
  }
1694
1094
  async destroyAsync(e) {
1695
- return await Ke(this)(e);
1095
+ return await Ce(this)(e);
1696
1096
  }
1697
- async logoutSameTabAsync(e, t) {
1698
- this.configuration.monitor_session && this.configuration.client_id === e && t && this.tokens && this.tokens.idTokenPayload && this.tokens.idTokenPayload.sub === t && (await this.destroyAsync("LOGGED_OUT"), this.publishEvent(i.logout_from_same_tab, {
1097
+ async logoutSameTabAsync(t, n) {
1098
+ this.configuration.monitor_session && this.configuration.client_id === t && n && this.tokens && this.tokens.idTokenPayload && this.tokens.idTokenPayload.sub === n && (await this.destroyAsync("LOGGED_OUT"), this.publishEvent(e.logout_from_same_tab, {
1699
1099
  mmessage: "SessionMonitor",
1700
- sub: t
1100
+ sub: n
1701
1101
  }));
1702
1102
  }
1703
- async logoutOtherTabAsync(e, t) {
1704
- this.configuration.monitor_session && this.configuration.client_id === e && t && this.tokens && this.tokens.idTokenPayload && this.tokens.idTokenPayload.sub === t && (await this.destroyAsync("LOGGED_OUT"), this.publishEvent(i.logout_from_another_tab, {
1103
+ async logoutOtherTabAsync(t, n) {
1104
+ this.configuration.monitor_session && this.configuration.client_id === t && n && this.tokens && this.tokens.idTokenPayload && this.tokens.idTokenPayload.sub === n && (await this.destroyAsync("LOGGED_OUT"), this.publishEvent(e.logout_from_another_tab, {
1705
1105
  message: "SessionMonitor",
1706
- sub: t
1106
+ sub: n
1707
1107
  }));
1708
1108
  }
1709
1109
  async logoutAsync(e = void 0, t = null) {
1710
- return this.logoutPromise ? this.logoutPromise : (this.logoutPromise = qe(this, Q, this.getFetch(), console, this.location)(e, t), this.logoutPromise.finally(() => {
1110
+ return this.logoutPromise ? this.logoutPromise : (this.logoutPromise = we(this, L, this.getFetch(), console, this.location)(e, t), this.logoutPromise.finally(() => {
1711
1111
  this.logoutPromise = null;
1712
1112
  }));
1713
1113
  }
1714
- }, et = class t {
1715
- constructor(e) {
1716
- this._oidc = e;
1717
- }
1718
- subscribeEvents(e) {
1719
- return this._oidc.subscribeEvents(e);
1720
- }
1721
- removeEventSubscription(e) {
1722
- this._oidc.removeEventSubscription(e);
1723
- }
1724
- publishEvent(e, t) {
1725
- this._oidc.publishEvent(e, t);
1114
+ };
1115
+ //#endregion
1116
+ //#region src/renewTokens.ts
1117
+ async function je(e, t, n, r = null) {
1118
+ let { tokens: a, status: o } = await H(e)((t) => {
1119
+ e.tokens = t;
1120
+ }, 0, 0, t, n, r);
1121
+ return await $(e.configuration, e.configurationName) || i(e.configurationName, e.configuration.storage, e.configuration.login_state_storage ?? e.configuration.storage).setTokens(e.tokens), e.tokens ? a : (await e.destroyAsync(o), null);
1122
+ }
1123
+ async function Me(e, t = !1, n = null, r = null) {
1124
+ let i = e.configuration, a = `${i.client_id}_${e.configurationName}_${i.authority}`, o, s = await $(e.configuration, e.configurationName);
1125
+ if (i?.storage === window?.sessionStorage && !s || !navigator.locks) o = await je(e, t, n, r);
1126
+ else {
1127
+ let i = "retry";
1128
+ for (; i === "retry";) i = await navigator.locks.request(a, { ifAvailable: !0 }, async (i) => i ? await je(e, t, n, r) : (e.publishEvent(R.eventNames.syncTokensAsync_lock_not_available, { lock: "lock not available" }), "retry"));
1129
+ o = i;
1130
+ }
1131
+ return o ? (e.timeoutId &&= z(e, e.tokens.expiresAt, n, r), e.tokens) : null;
1132
+ }
1133
+ var z = (e, t, n = null, r = null) => {
1134
+ let i = e.configuration.refresh_time_before_tokens_expiration_in_second;
1135
+ return e.timeoutId && c.clearTimeout(e.timeoutId), c.setTimeout(async () => {
1136
+ let a = { timeLeft: K(i, t) };
1137
+ e.publishEvent(R.eventNames.token_timer, a), await Me(e, !1, n, r);
1138
+ }, 1e3);
1139
+ }, B = {
1140
+ FORCE_REFRESH: "FORCE_REFRESH",
1141
+ SESSION_LOST: "SESSION_LOST",
1142
+ NOT_CONNECTED: "NOT_CONNECTED",
1143
+ TOKENS_VALID: "TOKENS_VALID",
1144
+ TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID: "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID",
1145
+ TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID: "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID",
1146
+ LOGOUT_FROM_ANOTHER_TAB: "LOGOUT_FROM_ANOTHER_TAB",
1147
+ REQUIRE_SYNC_TOKENS: "REQUIRE_SYNC_TOKENS",
1148
+ TOKENS_INVALID: "TOKENS_INVALID"
1149
+ }, V = (e) => async (t, n, r, a = !1) => {
1150
+ let o = { nonce: null };
1151
+ if (!r) return {
1152
+ tokens: null,
1153
+ status: B.NOT_CONNECTED,
1154
+ nonce: o
1155
+ };
1156
+ let s, c = await e.initAsync(t.authority, t.authority_configuration), l = await $(t, n);
1157
+ if (l) {
1158
+ let { status: e, tokens: n } = await l.initAsync(c, "syncTokensAsync", t);
1159
+ if (e === "LOGGED_OUT") return {
1160
+ tokens: null,
1161
+ status: B.LOGOUT_FROM_ANOTHER_TAB,
1162
+ nonce: o
1163
+ };
1164
+ if (e === "SESSIONS_LOST") return {
1165
+ tokens: null,
1166
+ status: B.SESSION_LOST,
1167
+ nonce: o
1168
+ };
1169
+ if (!e || !n) return {
1170
+ tokens: null,
1171
+ status: B.REQUIRE_SYNC_TOKENS,
1172
+ nonce: o
1173
+ };
1174
+ if (n.issuedAt !== r.issuedAt) return {
1175
+ tokens: n,
1176
+ status: K(t.refresh_time_before_tokens_expiration_in_second, n.expiresAt) > 0 ? B.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID : B.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID,
1177
+ nonce: await l.getNonceAsync()
1178
+ };
1179
+ s = await l.getNonceAsync();
1180
+ } else {
1181
+ let a = i(n, t.storage ?? sessionStorage, t.login_state_storage ?? t.storage ?? sessionStorage), c = await a.initAsync(), { tokens: l } = c, { status: u } = c;
1182
+ if (l &&= W(l, e.tokens, t.token_renew_mode), !l) return {
1183
+ tokens: null,
1184
+ status: B.LOGOUT_FROM_ANOTHER_TAB,
1185
+ nonce: o
1186
+ };
1187
+ if (u === "SESSIONS_LOST") return {
1188
+ tokens: null,
1189
+ status: B.SESSION_LOST,
1190
+ nonce: o
1191
+ };
1192
+ if (l.issuedAt !== r.issuedAt) {
1193
+ let e = K(t.refresh_time_before_tokens_expiration_in_second, l.expiresAt) > 0 ? B.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID : B.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID, n = await a.getNonceAsync();
1194
+ return {
1195
+ tokens: l,
1196
+ status: e,
1197
+ nonce: n
1198
+ };
1199
+ }
1200
+ s = await a.getNonceAsync();
1201
+ }
1202
+ let u = K(t.refresh_time_before_tokens_expiration_in_second, r.expiresAt) > 0 ? "TOKENS_VALID" : "TOKENS_INVALID";
1203
+ return a ? {
1204
+ tokens: r,
1205
+ status: "FORCE_REFRESH",
1206
+ nonce: s
1207
+ } : {
1208
+ tokens: r,
1209
+ status: u,
1210
+ nonce: s
1211
+ };
1212
+ }, H = (t) => async (n, r = 0, a = 0, o = !1, s = null, c = null) => {
1213
+ if (!navigator.onLine && document.hidden) return {
1214
+ tokens: t.tokens,
1215
+ status: "GIVE_UP"
1216
+ };
1217
+ let u = 6, d = o ? 2 : 5;
1218
+ for (; !navigator.onLine && u > 0;) await J({ milliseconds: 1e3 }), u--, t.publishEvent(e.refreshTokensAsync, { message: `wait because navigator is offline try ${u}` });
1219
+ let f = document.hidden, p = f ? r : r + 1, m = f ? a + 1 : a;
1220
+ if (r >= d || a >= 5) return n(null), t.publishEvent(e.refreshTokensAsync_error, { message: "refresh token" }), {
1221
+ tokens: null,
1222
+ status: "SESSION_LOST"
1223
+ };
1224
+ s ||= {};
1225
+ let h = t.configuration, g = (e, n = null, r = null) => l(t.configurationName, t.configuration, t.publishEvent.bind(t))(e, n, r), _ = async () => {
1226
+ try {
1227
+ let r, a = await $(h, t.configurationName);
1228
+ r = a ? a.getLoginParams() : i(t.configurationName, h.storage, h.login_state_storage ?? h.storage).getLoginParams();
1229
+ let o = {};
1230
+ if (r && r.extras) for (let [e, t] of Object.entries(r.extras)) t != null && (o[e] = t);
1231
+ if (s) for (let [e, t] of Object.entries(s)) t != null && (o[e] = t);
1232
+ o.prompt = "none", c && (o.scope = c);
1233
+ let l = await g(o);
1234
+ return l ? l.error ? (n(null), t.publishEvent(e.refreshTokensAsync_error, { message: "refresh token silent" }), {
1235
+ tokens: null,
1236
+ status: "SESSION_LOST"
1237
+ }) : (n(l.tokens), t.publishEvent(R.eventNames.token_renewed, {}), {
1238
+ tokens: l.tokens,
1239
+ status: "LOGGED"
1240
+ }) : (n(null), t.publishEvent(e.refreshTokensAsync_error, { message: "refresh token silent not active" }), {
1241
+ tokens: null,
1242
+ status: "SESSION_LOST"
1243
+ });
1244
+ } catch (r) {
1245
+ return console.error(r), t.publishEvent(e.refreshTokensAsync_silent_error, {
1246
+ message: "exceptionSilent",
1247
+ exception: r.message
1248
+ }), await H(t)(n, p, m, o, s, c);
1249
+ }
1250
+ };
1251
+ try {
1252
+ let { status: l, tokens: u, nonce: d } = await V(t)(h, t.configurationName, t.tokens, o);
1253
+ switch (l) {
1254
+ case B.SESSION_LOST: return n(null), t.publishEvent(e.refreshTokensAsync_error, { message: "refresh token session lost" }), {
1255
+ tokens: null,
1256
+ status: "SESSION_LOST"
1257
+ };
1258
+ case B.NOT_CONNECTED: return n(null), {
1259
+ tokens: null,
1260
+ status: null
1261
+ };
1262
+ case B.TOKENS_VALID: return n(u), {
1263
+ tokens: u,
1264
+ status: "LOGGED_IN"
1265
+ };
1266
+ case B.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID: return n(u), t.publishEvent(R.eventNames.token_renewed, { reason: "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID" }), {
1267
+ tokens: u,
1268
+ status: "LOGGED_IN"
1269
+ };
1270
+ case B.LOGOUT_FROM_ANOTHER_TAB: return n(null), t.publishEvent(e.logout_from_another_tab, { status: "session syncTokensAsync" }), {
1271
+ tokens: null,
1272
+ status: "LOGGED_OUT"
1273
+ };
1274
+ case B.REQUIRE_SYNC_TOKENS: return h.token_automatic_renew_mode == F.AutomaticOnlyWhenFetchExecuted && !o ? (t.publishEvent(e.tokensInvalidAndWaitingActionsToRefresh, {}), {
1275
+ tokens: t.tokens,
1276
+ status: "GIVE_UP"
1277
+ }) : (t.publishEvent(e.refreshTokensAsync_begin, { tryNumber: r }), await _());
1278
+ default: {
1279
+ if (h.token_automatic_renew_mode == F.AutomaticOnlyWhenFetchExecuted && B.FORCE_REFRESH !== l) return t.publishEvent(e.tokensInvalidAndWaitingActionsToRefresh, {}), {
1280
+ tokens: t.tokens,
1281
+ status: "GIVE_UP"
1282
+ };
1283
+ if (t.publishEvent(e.refreshTokensAsync_begin, {
1284
+ refreshToken: u.refreshToken,
1285
+ status: l,
1286
+ tryNumber: r,
1287
+ backgroundTry: a
1288
+ }), !u.refreshToken) return await _();
1289
+ let f = h.client_id, g = h.redirect_uri, v = h.authority, y = { ...h.token_request_extras ? h.token_request_extras : {} };
1290
+ for (let [e, t] of Object.entries(s)) e.endsWith(":token_request") && (y[e.replace(":token_request", "")] = t);
1291
+ return await (async () => {
1292
+ let r = {
1293
+ client_id: f,
1294
+ redirect_uri: g,
1295
+ grant_type: "refresh_token",
1296
+ refresh_token: u.refreshToken
1297
+ }, a = await t.initAsync(v, h.authority_configuration), l = document.hidden ? 1e4 : 3e4 * 10, _ = a.tokenEndpoint, b = {};
1298
+ h.demonstrating_proof_of_possession && (b.DPoP = await t.generateDemonstrationOfProofOfPossessionAsync(u.accessToken, _, "POST"));
1299
+ let x = await pe(t.getFetch())(_, r, y, u, b, h.token_renew_mode, l);
1300
+ if (x.success) {
1301
+ let { isValid: r, reason: o } = Be(x.data, d.nonce, a);
1302
+ if (!r) return n(null), t.publishEvent(e.refreshTokensAsync_error, { message: `refresh token return not valid tokens, reason: ${o}` }), {
1303
+ tokens: null,
1304
+ status: "SESSION_LOST"
1305
+ };
1306
+ if (n(x.data), x.demonstratingProofOfPossessionNonce) {
1307
+ let e = await $(h, t.configurationName);
1308
+ e ? await e.setDemonstratingProofOfPossessionNonce(x.demonstratingProofOfPossessionNonce) : await i(t.configurationName, h.storage, h.login_state_storage ?? h.storage).setDemonstratingProofOfPossessionNonce(x.demonstratingProofOfPossessionNonce);
1309
+ }
1310
+ return t.publishEvent(e.refreshTokensAsync_end, { success: x.success }), t.publishEvent(R.eventNames.token_renewed, { reason: "REFRESH_TOKEN" }), {
1311
+ tokens: x.data,
1312
+ status: "LOGGED_IN"
1313
+ };
1314
+ } else return t.publishEvent(e.refreshTokensAsync_silent_error, {
1315
+ message: "bad request",
1316
+ tokenResponse: x
1317
+ }), x.status >= 400 && x.status < 500 ? (n(null), t.publishEvent(e.refreshTokensAsync_error, { message: `session lost: ${x.status}` }), {
1318
+ tokens: null,
1319
+ status: "SESSION_LOST"
1320
+ }) : await H(t)(n, p, m, o, s, c);
1321
+ })();
1322
+ }
1323
+ }
1324
+ } catch (r) {
1325
+ return console.error(r), t.publishEvent(e.refreshTokensAsync_silent_error, {
1326
+ message: "exception",
1327
+ exception: r.message
1328
+ }), new Promise((e, r) => {
1329
+ setTimeout(() => {
1330
+ H(t)(n, p, m, o, s, c).then(e).catch(r);
1331
+ }, 1e3);
1332
+ });
1333
+ }
1334
+ }, Ne = (e) => decodeURIComponent(Array.prototype.map.call(atob(e), (e) => "%" + ("00" + e.charCodeAt(0).toString(16)).slice(-2)).join("")), Pe = (e) => JSON.parse(Ne(e.replaceAll(/-/g, "+").replaceAll(/_/g, "/"))), Fe = (e) => {
1335
+ try {
1336
+ return e && Ie(e, ".") === 2 ? Pe(e.split(".")[1]) : null;
1337
+ } catch (e) {
1338
+ console.warn(e);
1339
+ }
1340
+ return null;
1341
+ }, Ie = (e, t) => e.split(t).length - 1, U = {
1342
+ access_token_or_id_token_invalid: "access_token_or_id_token_invalid",
1343
+ access_token_invalid: "access_token_invalid",
1344
+ id_token_invalid: "id_token_invalid"
1345
+ };
1346
+ function Le(e, t, n) {
1347
+ return e.issuedAt ? typeof e.issuedAt == "string" ? parseInt(e.issuedAt, 10) : e.issuedAt : t && t.iat ? t.iat : n && n.iat ? n.iat : (/* @__PURE__ */ new Date()).getTime() / 1e3;
1348
+ }
1349
+ var W = (e, t = null, n) => {
1350
+ if (!e) return null;
1351
+ let r, i = typeof e.expiresIn == "string" ? parseInt(e.expiresIn, 10) : e.expiresIn;
1352
+ r = e.accessTokenPayload === void 0 ? Fe(e.accessToken) : e.accessTokenPayload;
1353
+ let a;
1354
+ a = t != null && "idToken" in t && !("idToken" in e) ? t.idToken : e.idToken;
1355
+ let o = e.idTokenPayload ? e.idTokenPayload : Fe(a), s = o && o.exp ? o.exp : Number.MAX_VALUE, c = r && r.exp ? r.exp : e.issuedAt + i;
1356
+ e.issuedAt = Le(e, r, o);
1357
+ let l;
1358
+ l = e.expiresAt ? e.expiresAt : n === U.access_token_invalid ? c : n === U.id_token_invalid || s < c ? s : c;
1359
+ let u = {
1360
+ ...e,
1361
+ idTokenPayload: o,
1362
+ accessTokenPayload: r,
1363
+ expiresAt: l,
1364
+ idToken: a
1365
+ };
1366
+ if (t != null && "refreshToken" in t && !("refreshToken" in e)) {
1367
+ let e = t.refreshToken;
1368
+ return {
1369
+ ...u,
1370
+ refreshToken: e
1371
+ };
1372
+ }
1373
+ return u;
1374
+ }, G = (e, t, n) => {
1375
+ if (!e) return null;
1376
+ e.issued_at ||= (/* @__PURE__ */ new Date()).getTime() / 1e3;
1377
+ let r = {
1378
+ accessToken: e.access_token,
1379
+ expiresIn: e.expires_in,
1380
+ idToken: e.id_token,
1381
+ scope: e.scope,
1382
+ tokenType: e.token_type,
1383
+ issuedAt: e.issued_at
1384
+ };
1385
+ return "refresh_token" in e && (r.refreshToken = e.refresh_token), e.accessTokenPayload !== void 0 && (r.accessTokenPayload = e.accessTokenPayload), e.idTokenPayload !== void 0 && (r.idTokenPayload = e.idTokenPayload), W(r, t, n);
1386
+ }, K = (e, t) => {
1387
+ let n = t - (/* @__PURE__ */ new Date()).getTime() / 1e3;
1388
+ return Math.round(n - e);
1389
+ }, Re = (e, t = 0) => e ? K(t, e.expiresAt) > 0 : !1, ze = async (e, t = 200, n = 50) => {
1390
+ let r = n, i = await e.syncTokensInfoAsync();
1391
+ for (; [
1392
+ B.REQUIRE_SYNC_TOKENS,
1393
+ B.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID,
1394
+ B.TOKENS_INVALID
1395
+ ].includes(i) && r > 0;) {
1396
+ if (e.configuration.token_automatic_renew_mode == F.AutomaticOnlyWhenFetchExecuted) {
1397
+ await e.renewTokensAsync({});
1398
+ break;
1399
+ } else await J({ milliseconds: t });
1400
+ --r, i = await e.syncTokensInfoAsync();
1401
+ }
1402
+ return {
1403
+ isTokensValid: Re(e.getTokens()),
1404
+ tokens: e.getTokens(),
1405
+ numberWaited: r - n
1406
+ };
1407
+ }, Be = (e, t, n) => {
1408
+ if (e.idTokenPayload) {
1409
+ let r = e.idTokenPayload;
1410
+ if (n.issuer !== r.iss) return {
1411
+ isValid: !1,
1412
+ reason: `Issuer does not match (oidcServerConfiguration issuer) ${n.issuer} !== (idTokenPayload issuer) ${r.iss}`
1413
+ };
1414
+ let i = (/* @__PURE__ */ new Date()).getTime() / 1e3;
1415
+ if (r.exp && r.exp < i) return {
1416
+ isValid: !1,
1417
+ reason: `Token expired (idTokenPayload exp) ${r.exp} < (currentTimeUnixSecond) ${i}`
1418
+ };
1419
+ let a = 3600 * 24 * 7;
1420
+ if (r.iat && r.iat + a < i) return {
1421
+ isValid: !1,
1422
+ reason: `Token is used from too long time (idTokenPayload iat + timeInSevenDays) ${r.iat + a} < (currentTimeUnixSecond) ${i}`
1423
+ };
1424
+ if (r.nonce && r.nonce !== t) return {
1425
+ isValid: !1,
1426
+ reason: `Nonce does not match (idTokenPayload nonce) ${r.nonce} !== (nonce) ${t}`
1427
+ };
1428
+ }
1429
+ return {
1430
+ isValid: !0,
1431
+ reason: ""
1432
+ };
1433
+ }, Ve = "7.27.13", He = null, q, J = ({ milliseconds: e }) => new Promise((t) => c.setTimeout(t, e)), Ue = (e = "/") => {
1434
+ try {
1435
+ q = new AbortController(), fetch(`${e}OidcKeepAliveServiceWorker.json?minSleepSeconds=150`, { signal: q.signal }).catch((e) => {
1436
+ console.log(e);
1437
+ }), J({ milliseconds: 150 * 1e3 }).then(() => Ue(e));
1438
+ } catch (e) {
1439
+ console.log(e);
1440
+ }
1441
+ }, Y = () => {
1442
+ q && q.abort();
1443
+ }, We = (e) => {
1444
+ let t = `oidc.tabId.${e}`, n = sessionStorage.getItem(t);
1445
+ if (n) return n;
1446
+ let r = globalThis.crypto.randomUUID();
1447
+ return sessionStorage.setItem(t, r), r;
1448
+ }, Ge = (e) => navigator.serviceWorker.controller ?? e.active ?? e.waiting ?? e.installing ?? null, X = (e, t) => (n) => {
1449
+ let r = t?.timeoutMs ?? 5e3;
1450
+ return new Promise((t, i) => {
1451
+ let a = Ge(e);
1452
+ if (!a) {
1453
+ i(/* @__PURE__ */ Error("Service worker target not available (controller/active/waiting/installing missing)"));
1454
+ return;
1455
+ }
1456
+ let o = new MessageChannel(), s = null, l = () => {
1457
+ try {
1458
+ s != null && (c.clearTimeout(s), s = null), o.port1.onmessage = null, o.port1.close(), o.port2.close();
1459
+ } catch (e) {
1460
+ console.error(e);
1461
+ }
1462
+ };
1463
+ s = c.setTimeout(() => {
1464
+ l(), i(/* @__PURE__ */ Error(`Service worker did not respond within ${r}ms (type=${n?.type})`));
1465
+ }, r), o.port1.onmessage = (e) => {
1466
+ l(), e?.data?.error ? i(e.data.error) : t(e.data);
1467
+ };
1468
+ try {
1469
+ let e = n?.configurationName;
1470
+ a.postMessage({
1471
+ ...n,
1472
+ tabId: We(e ?? "default")
1473
+ }, [o.port2]);
1474
+ } catch (e) {
1475
+ l(), i(e);
1476
+ }
1477
+ });
1478
+ }, Ke = async (e) => navigator.serviceWorker.controller ? navigator.serviceWorker.controller : new Promise((t) => {
1479
+ let n = !1, r = () => {
1480
+ n || (n = !0, navigator.serviceWorker.removeEventListener("controllerchange", r), t(navigator.serviceWorker.controller ?? null));
1481
+ };
1482
+ navigator.serviceWorker.addEventListener("controllerchange", r), c.setTimeout(() => {
1483
+ n || (n = !0, navigator.serviceWorker.removeEventListener("controllerchange", r), t(navigator.serviceWorker.controller ?? null));
1484
+ }, e);
1485
+ }), qe = !1, Z = !1, Q = /* @__PURE__ */ new Map(), Je = "oidc.sw.controllerchange_reload_count", Ye = 3, Xe = () => {
1486
+ try {
1487
+ return parseInt(sessionStorage.getItem(Je) ?? "0", 10);
1488
+ } catch {
1489
+ return 0;
1490
+ }
1491
+ }, Ze = () => {
1492
+ let e = Xe() + 1;
1493
+ try {
1494
+ sessionStorage.setItem(Je, String(e));
1495
+ } catch {}
1496
+ return e;
1497
+ }, Qe = () => {
1498
+ try {
1499
+ sessionStorage.removeItem(Je);
1500
+ } catch {}
1501
+ }, $ = async (e, t) => {
1502
+ let n = e.service_worker_relative_url;
1503
+ if (typeof window > "u" || typeof navigator > "u" || !navigator.serviceWorker || !n || e.service_worker_activate() === !1) return null;
1504
+ let r = `${n}?v=${Ve}`, i = null;
1505
+ e.service_worker_register ? (Q.has(n) || Q.set(n, e.service_worker_register(n)), i = await Q.get(n)) : (Q.has(r) || Q.set(r, navigator.serviceWorker.register(r, { updateViaCache: "none" })), i = await Q.get(r));
1506
+ let a = `oidc.sw.version_mismatch_reload.${t}`, o = async (e) => {
1507
+ Y(), console.log("New SW waiting – SKIP_WAITING");
1508
+ try {
1509
+ await new Promise((n, r) => {
1510
+ let i = new MessageChannel(), a = null, o = () => {
1511
+ try {
1512
+ a != null && (c.clearTimeout(a), a = null), i.port1.onmessage = null, i.port1.close(), i.port2.close();
1513
+ } catch (e) {
1514
+ console.error(e);
1515
+ }
1516
+ };
1517
+ a = c.setTimeout(() => {
1518
+ o(), r(/* @__PURE__ */ Error("SKIP_WAITING did not respond within 8000ms"));
1519
+ }, 8e3), i.port1.onmessage = (e) => {
1520
+ o(), e?.data?.error ? r(e.data.error) : n();
1521
+ };
1522
+ try {
1523
+ e.postMessage({
1524
+ type: "SKIP_WAITING",
1525
+ configurationName: t,
1526
+ data: null,
1527
+ tabId: We(t ?? "default")
1528
+ }, [i.port2]);
1529
+ } catch (e) {
1530
+ o(), r(e);
1531
+ }
1532
+ });
1533
+ } catch (e) {
1534
+ console.warn("SKIP_WAITING failed", e);
1535
+ }
1536
+ }, s = async () => {
1537
+ let e = i.waiting;
1538
+ e ? await o(e) : console.warn("sendSkipWaiting called but no waiting service worker found");
1539
+ }, l = (e) => {
1540
+ Y(), e.addEventListener("statechange", async () => {
1541
+ if (e.state === "installed" && navigator.serviceWorker.controller) {
1542
+ if (Xe() >= Ye) {
1543
+ console.warn("SW trackInstallingWorker: skipping SKIP_WAITING because the reload budget is exhausted");
1544
+ return;
1545
+ }
1546
+ await o(e);
1547
+ }
1548
+ });
1549
+ };
1550
+ i.addEventListener("updatefound", () => {
1551
+ let e = i.installing;
1552
+ e && l(e);
1553
+ }), i.installing ? l(i.installing) : i.waiting && navigator.serviceWorker.controller && (Xe() < Ye ? s() : console.warn("SW: a waiting worker exists but reload budget is exhausted – skipping activation")), i.update().catch((e) => {
1554
+ console.error(e);
1555
+ });
1556
+ try {
1557
+ await navigator.serviceWorker.ready, navigator.serviceWorker.controller || (await X(i, { timeoutMs: 8e3 })({
1558
+ type: "claim",
1559
+ configurationName: t,
1560
+ data: null
1561
+ }), await Ke(2e3));
1562
+ } catch (e) {
1563
+ return console.warn(`Failed init ServiceWorker ${e?.toString?.() ?? String(e)}`), null;
1564
+ }
1565
+ qe || (qe = !0, navigator.serviceWorker.addEventListener("controllerchange", () => {
1566
+ if (Z) return;
1567
+ let e = Ze();
1568
+ if (e > Ye) {
1569
+ console.warn(`SW controllerchange: reload budget exhausted (${e - 1} reloads). Skipping reload to avoid infinite loop.`);
1570
+ return;
1571
+ }
1572
+ Z = !0, console.log("SW controller changed – reloading page"), Y(), window.location.reload();
1573
+ }));
1574
+ let u = async (e) => X(i)({
1575
+ type: "clear",
1576
+ data: { status: e },
1577
+ configurationName: t
1578
+ }), d = async (e, n, r) => {
1579
+ let o = await X(i)({
1580
+ type: "init",
1581
+ data: {
1582
+ oidcServerConfiguration: e,
1583
+ where: n,
1584
+ oidcConfiguration: {
1585
+ token_renew_mode: r.token_renew_mode,
1586
+ service_worker_convert_all_requests_to_cors: r.service_worker_convert_all_requests_to_cors
1587
+ }
1588
+ },
1589
+ configurationName: t
1590
+ }), c = o.version;
1591
+ if (c !== "7.27.13") {
1592
+ console.warn(`Service worker ${c} version mismatch with js client version ${Ve}, unregistering and reloading`);
1593
+ let e = parseInt(sessionStorage.getItem(a) ?? "0", 10);
1594
+ if (e < 3) {
1595
+ if (sessionStorage.setItem(a, String(e + 1)), i.waiting) return await s(), await J({ milliseconds: 500 }), Z || (Z = !0, window.location.reload()), new Promise(() => {});
1596
+ {
1597
+ Y();
1598
+ try {
1599
+ await i.update();
1600
+ } catch (e) {
1601
+ console.error(e);
1602
+ }
1603
+ let e = await i.unregister();
1604
+ return console.log(`Service worker unregistering ${e}`), await J({ milliseconds: 500 }), Z || (Z = !0, window.location.reload()), new Promise(() => {});
1605
+ }
1606
+ } else console.error(`Service worker version mismatch persists after ${e} attempt(s). Continuing with mismatched version.`);
1607
+ } else sessionStorage.removeItem(a), Qe();
1608
+ return {
1609
+ tokens: G(o.tokens, null, r.token_renew_mode),
1610
+ status: o.status
1611
+ };
1612
+ }, f = (e = "/") => {
1613
+ He ?? (He = "not_null", Ue(e));
1614
+ }, p = (e) => X(i)({
1615
+ type: "setSessionState",
1616
+ data: { sessionState: e },
1617
+ configurationName: t
1618
+ }), m = async () => (await X(i)({
1619
+ type: "getSessionState",
1620
+ data: null,
1621
+ configurationName: t
1622
+ })).sessionState, h = (e) => (sessionStorage[`oidc.nonce.${t}`] = e.nonce, X(i)({
1623
+ type: "setNonce",
1624
+ data: { nonce: e },
1625
+ configurationName: t
1626
+ })), g = async (e = !0) => {
1627
+ let n = (await X(i)({
1628
+ type: "getNonce",
1629
+ data: null,
1630
+ configurationName: t
1631
+ })).nonce;
1632
+ return n || (n = sessionStorage[`oidc.nonce.${t}`], console.warn("nonce not found in service worker, using sessionStorage"), e && (await h(n), n = (await g(!1)).nonce)), { nonce: n };
1633
+ }, _ = {}, v = (e) => {
1634
+ if (e == null) {
1635
+ delete _[t], delete localStorage[`oidc.login.${t}`];
1636
+ return;
1637
+ }
1638
+ _[t] = e, localStorage[`oidc.login.${t}`] = JSON.stringify(e);
1639
+ }, y = () => {
1640
+ if (_[t]) return _[t];
1641
+ let e = localStorage[`oidc.login.${t}`];
1642
+ if (typeof e != "string" || e === "" || e === "undefined" || e === "null") return null;
1643
+ try {
1644
+ _[t] = JSON.parse(e);
1645
+ } catch {
1646
+ return null;
1647
+ }
1648
+ return _[t];
1649
+ }, b = async (e) => {
1650
+ await X(i)({
1651
+ type: "setDemonstratingProofOfPossessionNonce",
1652
+ data: { demonstratingProofOfPossessionNonce: e },
1653
+ configurationName: t
1654
+ });
1655
+ }, x = async () => (await X(i)({
1656
+ type: "getDemonstratingProofOfPossessionNonce",
1657
+ data: null,
1658
+ configurationName: t
1659
+ })).demonstratingProofOfPossessionNonce, S = async (e) => {
1660
+ let n = JSON.stringify(e);
1661
+ await X(i)({
1662
+ type: "setDemonstratingProofOfPossessionJwk",
1663
+ data: { demonstratingProofOfPossessionJwkJson: n },
1664
+ configurationName: t
1665
+ });
1666
+ }, C = async () => {
1667
+ let e = await X(i)({
1668
+ type: "getDemonstratingProofOfPossessionJwk",
1669
+ data: null,
1670
+ configurationName: t
1671
+ });
1672
+ return e.demonstratingProofOfPossessionJwkJson ? JSON.parse(e.demonstratingProofOfPossessionJwkJson) : null;
1673
+ }, w = async (e = !0) => {
1674
+ let n = (await X(i)({
1675
+ type: "getState",
1676
+ data: null,
1677
+ configurationName: t
1678
+ })).state;
1679
+ return n || (n = sessionStorage[`oidc.state.${t}`], console.warn("state not found in service worker, using sessionStorage"), e && (await T(n), n = await w(!1))), n;
1680
+ }, T = async (e) => (sessionStorage[`oidc.state.${t}`] = e, X(i)({
1681
+ type: "setState",
1682
+ data: { state: e },
1683
+ configurationName: t
1684
+ })), E = async (e = !0) => {
1685
+ let n = (await X(i)({
1686
+ type: "getCodeVerifier",
1687
+ data: null,
1688
+ configurationName: t
1689
+ })).codeVerifier;
1690
+ return n || (n = sessionStorage[`oidc.code_verifier.${t}`], console.warn("codeVerifier not found in service worker, using sessionStorage"), e && (await D(n), n = await E(!1))), n;
1691
+ }, D = async (e) => (sessionStorage[`oidc.code_verifier.${t}`] = e, X(i)({
1692
+ type: "setCodeVerifier",
1693
+ data: { codeVerifier: e },
1694
+ configurationName: t
1695
+ }));
1696
+ return {
1697
+ clearAsync: u,
1698
+ initAsync: d,
1699
+ startKeepAliveServiceWorker: () => f(e.service_worker_keep_alive_path),
1700
+ setSessionStateAsync: p,
1701
+ getSessionStateAsync: m,
1702
+ setNonceAsync: h,
1703
+ getNonceAsync: g,
1704
+ setLoginParams: v,
1705
+ getLoginParams: y,
1706
+ getStateAsync: w,
1707
+ setStateAsync: T,
1708
+ getCodeVerifierAsync: E,
1709
+ setCodeVerifierAsync: D,
1710
+ setDemonstratingProofOfPossessionNonce: b,
1711
+ getDemonstratingProofOfPossessionNonce: x,
1712
+ setDemonstratingProofOfPossessionJwkAsync: S,
1713
+ getDemonstratingProofOfPossessionJwkAsync: C,
1714
+ signalAsync: (e, n) => X(i, n)({
1715
+ ...e,
1716
+ configurationName: e.configurationName ?? t
1717
+ })
1718
+ };
1719
+ }, $e = async (e, t, n, r) => {
1720
+ let i = await $(e, t);
1721
+ if (!i) throw Error(`signalServiceWorkerAsync: no service worker registered for configuration "${t}"`);
1722
+ return i.signalAsync(n, r);
1723
+ }, et = class e {
1724
+ constructor(e) {
1725
+ this._oidc = e;
1726
+ }
1727
+ subscribeEvents(e) {
1728
+ return this._oidc.subscribeEvents(e);
1729
+ }
1730
+ removeEventSubscription(e) {
1731
+ this._oidc.removeEventSubscription(e);
1732
+ }
1733
+ publishEvent(e, t) {
1734
+ this._oidc.publishEvent(e, t);
1726
1735
  }
1727
1736
  static {
1728
- this.getOrCreate = (n, r = new e()) => (e, i = "default") => new t($.getOrCreate(n, r)(e, i));
1737
+ this.getOrCreate = (t, n = new O()) => (r, i = "default") => new e(R.getOrCreate(t, n)(r, i));
1729
1738
  }
1730
- static get(e = "default") {
1731
- return new t($.get(e));
1739
+ static get(t = "default") {
1740
+ return new e(R.get(t));
1732
1741
  }
1733
1742
  static {
1734
- this.eventNames = $.eventNames;
1743
+ this.eventNames = R.eventNames;
1735
1744
  }
1736
1745
  tryKeepExistingSessionAsync() {
1737
1746
  return this._oidc.tryKeepExistingSessionAsync();
@@ -1762,21 +1771,21 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
1762
1771
  }
1763
1772
  async getValidTokenAsync(e = 200, t = 50) {
1764
1773
  let n = this._oidc;
1765
- return b({
1774
+ return ze({
1766
1775
  getTokens: () => n.tokens,
1767
1776
  configuration: {
1768
1777
  token_automatic_renew_mode: n.configuration.token_automatic_renew_mode,
1769
1778
  refresh_time_before_tokens_expiration_in_second: n.configuration.refresh_time_before_tokens_expiration_in_second
1770
1779
  },
1771
1780
  syncTokensInfoAsync: async () => {
1772
- let { status: e } = await K(n)(n.configuration, n.configurationName, n.tokens, !1);
1781
+ let { status: e } = await V(n)(n.configuration, n.configurationName, n.tokens, !1);
1773
1782
  return e;
1774
1783
  },
1775
1784
  renewTokensAsync: n.renewTokensAsync.bind(n)
1776
1785
  }, e, t);
1777
1786
  }
1778
1787
  fetchWithTokens(e, t = !1) {
1779
- return Je(e, this._oidc, t);
1788
+ return Te(e, this._oidc, t);
1780
1789
  }
1781
1790
  async userInfoAsync(e = !1, t = !1) {
1782
1791
  return this._oidc.userInfoAsync(e, t);
@@ -1784,6 +1793,38 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
1784
1793
  userInfo() {
1785
1794
  return this._oidc.userInfo;
1786
1795
  }
1787
- };
1796
+ async signalServiceWorker(e, t) {
1797
+ return $e(this._oidc.configuration, this._oidc.configurationName, e, t);
1798
+ }
1799
+ }, tt = "1.0.0", nt = {
1800
+ SKIP_WAITING: "SKIP_WAITING",
1801
+ CLAIM: "claim",
1802
+ CLEAR: "clear",
1803
+ INIT: "init",
1804
+ SET_STATE: "setState",
1805
+ GET_STATE: "getState",
1806
+ SET_CODE_VERIFIER: "setCodeVerifier",
1807
+ GET_CODE_VERIFIER: "getCodeVerifier",
1808
+ SET_SESSION_STATE: "setSessionState",
1809
+ GET_SESSION_STATE: "getSessionState",
1810
+ SET_NONCE: "setNonce",
1811
+ GET_NONCE: "getNonce",
1812
+ SET_DPOP_NONCE: "setDemonstratingProofOfPossessionNonce",
1813
+ GET_DPOP_NONCE: "getDemonstratingProofOfPossessionNonce",
1814
+ SET_DPOP_JWK: "setDemonstratingProofOfPossessionJwk",
1815
+ GET_DPOP_JWK: "getDemonstratingProofOfPossessionJwk"
1816
+ }, rt = {
1817
+ ACCESS_TOKEN: "ACCESS_TOKEN_SECURED_BY_OIDC_SERVICE_WORKER",
1818
+ REFRESH_TOKEN: "REFRESH_TOKEN_SECURED_BY_OIDC_SERVICE_WORKER",
1819
+ NONCE_TOKEN: "NONCE_SECURED_BY_OIDC_SERVICE_WORKER",
1820
+ CODE_VERIFIER: "CODE_VERIFIER_SECURED_BY_OIDC_SERVICE_WORKER"
1821
+ }, it = "DPOP_SECURED_BY_OIDC_SERVICE_WORKER", at = {
1822
+ TAB_ID: "oidc.tabId.",
1823
+ STATE: "oidc.state.",
1824
+ NONCE: "oidc.nonce.",
1825
+ CODE_VERIFIER: "oidc.code_verifier.",
1826
+ LOGIN_PARAMS: "oidc.login.",
1827
+ SW_VERSION_MISMATCH_RELOAD: "oidc.sw.version_mismatch_reload."
1828
+ }, ot = "oidc.sw.controllerchange_reload_count", st = (e, t) => `${e}${t}`, ct = (e, t, n = "default") => `${e}_${t}#tabId=${n}`, lt = (e, t = "default") => `${it}_${e}#tabId=${t}`, ut = (e) => typeof e == "string" ? Object.values(nt).includes(e) : !1;
1788
1829
  //#endregion
1789
- export { et as OidcClient, e as OidcLocation, l as TokenAutomaticRenewMode, m as TokenRenewMode, Xe as getFetchDefault, Y as getParseQueryStringFromLocation, Be as getPath };
1830
+ export { it as DPOP_TOKEN_PLACEHOLDER_PREFIX, et as OidcClient, O as OidcLocation, tt as PROTOCOL_VERSION, at as STORAGE_KEY_PREFIX, ot as SW_CONTROLLER_CHANGE_RELOAD_COUNT_KEY, nt as ServiceWorkerMessageType, rt as TOKEN_PLACEHOLDERS, F as TokenAutomaticRenewMode, U as TokenRenewMode, lt as buildDpopSecuredPlaceholder, ct as buildSecuredTokenPlaceholder, st as buildStorageKey, De as getFetchDefault, N as getParseQueryStringFromLocation, _e as getPath, ut as isServiceWorkerMessageType, $e as signalServiceWorkerAsync };