@axa-fr/oidc-client 7.27.11 → 7.27.12

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