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