@axa-fr/oidc-client 7.7.0-beta.1072 → 7.7.0-beta.1075

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,5 +1,5 @@
1
- const R = console;
2
- class Ce {
1
+ const F = console;
2
+ class Ie {
3
3
  constructor(e, s, t, o = 2e3, i = !0) {
4
4
  this._callback = e, this._client_id = s, this._url = t, this._interval = o || 2e3, this._stopOnError = i;
5
5
  const r = t.indexOf("/", t.indexOf("//") + 2);
@@ -13,20 +13,20 @@ class Ce {
13
13
  });
14
14
  }
15
15
  _message(e) {
16
- e.origin === this._frame_origin && e.source === this._frame.contentWindow && (e.data === "error" ? (R.error("CheckSessionIFrame: error message from check session op iframe"), this._stopOnError && this.stop()) : e.data === "changed" ? (R.debug(e), R.debug("CheckSessionIFrame: changed message from check session op iframe"), this.stop(), this._callback()) : R.debug("CheckSessionIFrame: " + e.data + " message from check session op iframe"));
16
+ e.origin === this._frame_origin && e.source === this._frame.contentWindow && (e.data === "error" ? (F.error("CheckSessionIFrame: error message from check session op iframe"), this._stopOnError && this.stop()) : e.data === "changed" ? (F.debug(e), F.debug("CheckSessionIFrame: changed message from check session op iframe"), this.stop(), this._callback()) : F.debug("CheckSessionIFrame: " + e.data + " message from check session op iframe"));
17
17
  }
18
18
  start(e) {
19
- R.debug("CheckSessionIFrame.start :" + e), this.stop();
19
+ F.debug("CheckSessionIFrame.start :" + e), this.stop();
20
20
  const s = () => {
21
21
  this._frame.contentWindow.postMessage(this._client_id + " " + e, this._frame_origin);
22
22
  };
23
23
  s(), this._timer = window.setInterval(s, this._interval);
24
24
  }
25
25
  stop() {
26
- this._timer && (R.debug("CheckSessionIFrame.stop"), window.clearInterval(this._timer), this._timer = null);
26
+ this._timer && (F.debug("CheckSessionIFrame.stop"), window.clearInterval(this._timer), this._timer = null);
27
27
  }
28
28
  }
29
- const k = {
29
+ const m = {
30
30
  service_worker_not_supported_by_browser: "service_worker_not_supported_by_browser",
31
31
  token_aquired: "token_aquired",
32
32
  logout_from_another_tab: "logout_from_another_tab",
@@ -53,66 +53,66 @@ const k = {
53
53
  syncTokensAsync_begin: "syncTokensAsync_begin",
54
54
  syncTokensAsync_end: "syncTokensAsync_end",
55
55
  syncTokensAsync_error: "syncTokensAsync_error"
56
- }, E = (n, e = sessionStorage) => {
57
- const s = (p) => (e[`oidc.${n}`] = JSON.stringify({ tokens: null, status: p }), Promise.resolve()), t = async () => {
56
+ }, O = (n, e = sessionStorage) => {
57
+ const s = (w) => (e[`oidc.${n}`] = JSON.stringify({ tokens: null, status: w }), Promise.resolve()), t = async () => {
58
58
  if (!e[`oidc.${n}`])
59
59
  return e[`oidc.${n}`] = JSON.stringify({ tokens: null, status: null }), { tokens: null, status: null };
60
- const p = JSON.parse(e[`oidc.${n}`]);
61
- return Promise.resolve({ tokens: p.tokens, status: p.status });
62
- }, o = (p) => {
63
- e[`oidc.${n}`] = JSON.stringify({ tokens: p });
64
- }, i = async (p) => {
65
- e[`oidc.session_state.${n}`] = p;
66
- }, r = async () => e[`oidc.session_state.${n}`], l = (p) => {
67
- e[`oidc.nonce.${n}`] = p.nonce;
68
- }, a = (p) => {
69
- e[`oidc.jwk.${n}`] = JSON.stringify(p);
70
- }, f = () => JSON.parse(e[`oidc.jwk.${n}`]), c = async () => ({ nonce: e[`oidc.nonce.${n}`] }), _ = (p) => {
71
- e[`oidc.dpop_nonce.${n}`] = p;
72
- }, h = () => e[`oidc.dpop_nonce.${n}`], u = () => e[`oidc.${n}`] ? JSON.stringify({ tokens: JSON.parse(e[`oidc.${n}`]).tokens }) : null;
73
- let y = {};
60
+ const w = JSON.parse(e[`oidc.${n}`]);
61
+ return Promise.resolve({ tokens: w.tokens, status: w.status });
62
+ }, o = (w) => {
63
+ e[`oidc.${n}`] = JSON.stringify({ tokens: w });
64
+ }, i = async (w) => {
65
+ e[`oidc.session_state.${n}`] = w;
66
+ }, r = async () => e[`oidc.session_state.${n}`], c = (w) => {
67
+ e[`oidc.nonce.${n}`] = w.nonce;
68
+ }, a = (w) => {
69
+ e[`oidc.jwk.${n}`] = JSON.stringify(w);
70
+ }, y = () => JSON.parse(e[`oidc.jwk.${n}`]), l = async () => ({ nonce: e[`oidc.nonce.${n}`] }), u = (w) => {
71
+ e[`oidc.dpop_nonce.${n}`] = w;
72
+ }, f = () => e[`oidc.dpop_nonce.${n}`], d = () => e[`oidc.${n}`] ? JSON.stringify({ tokens: JSON.parse(e[`oidc.${n}`]).tokens }) : null;
73
+ let _ = {};
74
74
  return {
75
75
  clearAsync: s,
76
76
  initAsync: t,
77
77
  setTokens: o,
78
- getTokens: u,
78
+ getTokens: d,
79
79
  setSessionStateAsync: i,
80
80
  getSessionStateAsync: r,
81
- setNonceAsync: l,
82
- getNonceAsync: c,
83
- setLoginParams: (p) => {
84
- y[n] = p, e[`oidc.login.${n}`] = JSON.stringify(p);
81
+ setNonceAsync: c,
82
+ getNonceAsync: l,
83
+ setLoginParams: (w) => {
84
+ _[n] = w, e[`oidc.login.${n}`] = JSON.stringify(w);
85
85
  },
86
86
  getLoginParams: () => {
87
- const p = e[`oidc.login.${n}`];
88
- return y[n] || (y[n] = JSON.parse(p)), y[n];
87
+ const w = e[`oidc.login.${n}`];
88
+ return _[n] || (_[n] = JSON.parse(w)), _[n];
89
89
  },
90
90
  getStateAsync: async () => e[`oidc.state.${n}`],
91
- setStateAsync: async (p) => {
92
- e[`oidc.state.${n}`] = p;
91
+ setStateAsync: async (w) => {
92
+ e[`oidc.state.${n}`] = w;
93
93
  },
94
94
  getCodeVerifierAsync: async () => e[`oidc.code_verifier.${n}`],
95
- setCodeVerifierAsync: async (p) => {
96
- e[`oidc.code_verifier.${n}`] = p;
95
+ setCodeVerifierAsync: async (w) => {
96
+ e[`oidc.code_verifier.${n}`] = w;
97
97
  },
98
- setDemonstratingProofOfPossessionNonce: _,
99
- getDemonstratingProofOfPossessionNonce: h,
98
+ setDemonstratingProofOfPossessionNonce: u,
99
+ getDemonstratingProofOfPossessionNonce: f,
100
100
  setDemonstratingProofOfPossessionJwkAsync: a,
101
- getDemonstratingProofOfPossessionJwkAsync: f
101
+ getDemonstratingProofOfPossessionJwkAsync: y
102
102
  };
103
- }, xe = (n) => decodeURIComponent(Array.prototype.map.call(atob(n), (e) => "%" + ("00" + e.charCodeAt(0).toString(16)).slice(-2)).join("")), Ne = (n) => JSON.parse(xe(n.split(".")[1].replace("-", "+").replace("_", "/"))), ae = (n) => {
103
+ }, Ce = (n) => decodeURIComponent(Array.prototype.map.call(atob(n), (e) => "%" + ("00" + e.charCodeAt(0).toString(16)).slice(-2)).join("")), xe = (n) => JSON.parse(Ce(n.split(".")[1].replace("-", "+").replace("_", "/"))), re = (n) => {
104
104
  try {
105
- return n && Le(n, ".") === 2 ? Ne(n) : null;
105
+ return n && Ne(n, ".") === 2 ? xe(n) : null;
106
106
  } catch (e) {
107
107
  console.warn(e);
108
108
  }
109
109
  return null;
110
- }, Le = (n, e) => n.split(e).length - 1, z = {
110
+ }, Ne = (n, e) => n.split(e).length - 1, Y = {
111
111
  access_token_or_id_token_invalid: "access_token_or_id_token_invalid",
112
112
  access_token_invalid: "access_token_invalid",
113
113
  id_token_invalid: "id_token_invalid"
114
114
  };
115
- function We(n, e, s) {
115
+ function Le(n, e, s) {
116
116
  if (n.issuedAt) {
117
117
  if (typeof n.issuedAt == "string")
118
118
  return parseInt(n.issuedAt, 10);
@@ -120,23 +120,23 @@ function We(n, e, s) {
120
120
  return e && e.iat ? e.iat : s && s.iat ? s.iat : (/* @__PURE__ */ new Date()).getTime() / 1e3;
121
121
  return n.issuedAt;
122
122
  }
123
- const ge = (n, e = null, s) => {
123
+ const _e = (n, e = null, s) => {
124
124
  if (!n)
125
125
  return null;
126
126
  let t;
127
127
  const o = typeof n.expiresIn == "string" ? parseInt(n.expiresIn, 10) : n.expiresIn;
128
- n.accessTokenPayload !== void 0 ? t = n.accessTokenPayload : t = ae(n.accessToken);
129
- const i = n.idTokenPayload ? n.idTokenPayload : ae(n.idToken), r = i && i.exp ? i.exp : Number.MAX_VALUE, l = t && t.exp ? t.exp : n.issuedAt + o;
130
- n.issuedAt = We(n, t, i);
128
+ n.accessTokenPayload !== void 0 ? t = n.accessTokenPayload : t = re(n.accessToken);
129
+ const i = n.idTokenPayload ? n.idTokenPayload : re(n.idToken), r = i && i.exp ? i.exp : Number.MAX_VALUE, c = t && t.exp ? t.exp : n.issuedAt + o;
130
+ n.issuedAt = Le(n, t, i);
131
131
  let a;
132
- n.expiresAt ? a = n.expiresAt : s === z.access_token_invalid ? a = l : s === z.id_token_invalid ? a = r : a = r < l ? r : l;
133
- const f = { ...n, idTokenPayload: i, accessTokenPayload: t, expiresAt: a };
132
+ n.expiresAt ? a = n.expiresAt : s === Y.access_token_invalid ? a = c : s === Y.id_token_invalid ? a = r : a = r < c ? r : c;
133
+ const y = { ...n, idTokenPayload: i, accessTokenPayload: t, expiresAt: a };
134
134
  if (e != null && "refreshToken" in e && !("refreshToken" in n)) {
135
- const c = e.refreshToken;
136
- return { ...f, refreshToken: c };
135
+ const l = e.refreshToken;
136
+ return { ...y, refreshToken: l };
137
137
  }
138
- return f;
139
- }, te = (n, e, s) => {
138
+ return y;
139
+ }, se = (n, e, s) => {
140
140
  if (!n)
141
141
  return null;
142
142
  if (!n.issued_at) {
@@ -151,22 +151,22 @@ const ge = (n, e = null, s) => {
151
151
  tokenType: n.token_type,
152
152
  issuedAt: n.issued_at
153
153
  };
154
- return "refresh_token" in n && (t.refreshToken = n.refresh_token), n.accessTokenPayload !== void 0 && (t.accessTokenPayload = n.accessTokenPayload), n.idTokenPayload !== void 0 && (t.idTokenPayload = n.idTokenPayload), ge(t, e, s);
155
- }, U = (n, e) => {
154
+ return "refresh_token" in n && (t.refreshToken = n.refresh_token), n.accessTokenPayload !== void 0 && (t.accessTokenPayload = n.accessTokenPayload), n.idTokenPayload !== void 0 && (t.idTokenPayload = n.idTokenPayload), _e(t, e, s);
155
+ }, M = (n, e) => {
156
156
  const s = (/* @__PURE__ */ new Date()).getTime() / 1e3, t = e - s;
157
157
  return Math.round(t - n);
158
- }, Q = (n) => n ? U(0, n.expiresAt) > 0 : !1, De = async (n, e = 200, s = 50) => {
158
+ }, z = (n) => n ? M(0, n.expiresAt) > 0 : !1, We = async (n, e = 200, s = 50) => {
159
159
  let t = s;
160
160
  if (!n.tokens)
161
161
  return null;
162
- for (; !Q(n.tokens) && t > 0; )
163
- await D(e), t = t - 1;
162
+ for (; !z(n.tokens) && t > 0; )
163
+ await $(e), t = t - 1;
164
164
  return {
165
- isTokensValid: Q(n.tokens),
165
+ isTokensValid: z(n.tokens),
166
166
  tokens: n.tokens,
167
167
  numberWaited: t - s
168
168
  };
169
- }, ke = (n, e, s) => {
169
+ }, ye = (n, e, s) => {
170
170
  if (n.idTokenPayload) {
171
171
  const t = n.idTokenPayload;
172
172
  if (s.issuer !== t.iss)
@@ -181,59 +181,59 @@ const ge = (n, e = null, s) => {
181
181
  return { isValid: !1, reason: `Nonce does not match (idTokenPayload nonce) ${t.nonce} !== (nonce) ${e}` };
182
182
  }
183
183
  return { isValid: !0, reason: "" };
184
- }, K = function() {
184
+ }, J = function() {
185
185
  const n = function() {
186
- let a, f;
187
- const c = (function() {
188
- const h = {}, u = {
189
- setTimeout: function(d, g, w) {
190
- h[g] = setTimeout(function() {
191
- d.postMessage(g), h[g] = null;
192
- }, w);
186
+ let a, y;
187
+ const l = (function() {
188
+ const f = {}, d = {
189
+ setTimeout: function(h, g, A) {
190
+ f[g] = setTimeout(function() {
191
+ h.postMessage(g), f[g] = null;
192
+ }, A);
193
193
  },
194
- setInterval: function(d, g, w) {
195
- h[g] = setInterval(function() {
196
- d.postMessage(g);
197
- }, w);
194
+ setInterval: function(h, g, A) {
195
+ f[g] = setInterval(function() {
196
+ h.postMessage(g);
197
+ }, A);
198
198
  },
199
- clearTimeout: function(d, g) {
200
- clearTimeout(h[g]), h[g] = null;
199
+ clearTimeout: function(h, g) {
200
+ clearTimeout(f[g]), f[g] = null;
201
201
  },
202
- clearInterval: function(d, g) {
203
- clearInterval(h[g]), h[g] = null;
202
+ clearInterval: function(h, g) {
203
+ clearInterval(f[g]), f[g] = null;
204
204
  }
205
205
  };
206
- function y(d, g) {
207
- const w = g.data[0], T = g.data[1], v = g.data[2];
208
- u[w] && u[w](d, T, v);
206
+ function _(h, g) {
207
+ const A = g.data[0], v = g.data[1], T = g.data[2];
208
+ d[A] && d[A](h, v, T);
209
209
  }
210
- this.onmessage = function(d) {
211
- y(self, d);
212
- }, this.onconnect = function(d) {
213
- const g = d.ports[0];
214
- g.onmessage = function(w) {
215
- y(g, w);
210
+ this.onmessage = function(h) {
211
+ _(self, h);
212
+ }, this.onconnect = function(h) {
213
+ const g = h.ports[0];
214
+ g.onmessage = function(A) {
215
+ _(g, A);
216
216
  };
217
217
  };
218
218
  }).toString();
219
219
  try {
220
- const h = new Blob(["(", c, ")()"], { type: "application/javascript" });
221
- f = URL.createObjectURL(h);
220
+ const f = new Blob(["(", l, ")()"], { type: "application/javascript" });
221
+ y = URL.createObjectURL(f);
222
222
  } catch {
223
223
  return null;
224
224
  }
225
- const _ = typeof process > "u";
225
+ const u = typeof process > "u";
226
226
  try {
227
227
  if (SharedWorker)
228
- return a = new SharedWorker(f), a.port;
228
+ return a = new SharedWorker(y), a.port;
229
229
  } catch {
230
- _ && console.warn("SharedWorker not available");
230
+ u && console.warn("SharedWorker not available");
231
231
  }
232
232
  try {
233
233
  if (Worker)
234
- return a = new Worker(f), a;
234
+ return a = new Worker(y), a;
235
235
  } catch {
236
- _ && console.warn("Worker not available");
236
+ u && console.warn("Worker not available");
237
237
  }
238
238
  return null;
239
239
  }();
@@ -253,35 +253,35 @@ const ge = (n, e = null, s) => {
253
253
  };
254
254
  }(), s = {}, t = {};
255
255
  n.onmessage = function(a) {
256
- const f = a.data, c = s[f];
257
- if (c) {
258
- c(), s[f] = null;
256
+ const y = a.data, l = s[y];
257
+ if (l) {
258
+ l(), s[y] = null;
259
259
  return;
260
260
  }
261
- const _ = t[f];
262
- _ && _();
261
+ const u = t[y];
262
+ u && u();
263
263
  };
264
- function o(a, f) {
265
- const c = e();
266
- return n.postMessage(["setTimeout", c, f]), s[c] = a, c;
264
+ function o(a, y) {
265
+ const l = e();
266
+ return n.postMessage(["setTimeout", l, y]), s[l] = a, l;
267
267
  }
268
268
  function i(a) {
269
269
  n.postMessage(["clearTimeout", a]), s[a] = null;
270
270
  }
271
- function r(a, f) {
272
- const c = e();
273
- return n.postMessage(["setInterval", c, f]), t[c] = a, c;
271
+ function r(a, y) {
272
+ const l = e();
273
+ return n.postMessage(["setInterval", l, y]), t[l] = a, l;
274
274
  }
275
- function l(a) {
275
+ function c(a) {
276
276
  n.postMessage(["clearInterval", a]), t[a] = null;
277
277
  }
278
278
  return {
279
279
  setTimeout: o,
280
280
  clearTimeout: i,
281
281
  setInterval: r,
282
- clearInterval: l
282
+ clearInterval: c
283
283
  };
284
- }(), ce = "7.7.0-beta.1072", me = (n) => {
284
+ }(), ae = "7.7.0-beta.1075", ge = (n) => {
285
285
  const e = n.appVersion, s = n.userAgent, t = "-";
286
286
  let o = t;
287
287
  const i = [
@@ -313,8 +313,8 @@ const ge = (n, e = null, s) => {
313
313
  { s: "OS/2", r: /OS\/2/ },
314
314
  { s: "Search Bot", r: /(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/ }
315
315
  ];
316
- for (const l in i) {
317
- const a = i[l];
316
+ for (const c in i) {
317
+ const a = i[c];
318
318
  if (a.r.test(s)) {
319
319
  o = a.s;
320
320
  break;
@@ -328,8 +328,8 @@ const ge = (n, e = null, s) => {
328
328
  r = /(?:Android|Mac OS|Mac OS X|MacPPC|MacIntel|Mac_PowerPC|Macintosh) ([._\d]+)/.exec(s)[1];
329
329
  break;
330
330
  case "iOS": {
331
- const l = /OS (\d+)_(\d+)_?(\d+)?/.exec(e);
332
- r = l[1] + "." + l[2] + "." + (parseInt(l[3]) | 0);
331
+ const c = /OS (\d+)_(\d+)_?(\d+)?/.exec(e);
332
+ r = c[1] + "." + c[2] + "." + (parseInt(c[3]) | 0);
333
333
  break;
334
334
  }
335
335
  }
@@ -338,7 +338,7 @@ const ge = (n, e = null, s) => {
338
338
  osVersion: r
339
339
  };
340
340
  };
341
- function $e() {
341
+ function De() {
342
342
  const n = navigator.userAgent;
343
343
  let e, s = n.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
344
344
  if (/trident/i.test(s[1]))
@@ -356,39 +356,43 @@ function $e() {
356
356
  version: s[1]
357
357
  };
358
358
  }
359
- let le = null;
360
- const D = (n) => new Promise((e) => K.setTimeout(e, n));
361
- let q;
362
- const pe = () => {
359
+ let ce = null;
360
+ const $ = (n) => new Promise((e) => J.setTimeout(e, n));
361
+ let j;
362
+ const ke = () => {
363
363
  try {
364
- const e = me(navigator).os === "Android" ? 240 : 150;
365
- q = new AbortController(), fetch(`/OidcKeepAliveServiceWorker.json?minSleepSeconds=${e}`, { signal: q.signal }).catch((t) => {
364
+ const e = ge(navigator).os === "Android" ? 240 : 150;
365
+ j = new AbortController(), fetch(`/OidcKeepAliveServiceWorker.json?minSleepSeconds=${e}`, { signal: j.signal }).catch((t) => {
366
366
  console.log(t);
367
- }), D(e * 1e3).then(pe);
367
+ }), $(e * 1e3).then(ke);
368
368
  } catch (n) {
369
369
  console.log(n);
370
370
  }
371
- }, ue = () => {
372
- q && q.abort();
371
+ }, $e = () => {
372
+ j && j.abort();
373
373
  }, Re = () => fetch("/OidcKeepAliveServiceWorker.json", {
374
374
  headers: {
375
375
  "oidc-vanilla": "true"
376
376
  }
377
377
  }).then((n) => n.statusText === "oidc-service-worker").catch((n) => {
378
378
  console.log(n);
379
- }), Fe = (n) => !!(n.os === "iOS" && n.osVersion.startsWith("12") || n.os === "Mac OS X" && n.osVersion.startsWith("10_15_6")), P = (n) => (e) => new Promise(function(s, t) {
379
+ }), Fe = (n) => async (e, s) => {
380
+ s(), await e.update();
381
+ const t = await e.unregister();
382
+ console.log(`Service worker unregistering ${t}`), await $(2e3), n.reload();
383
+ }, Ve = (n) => !!(n.os === "iOS" && n.osVersion.startsWith("12") || n.os === "Mac OS X" && n.osVersion.startsWith("10_15_6")), b = (n) => (e) => new Promise(function(s, t) {
380
384
  const o = new MessageChannel();
381
385
  o.port1.onmessage = function(i) {
382
386
  i.data && i.data.error ? t(i.data.error) : s(i.data);
383
387
  }, n.active.postMessage(e, [o.port2]);
384
- }), x = async (n, e) => {
388
+ }), E = async (n, e) => {
385
389
  if (typeof window > "u" || typeof navigator > "u" || !navigator.serviceWorker || !n)
386
390
  return null;
387
- const { name: s, version: t } = $e();
391
+ const { name: s, version: t } = De();
388
392
  if (s === "chrome" && parseInt(t) <= 70 || s === "opera" && (!t || parseInt(t.split(".")[0]) < 80) || s === "ie")
389
393
  return null;
390
- const o = me(navigator);
391
- if (Fe(o))
394
+ const o = ge(navigator);
395
+ if (Ve(o))
392
396
  return null;
393
397
  const i = await navigator.serviceWorker.register(n);
394
398
  try {
@@ -396,258 +400,250 @@ const pe = () => {
396
400
  } catch {
397
401
  return null;
398
402
  }
399
- const r = async (m) => P(i)({ type: "clear", data: { status: m }, configurationName: e }), l = async (m, S, A) => {
400
- const b = await P(i)({
403
+ const r = async (k) => b(i)({ type: "clear", data: { status: k }, configurationName: e }), c = async (k, S, x) => {
404
+ const p = await b(i)({
401
405
  type: "init",
402
406
  data: {
403
- oidcServerConfiguration: m,
407
+ oidcServerConfiguration: k,
404
408
  where: S,
405
409
  oidcConfiguration: {
406
- token_renew_mode: A.token_renew_mode,
407
- service_worker_convert_all_requests_to_cors: A.service_worker_convert_all_requests_to_cors
410
+ token_renew_mode: x.token_renew_mode,
411
+ service_worker_convert_all_requests_to_cors: x.service_worker_convert_all_requests_to_cors
408
412
  }
409
413
  },
410
414
  configurationName: e
411
- }), B = b.version;
412
- if (B !== ce)
413
- if (console.warn(`Service worker ${B} version mismatch with js client version ${ce}, unregistering and reloading`), A.service_worker_update_require_callback)
414
- await A.service_worker_update_require_callback(i, ue);
415
- else {
416
- ue(), await i.update();
417
- const Y = await i.unregister();
418
- console.log(`Service worker unregistering ${Y}`), await D(2e3), window.location.reload();
419
- }
420
- return { tokens: te(b.tokens, null, A.token_renew_mode), status: b.status };
415
+ }), N = p.version;
416
+ return N !== ae && (console.warn(`Service worker ${N} version mismatch with js client version ${ae}, unregistering and reloading`), await x.service_worker_update_require_callback(i, $e)), { tokens: se(p.tokens, null, x.token_renew_mode), status: p.status };
421
417
  }, a = () => {
422
- le == null && (le = "not_null", pe());
423
- }, f = (m) => P(i)({ type: "setSessionState", data: { sessionState: m }, configurationName: e }), c = async () => (await P(i)({ type: "getSessionState", data: null, configurationName: e })).sessionState, _ = (m) => (sessionStorage[`oidc.nonce.${e}`] = m.nonce, P(i)({ type: "setNonce", data: { nonce: m }, configurationName: e })), h = async () => {
424
- let S = (await P(i)({ type: "getNonce", data: null, configurationName: e })).nonce;
418
+ ce == null && (ce = "not_null", ke());
419
+ }, y = (k) => b(i)({ type: "setSessionState", data: { sessionState: k }, configurationName: e }), l = async () => (await b(i)({ type: "getSessionState", data: null, configurationName: e })).sessionState, u = (k) => (sessionStorage[`oidc.nonce.${e}`] = k.nonce, b(i)({ type: "setNonce", data: { nonce: k }, configurationName: e })), f = async () => {
420
+ let S = (await b(i)({ type: "getNonce", data: null, configurationName: e })).nonce;
425
421
  return S || (S = sessionStorage[`oidc.nonce.${e}`], console.warn("nonce not found in service worker, using sessionStorage")), { nonce: S };
426
422
  };
427
- let u = {};
423
+ let d = {};
428
424
  return {
429
425
  clearAsync: r,
430
- initAsync: l,
426
+ initAsync: c,
431
427
  startKeepAliveServiceWorker: a,
432
428
  isServiceWorkerProxyActiveAsync: Re,
433
- setSessionStateAsync: f,
434
- getSessionStateAsync: c,
435
- setNonceAsync: _,
436
- getNonceAsync: h,
437
- setLoginParams: (m) => {
438
- u[e] = m, localStorage[`oidc.login.${e}`] = JSON.stringify(m);
429
+ setSessionStateAsync: y,
430
+ getSessionStateAsync: l,
431
+ setNonceAsync: u,
432
+ getNonceAsync: f,
433
+ setLoginParams: (k) => {
434
+ d[e] = k, localStorage[`oidc.login.${e}`] = JSON.stringify(k);
439
435
  },
440
436
  getLoginParams: () => {
441
- const m = localStorage[`oidc.login.${e}`];
442
- return u[e] || (u[e] = JSON.parse(m)), u[e];
437
+ const k = localStorage[`oidc.login.${e}`];
438
+ return d[e] || (d[e] = JSON.parse(k)), d[e];
443
439
  },
444
440
  getStateAsync: async () => {
445
- let S = (await P(i)({ type: "getState", data: null, configurationName: e })).state;
441
+ let S = (await b(i)({ type: "getState", data: null, configurationName: e })).state;
446
442
  return S || (S = sessionStorage[`oidc.state.${e}`], console.warn("state not found in service worker, using sessionStorage")), S;
447
443
  },
448
- setStateAsync: async (m) => (sessionStorage[`oidc.state.${e}`] = m, P(i)({ type: "setState", data: { state: m }, configurationName: e })),
444
+ setStateAsync: async (k) => (sessionStorage[`oidc.state.${e}`] = k, b(i)({ type: "setState", data: { state: k }, configurationName: e })),
449
445
  getCodeVerifierAsync: async () => {
450
- let S = (await P(i)({ type: "getCodeVerifier", data: null, configurationName: e })).codeVerifier;
446
+ let S = (await b(i)({ type: "getCodeVerifier", data: null, configurationName: e })).codeVerifier;
451
447
  return S || (S = sessionStorage[`oidc.code_verifier.${e}`], console.warn("codeVerifier not found in service worker, using sessionStorage")), S;
452
448
  },
453
- setCodeVerifierAsync: async (m) => (sessionStorage[`oidc.code_verifier.${e}`] = m, P(i)({ type: "setCodeVerifier", data: { codeVerifier: m }, configurationName: e })),
454
- setDemonstratingProofOfPossessionNonce: (m) => {
455
- P(i)({ type: "setDemonstratingProofOfPossessionNonce", data: { demonstratingProofOfPossessionNonce: m }, configurationName: e });
449
+ setCodeVerifierAsync: async (k) => (sessionStorage[`oidc.code_verifier.${e}`] = k, b(i)({ type: "setCodeVerifier", data: { codeVerifier: k }, configurationName: e })),
450
+ setDemonstratingProofOfPossessionNonce: (k) => {
451
+ b(i)({ type: "setDemonstratingProofOfPossessionNonce", data: { demonstratingProofOfPossessionNonce: k }, configurationName: e });
456
452
  },
457
- getDemonstratingProofOfPossessionNonce: async () => (await P(i)({ type: "getDemonstratingProofOfPossessionNonce", data: null, configurationName: e })).demonstratingProofOfPossessionNonce,
458
- setDemonstratingProofOfPossessionJwkAsync: (m) => {
459
- const S = JSON.stringify(m);
460
- P(i)({ type: "setDemonstratingProofOfPossessionJwk", data: { demonstratingProofOfPossessionJwkJson: S }, configurationName: e });
453
+ getDemonstratingProofOfPossessionNonce: async () => (await b(i)({ type: "getDemonstratingProofOfPossessionNonce", data: null, configurationName: e })).demonstratingProofOfPossessionNonce,
454
+ setDemonstratingProofOfPossessionJwkAsync: (k) => {
455
+ const S = JSON.stringify(k);
456
+ b(i)({ type: "setDemonstratingProofOfPossessionJwk", data: { demonstratingProofOfPossessionJwkJson: S }, configurationName: e });
461
457
  },
462
458
  getDemonstratingProofOfPossessionJwkAsync: async () => {
463
- const m = await P(i)({ type: "getDemonstratingProofOfPossessionJwk", data: null, configurationName: e });
464
- return m.demonstratingProofOfPossessionJwkJson ? JSON.parse(m.demonstratingProofOfPossessionJwkJson) : null;
459
+ const k = await b(i)({ type: "getDemonstratingProofOfPossessionJwk", data: null, configurationName: e });
460
+ return k.demonstratingProofOfPossessionJwkJson ? JSON.parse(k.demonstratingProofOfPossessionJwkJson) : null;
465
461
  }
466
462
  };
467
463
  };
468
- async function we(n, e, s = !1, t = null) {
464
+ async function me(n, e, s = !1, t = null) {
469
465
  const o = (a) => {
470
466
  n.tokens = a;
471
467
  }, { tokens: i, status: r } = await n.synchroniseTokensAsync(e, 0, s, t, o);
472
- if (await x(n.configuration.service_worker_relative_url, n.configurationName) || await E(n.configurationName, n.configuration.storage).setTokens(n.tokens), !n.tokens) {
468
+ if (await E(n.configuration.service_worker_relative_url, n.configurationName) || await O(n.configurationName, n.configuration.storage).setTokens(n.tokens), !n.tokens) {
473
469
  await n.destroyAsync(r);
474
470
  return;
475
471
  }
476
- return n.timeoutId && (n.timeoutId = M(n, i.refreshToken, n.tokens.expiresAt, t)), n.tokens;
472
+ return n.timeoutId && (n.timeoutId = K(n, i.refreshToken, n.tokens.expiresAt, t)), n.tokens;
477
473
  }
478
- const M = (n, e, s, t = null) => {
474
+ const K = (n, e, s, t = null) => {
479
475
  const o = n.configuration.refresh_time_before_tokens_expiration_in_second;
480
- return K.setTimeout(async () => {
481
- const r = { timeLeft: U(o, s) };
482
- n.publishEvent($.eventNames.token_timer, r), await we(n, e, !1, t);
476
+ return J.setTimeout(async () => {
477
+ const r = { timeLeft: M(o, s) };
478
+ n.publishEvent(R.eventNames.token_timer, r), await me(n, e, !1, t);
483
479
  }, 1e3);
484
- }, oe = (n, e, s) => (t = null, o = null, i = null) => {
480
+ }, te = (n, e, s) => (t = null, o = null, i = null) => {
485
481
  if (!e.silent_redirect_uri || !e.silent_login_uri)
486
482
  return Promise.resolve(null);
487
483
  try {
488
- s(k.silentLoginAsync_begin, {});
484
+ s(m.silentLoginAsync_begin, {});
489
485
  let r = "";
490
486
  if (o && (t == null && (t = {}), t.state = o), i && (t == null && (t = {}), t.scope = i), t != null)
491
- for (const [_, h] of Object.entries(t))
492
- r === "" ? r = `?${encodeURIComponent(_)}=${encodeURIComponent(h)}` : r += `&${encodeURIComponent(_)}=${encodeURIComponent(h)}`;
493
- const l = e.silent_login_uri + r, a = l.indexOf("/", l.indexOf("//") + 2), f = l.substr(0, a), c = document.createElement("iframe");
494
- return c.width = "0px", c.height = "0px", c.id = `${n}_oidc_iframe`, c.setAttribute("src", l), document.body.appendChild(c), new Promise((_, h) => {
487
+ for (const [u, f] of Object.entries(t))
488
+ r === "" ? r = `?${encodeURIComponent(u)}=${encodeURIComponent(f)}` : r += `&${encodeURIComponent(u)}=${encodeURIComponent(f)}`;
489
+ const c = e.silent_login_uri + r, a = c.indexOf("/", c.indexOf("//") + 2), y = c.substr(0, a), l = document.createElement("iframe");
490
+ return l.width = "0px", l.height = "0px", l.id = `${n}_oidc_iframe`, l.setAttribute("src", c), document.body.appendChild(l), new Promise((u, f) => {
495
491
  try {
496
- let u = !1;
497
- window.onmessage = (d) => {
498
- if (d.origin === f && d.source === c.contentWindow) {
499
- const g = `${n}_oidc_tokens:`, w = `${n}_oidc_error:`, T = d.data;
500
- if (T && typeof T == "string" && !u) {
501
- if (T.startsWith(g)) {
502
- const v = JSON.parse(d.data.replace(g, ""));
503
- s(k.silentLoginAsync_end, {}), c.remove(), u = !0, _(v);
504
- } else if (T.startsWith(w)) {
505
- const v = JSON.parse(d.data.replace(w, ""));
506
- s(k.silentLoginAsync_error, v), c.remove(), u = !0, h(new Error("oidc_" + v.error));
492
+ let d = !1;
493
+ window.onmessage = (h) => {
494
+ if (h.origin === y && h.source === l.contentWindow) {
495
+ const g = `${n}_oidc_tokens:`, A = `${n}_oidc_error:`, v = h.data;
496
+ if (v && typeof v == "string" && !d) {
497
+ if (v.startsWith(g)) {
498
+ const T = JSON.parse(h.data.replace(g, ""));
499
+ s(m.silentLoginAsync_end, {}), l.remove(), d = !0, u(T);
500
+ } else if (v.startsWith(A)) {
501
+ const T = JSON.parse(h.data.replace(A, ""));
502
+ s(m.silentLoginAsync_error, T), l.remove(), d = !0, f(new Error("oidc_" + T.error));
507
503
  }
508
504
  }
509
505
  }
510
506
  };
511
- const y = e.silent_login_timeout;
507
+ const _ = e.silent_login_timeout;
512
508
  setTimeout(() => {
513
- u || (s(k.silentLoginAsync_error, { reason: "timeout" }), c.remove(), u = !0, h(new Error("timeout")));
514
- }, y);
515
- } catch (u) {
516
- c.remove(), s(k.silentLoginAsync_error, u), h(u);
509
+ d || (s(m.silentLoginAsync_error, { reason: "timeout" }), l.remove(), d = !0, f(new Error("timeout")));
510
+ }, _);
511
+ } catch (d) {
512
+ l.remove(), s(m.silentLoginAsync_error, d), f(d);
517
513
  }
518
514
  });
519
515
  } catch (r) {
520
- throw s(k.silentLoginAsync_error, r), r;
516
+ throw s(m.silentLoginAsync_error, r), r;
521
517
  }
522
- }, Ve = (n, e, s, t, o) => (i = null, r = void 0) => {
518
+ }, Ue = (n, e, s, t, o) => (i = null, r = void 0) => {
523
519
  i = { ...i };
524
- const l = (f, c, _) => oe(e, s, t.bind(o))(f, c, _);
520
+ const c = (y, l, u) => te(e, s, t.bind(o))(y, l, u);
525
521
  return (async () => {
526
- o.timeoutId && K.clearTimeout(o.timeoutId);
527
- let f;
528
- i && "state" in i && (f = i.state, delete i.state);
522
+ o.timeoutId && J.clearTimeout(o.timeoutId);
523
+ let y;
524
+ i && "state" in i && (y = i.state, delete i.state);
529
525
  try {
530
- const c = s.extras ? { ...s.extras, ...i } : i, _ = await l({
531
- ...c,
526
+ const l = s.extras ? { ...s.extras, ...i } : i, u = await c({
527
+ ...l,
532
528
  prompt: "none"
533
- }, f, r);
534
- if (_)
535
- return o.tokens = _.tokens, t(k.token_aquired, {}), o.timeoutId = M(o, o.tokens.refreshToken, o.tokens.expiresAt, i), {};
536
- } catch (c) {
537
- return c;
529
+ }, y, r);
530
+ if (u)
531
+ return o.tokens = u.tokens, t(m.token_aquired, {}), o.timeoutId = K(o, o.tokens.refreshToken, o.tokens.expiresAt, i), {};
532
+ } catch (l) {
533
+ return l;
538
534
  }
539
535
  })();
540
- }, Ue = (n, e, s) => (t, o, i, r = !1) => {
541
- const l = (a, f = void 0, c = void 0) => oe(n.configurationName, s, n.publishEvent.bind(n))(a, f, c);
542
- return new Promise((a, f) => {
536
+ }, Me = (n, e, s) => (t, o, i, r = !1) => {
537
+ const c = (a, y = void 0, l = void 0) => te(n.configurationName, s, n.publishEvent.bind(n))(a, y, l);
538
+ return new Promise((a, y) => {
543
539
  if (s.silent_login_uri && s.silent_redirect_uri && s.monitor_session && t && i && !r) {
544
- const c = () => {
540
+ const l = () => {
545
541
  n.checkSessionIFrame.stop();
546
- const _ = n.tokens;
547
- if (_ === null)
542
+ const u = n.tokens;
543
+ if (u === null)
548
544
  return;
549
- const h = _.idToken, u = _.idTokenPayload;
550
- return l({
545
+ const f = u.idToken, d = u.idTokenPayload;
546
+ return c({
551
547
  prompt: "none",
552
- id_token_hint: h,
548
+ id_token_hint: f,
553
549
  scope: s.scope || "openid"
554
- }).then((y) => {
555
- const d = y.tokens.idTokenPayload;
556
- if (u.sub === d.sub) {
557
- const g = y.sessionState;
558
- n.checkSessionIFrame.start(y.sessionState), u.sid === d.sid ? console.debug("SessionMonitor._callback: Same sub still logged in at OP, restarting check session iframe; session_state:", g) : console.debug("SessionMonitor._callback: Same sub still logged in at OP, session state has changed, restarting check session iframe; session_state:", g);
550
+ }).then((_) => {
551
+ const h = _.tokens.idTokenPayload;
552
+ if (d.sub === h.sub) {
553
+ const g = _.sessionState;
554
+ n.checkSessionIFrame.start(_.sessionState), d.sid === h.sid ? console.debug("SessionMonitor._callback: Same sub still logged in at OP, restarting check session iframe; session_state:", g) : console.debug("SessionMonitor._callback: Same sub still logged in at OP, session state has changed, restarting check session iframe; session_state:", g);
559
555
  } else
560
- console.debug("SessionMonitor._callback: Different subject signed into OP:", d.sub);
561
- }).catch(async (y) => {
562
- console.warn("SessionMonitor._callback: Silent login failed, logging out other tabs:", y);
563
- for (const [d, g] of Object.entries(e))
564
- await g.logoutOtherTabAsync(s.client_id, u.sub);
556
+ console.debug("SessionMonitor._callback: Different subject signed into OP:", h.sub);
557
+ }).catch(async (_) => {
558
+ console.warn("SessionMonitor._callback: Silent login failed, logging out other tabs:", _);
559
+ for (const [h, g] of Object.entries(e))
560
+ await g.logoutOtherTabAsync(s.client_id, d.sub);
565
561
  });
566
562
  };
567
- n.checkSessionIFrame = new Ce(c, o, t), n.checkSessionIFrame.load().then(() => {
563
+ n.checkSessionIFrame = new Ie(l, o, t), n.checkSessionIFrame.load().then(() => {
568
564
  n.checkSessionIFrame.start(i), a(n.checkSessionIFrame);
569
- }).catch((_) => {
570
- f(_);
565
+ }).catch((u) => {
566
+ y(u);
571
567
  });
572
568
  } else
573
569
  a(null);
574
570
  });
575
571
  };
576
- var Me = je, N = [], de = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
577
- for (var j = 0, Ke = de.length; j < Ke; ++j)
578
- N[j] = de[j];
579
- function Je(n) {
580
- return N[n >> 18 & 63] + N[n >> 12 & 63] + N[n >> 6 & 63] + N[n & 63];
572
+ var Ke = je, I = [], le = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
573
+ for (var q = 0, Je = le.length; q < Je; ++q)
574
+ I[q] = le[q];
575
+ function Be(n) {
576
+ return I[n >> 18 & 63] + I[n >> 12 & 63] + I[n >> 6 & 63] + I[n & 63];
581
577
  }
582
- function Be(n, e, s) {
578
+ function qe(n, e, s) {
583
579
  for (var t, o = [], i = e; i < s; i += 3)
584
- t = (n[i] << 16 & 16711680) + (n[i + 1] << 8 & 65280) + (n[i + 2] & 255), o.push(Je(t));
580
+ t = (n[i] << 16 & 16711680) + (n[i + 1] << 8 & 65280) + (n[i + 2] & 255), o.push(Be(t));
585
581
  return o.join("");
586
582
  }
587
583
  function je(n) {
588
- for (var e, s = n.length, t = s % 3, o = [], i = 16383, r = 0, l = s - t; r < l; r += i)
589
- o.push(Be(n, r, r + i > l ? l : r + i));
584
+ for (var e, s = n.length, t = s % 3, o = [], i = 16383, r = 0, c = s - t; r < c; r += i)
585
+ o.push(qe(n, r, r + i > c ? c : r + i));
590
586
  return t === 1 ? (e = n[s - 1], o.push(
591
- N[e >> 2] + N[e << 4 & 63] + "=="
587
+ I[e >> 2] + I[e << 4 & 63] + "=="
592
588
  )) : t === 2 && (e = (n[s - 2] << 8) + n[s - 1], o.push(
593
- N[e >> 10] + N[e >> 4 & 63] + N[e << 2 & 63] + "="
589
+ I[e >> 10] + I[e >> 4 & 63] + I[e << 2 & 63] + "="
594
590
  )), o.join("");
595
591
  }
596
- const Ae = () => {
592
+ const pe = () => {
597
593
  const n = typeof window < "u" && !!window.crypto, e = n && !!window.crypto.subtle;
598
594
  return { hasCrypto: n, hasSubtleCrypto: e };
599
- }, Z = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", qe = (n) => {
595
+ }, Q = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", He = (n) => {
600
596
  const e = [];
601
597
  for (let s = 0; s < n.byteLength; s += 1) {
602
- const t = n[s] % Z.length;
603
- e.push(Z[t]);
598
+ const t = n[s] % Q.length;
599
+ e.push(Q[t]);
604
600
  }
605
601
  return e.join("");
606
- }, Ge = (n) => Me(new Uint8Array(n)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, ""), ee = (n) => {
607
- const e = new Uint8Array(n), { hasCrypto: s } = Ae();
602
+ }, Ge = (n) => Ke(new Uint8Array(n)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, ""), Z = (n) => {
603
+ const e = new Uint8Array(n), { hasCrypto: s } = pe();
608
604
  if (s)
609
605
  window.crypto.getRandomValues(e);
610
606
  else
611
607
  for (let t = 0; t < n; t += 1)
612
- e[t] = Math.random() * Z.length | 0;
613
- return qe(e);
608
+ e[t] = Math.random() * Q.length | 0;
609
+ return He(e);
614
610
  };
615
- function He(n) {
611
+ function Xe(n) {
616
612
  const e = new ArrayBuffer(n.length), s = new Uint8Array(e);
617
613
  for (let t = 0; t < n.length; t++)
618
614
  s[t] = n.charCodeAt(t);
619
615
  return s;
620
616
  }
621
- function ve(n) {
617
+ function we(n) {
622
618
  return new Promise((e, s) => {
623
- crypto.subtle.digest("SHA-256", He(n)).then((t) => e(Ge(new Uint8Array(t))), (t) => s(t));
619
+ crypto.subtle.digest("SHA-256", Xe(n)).then((t) => e(Ge(new Uint8Array(t))), (t) => s(t));
624
620
  });
625
621
  }
626
- const Xe = (n) => {
622
+ const Ye = (n) => {
627
623
  if (n.length < 43 || n.length > 128)
628
624
  return Promise.reject(new Error("Invalid code length."));
629
- const { hasSubtleCrypto: e } = Ae();
630
- return e ? ve(n) : Promise.reject(new Error("window.crypto.subtle is unavailable."));
631
- }, F = {}, Ye = (n, e = window.sessionStorage, s) => {
632
- if (!F[n] && e) {
625
+ const { hasSubtleCrypto: e } = pe();
626
+ return e ? we(n) : Promise.reject(new Error("window.crypto.subtle is unavailable."));
627
+ }, V = {}, ze = (n, e = window.sessionStorage, s) => {
628
+ if (!V[n] && e) {
633
629
  const o = e.getItem(n);
634
- o && (F[n] = JSON.parse(o));
630
+ o && (V[n] = JSON.parse(o));
635
631
  }
636
632
  const t = 1e3 * s;
637
- return F[n] && F[n].timestamp + t > Date.now() ? F[n].result : null;
638
- }, ze = (n, e, s = window.sessionStorage) => {
633
+ return V[n] && V[n].timestamp + t > Date.now() ? V[n].result : null;
634
+ }, Qe = (n, e, s = window.sessionStorage) => {
639
635
  const t = Date.now();
640
- F[n] = { result: e, timestamp: t }, s && s.setItem(n, JSON.stringify({ result: e, timestamp: t }));
641
- }, Qe = 60 * 60, Ze = (n) => async (e, s = Qe, t = window.sessionStorage, o = 1e4) => {
642
- const i = `${e}/.well-known/openid-configuration`, r = `oidc.server:${e}`, l = Ye(r, t, s);
643
- if (l)
644
- return new se(l);
645
- const a = await J(n)(i, {}, o);
636
+ V[n] = { result: e, timestamp: t }, s && s.setItem(n, JSON.stringify({ result: e, timestamp: t }));
637
+ }, Ze = 60 * 60, en = (n) => async (e, s = Ze, t = window.sessionStorage, o = 1e4) => {
638
+ const i = `${e}/.well-known/openid-configuration`, r = `oidc.server:${e}`, c = ze(r, t, s);
639
+ if (c)
640
+ return new ne(c);
641
+ const a = await B(n)(i, {}, o);
646
642
  if (a.status !== 200)
647
643
  return null;
648
- const f = await a.json();
649
- return ze(r, f, t), new se(f);
650
- }, J = (n) => async (e, s = {}, t = 1e4, o = 0) => {
644
+ const y = await a.json();
645
+ return Qe(r, y, t), new ne(y);
646
+ }, B = (n) => async (e, s = {}, t = 1e4, o = 0) => {
651
647
  let i;
652
648
  try {
653
649
  const r = new AbortController();
@@ -655,27 +651,27 @@ const Xe = (n) => {
655
651
  } catch (r) {
656
652
  if (r.name === "AbortError" || r.message === "Network request failed") {
657
653
  if (o <= 1)
658
- return await J(n)(e, s, t, o + 1);
654
+ return await B(n)(e, s, t, o + 1);
659
655
  throw r;
660
656
  } else
661
657
  throw console.error(r.message), r;
662
658
  }
663
659
  return i;
664
- }, ne = {
660
+ }, ee = {
665
661
  refresh_token: "refresh_token",
666
662
  access_token: "access_token"
667
- }, fe = (n) => async (e, s, t = ne.refresh_token, o, i = 1e4) => {
663
+ }, ue = (n) => async (e, s, t = ee.refresh_token, o, i = 1e4) => {
668
664
  const r = {
669
665
  token: s,
670
666
  token_type_hint: t,
671
667
  client_id: o
672
- }, l = [];
673
- for (const c in r) {
674
- const _ = encodeURIComponent(c), h = encodeURIComponent(r[c]);
675
- l.push(`${_}=${h}`);
668
+ }, c = [];
669
+ for (const l in r) {
670
+ const u = encodeURIComponent(l), f = encodeURIComponent(r[l]);
671
+ c.push(`${u}=${f}`);
676
672
  }
677
- const a = l.join("&");
678
- return (await J(n)(e, {
673
+ const a = c.join("&");
674
+ return (await B(n)(e, {
679
675
  method: "POST",
680
676
  headers: {
681
677
  "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
@@ -684,69 +680,69 @@ const Xe = (n) => {
684
680
  }, i)).status !== 200 ? { success: !1 } : {
685
681
  success: !0
686
682
  };
687
- }, en = (n) => async (e, s, t, o, i = {}, r, l = 1e4) => {
688
- for (const [u, y] of Object.entries(t))
689
- s[u] === void 0 && (s[u] = y);
683
+ }, nn = (n) => async (e, s, t, o, i = {}, r, c = 1e4) => {
684
+ for (const [d, _] of Object.entries(t))
685
+ s[d] === void 0 && (s[d] = _);
690
686
  const a = [];
691
- for (const u in s) {
692
- const y = encodeURIComponent(u), d = encodeURIComponent(s[u]);
693
- a.push(`${y}=${d}`);
687
+ for (const d in s) {
688
+ const _ = encodeURIComponent(d), h = encodeURIComponent(s[d]);
689
+ a.push(`${_}=${h}`);
694
690
  }
695
- const f = a.join("&"), c = await J(n)(e, {
691
+ const y = a.join("&"), l = await B(n)(e, {
696
692
  method: "POST",
697
693
  headers: {
698
694
  "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
699
695
  ...i
700
696
  },
701
- body: f
702
- }, l);
703
- if (c.status !== 200)
704
- return { success: !1, status: c.status, demonstratingProofOfPossessionNonce: null };
705
- const _ = await c.json();
706
- let h = null;
707
- return c.headers.has(G) && (h = c.headers.get(G)), {
697
+ body: y
698
+ }, c);
699
+ if (l.status !== 200)
700
+ return { success: !1, status: l.status, demonstratingProofOfPossessionNonce: null };
701
+ const u = await l.json();
702
+ let f = null;
703
+ return l.headers.has(H) && (f = l.headers.get(H)), {
708
704
  success: !0,
709
- data: te(_, o, r),
710
- demonstratingProofOfPossessionNonce: h
705
+ data: se(u, o, r),
706
+ demonstratingProofOfPossessionNonce: f
711
707
  };
712
- }, nn = (n, e) => async (s, t) => {
708
+ }, sn = (n, e) => async (s, t) => {
713
709
  t = t ? { ...t } : {};
714
- const o = ee(128), i = await Xe(o);
710
+ const o = Z(128), i = await Ye(o);
715
711
  await n.setCodeVerifierAsync(o), await n.setStateAsync(t.state), t.code_challenge = i, t.code_challenge_method = "S256";
716
712
  let r = "";
717
713
  if (t)
718
- for (const [l, a] of Object.entries(t))
719
- r === "" ? r += "?" : r += "&", r += `${l}=${encodeURIComponent(a)}`;
714
+ for (const [c, a] of Object.entries(t))
715
+ r === "" ? r += "?" : r += "&", r += `${c}=${encodeURIComponent(a)}`;
720
716
  e.open(`${s}${r}`);
721
- }, G = "DPoP-Nonce", sn = (n) => async (e, s, t, o, i = 1e4) => {
717
+ }, H = "DPoP-Nonce", tn = (n) => async (e, s, t, o, i = 1e4) => {
722
718
  s = s ? { ...s } : {}, s.code_verifier = await n.getCodeVerifierAsync();
723
719
  const r = [];
724
- for (const _ in s) {
725
- const h = encodeURIComponent(_), u = encodeURIComponent(s[_]);
726
- r.push(`${h}=${u}`);
720
+ for (const u in s) {
721
+ const f = encodeURIComponent(u), d = encodeURIComponent(s[u]);
722
+ r.push(`${f}=${d}`);
727
723
  }
728
- const l = r.join("&"), a = await J(fetch)(e, {
724
+ const c = r.join("&"), a = await B(fetch)(e, {
729
725
  method: "POST",
730
726
  headers: {
731
727
  "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
732
728
  ...t
733
729
  },
734
- body: l
730
+ body: c
735
731
  }, i);
736
732
  if (await Promise.all([n.setCodeVerifierAsync(null), n.setStateAsync(null)]), a.status !== 200)
737
733
  return { success: !1, status: a.status };
738
- let f = null;
739
- a.headers.has(G) && (f = a.headers.get(G));
740
- const c = await a.json();
734
+ let y = null;
735
+ a.headers.has(H) && (y = a.headers.get(H));
736
+ const l = await a.json();
741
737
  return {
742
738
  success: !0,
743
739
  data: {
744
740
  state: s.state,
745
- tokens: te(c, null, o),
746
- demonstratingProofOfPossessionNonce: f
741
+ tokens: se(l, null, o),
742
+ demonstratingProofOfPossessionNonce: y
747
743
  }
748
744
  };
749
- }, Se = (n) => {
745
+ }, Ae = (n) => {
750
746
  const e = n.match(
751
747
  // eslint-disable-next-line no-useless-escape
752
748
  /^([a-z][\w-]+\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/
@@ -768,16 +764,16 @@ const Xe = (n) => {
768
764
  search: s,
769
765
  hash: t
770
766
  };
771
- }, mn = (n) => {
772
- const e = Se(n);
767
+ }, pn = (n) => {
768
+ const e = Ae(n);
773
769
  let { path: s } = e;
774
770
  s.endsWith("/") && (s = s.slice(0, -1));
775
771
  let { hash: t } = e;
776
772
  return t === "#_=_" && (t = ""), t && (s += t), s;
777
- }, H = (n) => {
778
- const e = Se(n), { search: s } = e;
779
- return tn(s);
780
- }, tn = (n) => {
773
+ }, G = (n) => {
774
+ const e = Ae(n), { search: s } = e;
775
+ return on(s);
776
+ }, on = (n) => {
781
777
  const e = {};
782
778
  let s, t, o;
783
779
  const i = n.split("&");
@@ -785,50 +781,50 @@ const Xe = (n) => {
785
781
  s = i[t].split("="), e[decodeURIComponent(s[0])] = decodeURIComponent(s[1]);
786
782
  return e;
787
783
  };
788
- function Te(n) {
784
+ function ve(n) {
789
785
  return new TextEncoder().encode(n);
790
786
  }
791
- function be(n) {
787
+ function Se(n) {
792
788
  return btoa(n).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+/g, "");
793
789
  }
794
- function on(n) {
790
+ function rn(n) {
795
791
  return encodeURIComponent(n).replace(/%([0-9A-F]{2})/g, function(t, o) {
796
792
  return String.fromCharCode(parseInt(o, 16));
797
793
  });
798
794
  }
799
- function Pe(n) {
795
+ function Te(n) {
800
796
  let e = "";
801
797
  return n.forEach(function(s) {
802
798
  e += String.fromCharCode(s);
803
- }), be(e);
799
+ }), Se(e);
804
800
  }
805
- function he(n) {
806
- return be(on(n));
801
+ function de(n) {
802
+ return Se(rn(n));
807
803
  }
808
- var Oe = {};
809
- Oe.sign = (n, e, s, t = "dpop+jwt") => {
804
+ var be = {};
805
+ be.sign = (n, e, s, t = "dpop+jwt") => {
810
806
  n = Object.assign({}, n), e.typ = t, e.alg = "ES256", e.kid || (e.jwk = { kty: n.kty, crv: n.crv, x: n.x, y: n.y });
811
807
  const o = {
812
808
  // @ts-ignore
813
809
  // JWT "headers" really means JWS "protected headers"
814
- protected: he(JSON.stringify(e)),
810
+ protected: de(JSON.stringify(e)),
815
811
  // @ts-ignore
816
812
  // JWT "claims" are really a JSON-defined JWS "payload"
817
- payload: he(JSON.stringify(s))
813
+ payload: de(JSON.stringify(s))
818
814
  }, i = {
819
815
  name: "ECDSA",
820
816
  namedCurve: "P-256",
821
817
  hash: { name: "ES256" }
822
- }, r = !0, l = ["sign"];
823
- return window.crypto.subtle.importKey("jwk", n, i, r, l).then(function(a) {
824
- const f = Te(o.protected + "." + o.payload), c = { name: "ECDSA", hash: { name: "SHA-256" } };
825
- return window.crypto.subtle.sign(c, a, f).then(function(_) {
826
- return o.signature = Pe(new Uint8Array(_)), o.protected + "." + o.payload + "." + o.signature;
818
+ }, r = !0, c = ["sign"];
819
+ return window.crypto.subtle.importKey("jwk", n, i, r, c).then(function(a) {
820
+ const y = ve(o.protected + "." + o.payload), l = { name: "ECDSA", hash: { name: "SHA-256" } };
821
+ return window.crypto.subtle.sign(l, a, y).then(function(u) {
822
+ return o.signature = Te(new Uint8Array(u)), o.protected + "." + o.payload + "." + o.signature;
827
823
  });
828
824
  });
829
825
  };
830
- const ie = {};
831
- ie.generate = function() {
826
+ const oe = {};
827
+ oe.generate = function() {
832
828
  const n = {
833
829
  name: "ECDSA",
834
830
  namedCurve: "P-256"
@@ -837,203 +833,203 @@ ie.generate = function() {
837
833
  return window.crypto.subtle.exportKey("jwk", t.privateKey);
838
834
  });
839
835
  };
840
- ie.neuter = function(n) {
836
+ oe.neuter = function(n) {
841
837
  const e = Object.assign({}, n);
842
838
  return delete e.d, e.key_ops = ["verify"], e;
843
839
  };
844
- var Ee = {};
845
- Ee.thumbprint = function(n) {
840
+ var Pe = {};
841
+ Pe.thumbprint = function(n) {
846
842
  const e = '{"crv":"CRV","kty":"EC","x":"X","y":"Y"}'.replace("CRV", n.crv).replace("X", n.x).replace("Y", n.y);
847
- return window.crypto.subtle.digest({ name: "SHA-256" }, Te(e)).then(function(s) {
848
- return Pe(new Uint8Array(s));
843
+ return window.crypto.subtle.digest({ name: "SHA-256" }, ve(e)).then(function(s) {
844
+ return Te(new Uint8Array(s));
849
845
  });
850
846
  };
851
- const rn = function() {
847
+ const an = function() {
852
848
  const n = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx", e = "0123456789abcdef";
853
849
  let s = 0, t = "";
854
850
  for (let o = 0; o < 36; o++)
855
851
  n[o] !== "-" && n[o] !== "4" && (s = Math.random() * 16 | 0), n[o] === "x" ? t += e[s] : n[o] === "y" ? (s &= 3, s |= 8, t += e[s]) : t += n[o];
856
852
  return t;
857
- }, an = () => ie.generate().then(function(n) {
853
+ }, cn = () => oe.generate().then(function(n) {
858
854
  return n;
859
- }), Ie = (n, e = "POST", s, t = {}) => {
855
+ }), Oe = (n, e = "POST", s, t = {}) => {
860
856
  const o = {
861
857
  // https://www.rfc-editor.org/rfc/rfc9449.html#name-concept
862
- jit: btoa(rn()),
858
+ jit: btoa(an()),
863
859
  htm: e,
864
860
  htu: s,
865
861
  iat: Math.round(Date.now() / 1e3),
866
862
  ...t
867
863
  };
868
- return Ee.thumbprint(n).then(function(i) {
869
- return Oe.sign(n, {
864
+ return Pe.thumbprint(n).then(function(i) {
865
+ return be.sign(n, {
870
866
  /*kid: kid*/
871
867
  }, o).then(function(r) {
872
868
  return r;
873
869
  });
874
870
  });
875
- }, cn = (n, e, s, t, o, i) => (r = void 0, l = null, a = !1, f = void 0) => {
876
- const c = l;
877
- return l = { ...l }, (async () => {
878
- const h = n.location, u = r || h.pathname + (h.search || "") + (h.hash || "");
879
- if ("state" in l || (l.state = ee(16)), t(k.loginAsync_begin, {}), l)
880
- for (const y of Object.keys(l))
881
- y.endsWith(":token_request") && delete l[y];
871
+ }, ln = (n, e, s, t, o) => (i = void 0, r = null, c = !1, a = void 0) => {
872
+ const y = r;
873
+ return r = { ...r }, (async () => {
874
+ const u = i || o.getPath();
875
+ if ("state" in r || (r.state = Z(16)), s(m.loginAsync_begin, {}), r)
876
+ for (const f of Object.keys(r))
877
+ f.endsWith(":token_request") && delete r[f];
882
878
  try {
883
- const y = a ? s.silent_redirect_uri : s.redirect_uri;
884
- f || (f = s.scope);
885
- const d = s.extras ? { ...s.extras, ...l } : l;
886
- d.nonce || (d.nonce = ee(12));
887
- const g = { nonce: d.nonce }, w = await x(s.service_worker_relative_url, e), T = await o(s.authority, s.authority_configuration);
888
- let v;
889
- if (w)
890
- w.setLoginParams({ callbackPath: u, extras: c }), await w.initAsync(T, "loginAsync", s), await w.setNonceAsync(g), w.startKeepAliveServiceWorker(), v = w;
879
+ const f = c ? e.silent_redirect_uri : e.redirect_uri;
880
+ a || (a = e.scope);
881
+ const d = e.extras ? { ...e.extras, ...r } : r;
882
+ d.nonce || (d.nonce = Z(12));
883
+ const _ = { nonce: d.nonce }, h = await E(e.service_worker_relative_url, n), g = await t(e.authority, e.authority_configuration);
884
+ let A;
885
+ if (h)
886
+ h.setLoginParams({ callbackPath: u, extras: y }), await h.initAsync(g, "loginAsync", e), await h.setNonceAsync(_), h.startKeepAliveServiceWorker(), A = h;
891
887
  else {
892
- const p = E(e, s.storage ?? sessionStorage);
893
- p.setLoginParams({ callbackPath: u, extras: c }), await p.setNonceAsync(g), v = p;
888
+ const T = O(n, e.storage ?? sessionStorage);
889
+ T.setLoginParams({ callbackPath: u, extras: y }), await T.setNonceAsync(_), A = T;
894
890
  }
895
- const I = {
896
- client_id: s.client_id,
897
- redirect_uri: y,
898
- scope: f,
891
+ const v = {
892
+ client_id: e.client_id,
893
+ redirect_uri: f,
894
+ scope: a,
899
895
  response_type: "code",
900
896
  ...d
901
897
  };
902
- await nn(v, i)(T.authorizationEndpoint, I);
903
- } catch (y) {
904
- throw t(k.loginAsync_error, y), y;
898
+ await sn(A, o)(g.authorizationEndpoint, v);
899
+ } catch (f) {
900
+ throw s(m.loginAsync_error, f), f;
905
901
  }
906
902
  })();
907
- }, ln = (n) => async (e = !1) => {
903
+ }, un = (n) => async (e = !1) => {
908
904
  try {
909
- n.publishEvent(k.loginCallbackAsync_begin, {});
910
- const s = n.configuration, t = s.client_id, o = e ? s.silent_redirect_uri : s.redirect_uri, i = s.authority, r = s.token_request_timeout, l = await n.initAsync(i, s.authority_configuration), f = H(window.location.href).session_state, c = await x(s.service_worker_relative_url, n.configurationName);
911
- let _, h, u, y;
912
- if (c)
913
- await c.initAsync(l, "loginCallbackAsync", s), await c.setSessionStateAsync(f), h = await c.getNonceAsync(), u = c.getLoginParams(), y = await c.getStateAsync(), c.startKeepAliveServiceWorker(), _ = c;
905
+ n.publishEvent(m.loginCallbackAsync_begin, {});
906
+ const s = n.configuration, t = s.client_id, o = e ? s.silent_redirect_uri : s.redirect_uri, i = s.authority, r = s.token_request_timeout, c = await n.initAsync(i, s.authority_configuration), a = n.location.getCurrentHref(), l = G(a).session_state, u = await E(s.service_worker_relative_url, n.configurationName);
907
+ let f, d, _, h;
908
+ if (u)
909
+ await u.initAsync(c, "loginCallbackAsync", s), await u.setSessionStateAsync(l), d = await u.getNonceAsync(), _ = u.getLoginParams(), h = await u.getStateAsync(), u.startKeepAliveServiceWorker(), f = u;
914
910
  else {
915
- const A = E(n.configurationName, s.storage ?? sessionStorage);
916
- await A.setSessionStateAsync(f), h = await A.getNonceAsync(), u = A.getLoginParams(), y = await A.getStateAsync(), _ = A;
911
+ const p = O(n.configurationName, s.storage ?? sessionStorage);
912
+ await p.setSessionStateAsync(l), d = await p.getNonceAsync(), _ = p.getLoginParams(), h = await p.getStateAsync(), f = p;
917
913
  }
918
- const d = H(window.location.toString());
919
- if (d.iss && d.iss !== l.issuer)
920
- throw console.error(), new Error(`issuer not valid (expected: ${l.issuer}, received: ${d.iss})`);
921
- if (d.state && d.state !== y)
922
- throw new Error(`state not valid (expected: ${y}, received: ${d.state})`);
923
- const g = {
924
- code: d.code,
914
+ const g = G(a);
915
+ if (g.iss && g.iss !== c.issuer)
916
+ throw console.error(), new Error(`issuer not valid (expected: ${c.issuer}, received: ${g.iss})`);
917
+ if (g.state && g.state !== h)
918
+ throw new Error(`state not valid (expected: ${h}, received: ${g.state})`);
919
+ const A = {
920
+ code: g.code,
925
921
  grant_type: "authorization_code",
926
922
  client_id: s.client_id,
927
923
  redirect_uri: o
928
- }, w = {};
924
+ }, v = {};
929
925
  if (s.token_request_extras)
930
- for (const [A, b] of Object.entries(s.token_request_extras))
931
- w[A] = b;
932
- if (u && u.extras)
933
- for (const [A, b] of Object.entries(u.extras))
934
- A.endsWith(":token_request") && (w[A.replace(":token_request", "")] = b);
935
- const T = l.tokenEndpoint, v = {};
926
+ for (const [p, N] of Object.entries(s.token_request_extras))
927
+ v[p] = N;
928
+ if (_ && _.extras)
929
+ for (const [p, N] of Object.entries(_.extras))
930
+ p.endsWith(":token_request") && (v[p.replace(":token_request", "")] = N);
931
+ const T = c.tokenEndpoint, D = {};
936
932
  if (s.demonstrating_proof_of_possession) {
937
- const A = await an();
938
- c ? await c.setDemonstratingProofOfPossessionJwkAsync(A) : await E(n.configurationName, s.storage).setDemonstratingProofOfPossessionJwkAsync(A), v.DPoP = await Ie(A, "POST", T);
933
+ const p = await cn();
934
+ u ? await u.setDemonstratingProofOfPossessionJwkAsync(p) : await O(n.configurationName, s.storage).setDemonstratingProofOfPossessionJwkAsync(p), D.DPoP = await Oe(p, "POST", T);
939
935
  }
940
- const I = await sn(_)(
936
+ const w = await tn(f)(
941
937
  T,
942
- { ...g, ...w },
943
- v,
938
+ { ...A, ...v },
939
+ D,
944
940
  n.configuration.token_renew_mode,
945
941
  r
946
942
  );
947
- if (!I.success)
943
+ if (!w.success)
948
944
  throw new Error("Token request failed");
949
- let p;
950
- const O = I.data.tokens, C = I.data.demonstratingProofOfPossessionNonce;
951
- if (I.data.state !== w.state)
945
+ let C;
946
+ const P = w.data.tokens, k = w.data.demonstratingProofOfPossessionNonce;
947
+ if (w.data.state !== v.state)
952
948
  throw new Error("state is not valid");
953
- const { isValid: m, reason: S } = ke(O, h.nonce, l);
954
- if (!m)
955
- throw new Error(`Tokens are not OpenID valid, reason: ${S}`);
956
- if (c) {
957
- if (O.refreshToken && !O.refreshToken.includes("SECURED_BY_OIDC_SERVICE_WORKER"))
949
+ const { isValid: S, reason: x } = ye(P, d.nonce, c);
950
+ if (!S)
951
+ throw new Error(`Tokens are not OpenID valid, reason: ${x}`);
952
+ if (u) {
953
+ if (P.refreshToken && !P.refreshToken.includes("SECURED_BY_OIDC_SERVICE_WORKER"))
958
954
  throw new Error("Refresh token should be hidden by service worker");
959
- if (C && O.accessToken && O.accessToken.includes("SECURED_BY_OIDC_SERVICE_WORKER"))
955
+ if (k && P.accessToken && P.accessToken.includes("SECURED_BY_OIDC_SERVICE_WORKER"))
960
956
  throw new Error("Demonstration of proof of possession require Access token not hidden by service worker");
961
957
  }
962
- if (c)
963
- await c.initAsync(o, "syncTokensAsync", s), p = c.getLoginParams(), C && await c.setDemonstratingProofOfPossessionNonce(C);
958
+ if (u)
959
+ await u.initAsync(o, "syncTokensAsync", s), C = u.getLoginParams(), k && await u.setDemonstratingProofOfPossessionNonce(k);
964
960
  else {
965
- const A = E(n.configurationName, s.storage);
966
- p = A.getLoginParams(), C && await A.setDemonstratingProofOfPossessionNonce(C);
961
+ const p = O(n.configurationName, s.storage);
962
+ C = p.getLoginParams(), k && await p.setDemonstratingProofOfPossessionNonce(k);
967
963
  }
968
- return await n.startCheckSessionAsync(l.checkSessionIframe, t, f, e), n.publishEvent(k.loginCallbackAsync_end, {}), {
969
- tokens: O,
964
+ return await n.startCheckSessionAsync(c.checkSessionIframe, t, l, e), n.publishEvent(m.loginCallbackAsync_end, {}), {
965
+ tokens: P,
970
966
  state: "request.state",
971
- callbackPath: p.callbackPath
967
+ callbackPath: C.callbackPath
972
968
  };
973
969
  } catch (s) {
974
- throw console.error(s), n.publishEvent(k.loginCallbackAsync_error, s), s;
970
+ throw console.error(s), n.publishEvent(m.loginCallbackAsync_error, s), s;
975
971
  }
976
- }, _e = {
972
+ }, fe = {
977
973
  access_token: "access_token",
978
974
  refresh_token: "refresh_token"
979
- }, un = (n) => async (e) => {
980
- K.clearTimeout(n.timeoutId), n.timeoutId = null, n.checkSessionIFrame && n.checkSessionIFrame.stop();
981
- const s = await x(n.configuration.service_worker_relative_url, n.configurationName);
982
- s ? await s.clearAsync(e) : await E(n.configurationName, n.configuration.storage).clearAsync(e), n.tokens = null, n.userInfo = null;
983
- }, dn = (n, e, s, t, o, i) => async (r = void 0, l = null) => {
984
- const a = n.configuration, f = await n.initAsync(a.authority, a.authority_configuration);
985
- r && typeof r != "string" && (r = void 0, o.warn("callbackPathOrUrl path is not a string"));
986
- const c = r ?? location.pathname + (location.search || "") + (location.hash || "");
987
- let _ = !1;
988
- r && (_ = r.includes("https://") || r.includes("http://"));
989
- const h = _ ? r : t.location.origin + c, u = n.tokens ? n.tokens.idToken : "";
975
+ }, dn = (n) => async (e) => {
976
+ J.clearTimeout(n.timeoutId), n.timeoutId = null, n.checkSessionIFrame && n.checkSessionIFrame.stop();
977
+ const s = await E(n.configuration.service_worker_relative_url, n.configurationName);
978
+ s ? await s.clearAsync(e) : await O(n.configurationName, n.configuration.storage).clearAsync(e), n.tokens = null, n.userInfo = null;
979
+ }, fn = (n, e, s, t, o) => async (i = void 0, r = null) => {
980
+ const c = n.configuration, a = await n.initAsync(c.authority, c.authority_configuration);
981
+ i && typeof i != "string" && (i = void 0, t.warn("callbackPathOrUrl path is not a string"));
982
+ const y = i ?? o.getPath();
983
+ let l = !1;
984
+ i && (l = i.includes("https://") || i.includes("http://"));
985
+ const u = l ? i : o.getOrigin() + y, f = n.tokens ? n.tokens.idToken : "";
990
986
  try {
991
- const d = f.revocationEndpoint;
992
- if (d) {
993
- const g = [], w = n.tokens.accessToken;
994
- if (w && a.logout_tokens_to_invalidate.includes(_e.access_token)) {
995
- const v = fe(s)(d, w, ne.access_token, a.client_id);
996
- g.push(v);
987
+ const _ = a.revocationEndpoint;
988
+ if (_) {
989
+ const h = [], g = n.tokens.accessToken;
990
+ if (g && c.logout_tokens_to_invalidate.includes(fe.access_token)) {
991
+ const v = ue(s)(_, g, ee.access_token, c.client_id);
992
+ h.push(v);
997
993
  }
998
- const T = n.tokens.refreshToken;
999
- if (T && a.logout_tokens_to_invalidate.includes(_e.refresh_token)) {
1000
- const v = fe(s)(d, T, ne.refresh_token, a.client_id);
1001
- g.push(v);
994
+ const A = n.tokens.refreshToken;
995
+ if (A && c.logout_tokens_to_invalidate.includes(fe.refresh_token)) {
996
+ const v = ue(s)(_, A, ee.refresh_token, c.client_id);
997
+ h.push(v);
1002
998
  }
1003
- g.length > 0 && await Promise.all(g);
999
+ h.length > 0 && await Promise.all(h);
1004
1000
  }
1005
- } catch (d) {
1006
- o.warn("logoutAsync: error when revoking tokens, if the error persist, you ay configure property logout_tokens_to_invalidate from configuration to avoid this error"), o.warn(d);
1001
+ } catch (_) {
1002
+ t.warn("logoutAsync: error when revoking tokens, if the error persist, you ay configure property logout_tokens_to_invalidate from configuration to avoid this error"), t.warn(_);
1007
1003
  }
1008
- const y = n.tokens && n.tokens.idTokenPayload ? n.tokens.idTokenPayload.sub : null;
1004
+ const d = n.tokens && n.tokens.idTokenPayload ? n.tokens.idTokenPayload.sub : null;
1009
1005
  await n.destroyAsync("LOGGED_OUT");
1010
- for (const [d, g] of Object.entries(e))
1011
- g !== n && await n.logoutSameTabAsync(n.configuration.client_id, y);
1012
- if (f.endSessionEndpoint) {
1013
- l || (l = {
1014
- id_token_hint: u
1015
- }, r !== null && (l.post_logout_redirect_uri = h));
1016
- let d = "";
1017
- if (l)
1018
- for (const [g, w] of Object.entries(l))
1019
- d === "" ? d += "?" : d += "&", d += `${g}=${encodeURIComponent(w)}`;
1020
- i.open(`${f.endSessionEndpoint}${d}`);
1006
+ for (const [_, h] of Object.entries(e))
1007
+ h !== n && await n.logoutSameTabAsync(n.configuration.client_id, d);
1008
+ if (a.endSessionEndpoint) {
1009
+ r || (r = {
1010
+ id_token_hint: f
1011
+ }, i !== null && (r.post_logout_redirect_uri = u));
1012
+ let _ = "";
1013
+ if (r)
1014
+ for (const [h, g] of Object.entries(r))
1015
+ _ === "" ? _ += "?" : _ += "&", _ += `${h}=${encodeURIComponent(g)}`;
1016
+ o.open(`${a.endSessionEndpoint}${_}`);
1021
1017
  } else
1022
- t.location.reload();
1023
- }, fn = (n) => async (e = !1) => {
1018
+ o.reload();
1019
+ }, hn = (n) => async (e = !1) => {
1024
1020
  if (n.userInfo != null && !e)
1025
1021
  return n.userInfo;
1026
- for (; n.tokens && !Q(n.tokens); )
1027
- await D(200);
1022
+ for (; n.tokens && !z(n.tokens); )
1023
+ await $(200);
1028
1024
  if (!n.tokens)
1029
1025
  return null;
1030
1026
  const s = n.tokens.accessToken;
1031
1027
  if (!s)
1032
1028
  return null;
1033
- const o = (await n.initAsync(n.configuration.authority, n.configuration.authority_configuration)).userInfoEndpoint, r = await (async (l) => {
1029
+ const o = (await n.initAsync(n.configuration.authority, n.configuration.authority_configuration)).userInfoEndpoint, r = await (async (c) => {
1034
1030
  const a = await fetch(o, {
1035
1031
  headers: {
1036
- authorization: `Bearer ${l}`
1032
+ authorization: `Bearer ${c}`
1037
1033
  }
1038
1034
  });
1039
1035
  return a.status !== 200 ? null : a.json();
@@ -1044,36 +1040,52 @@ class X {
1044
1040
  open(e) {
1045
1041
  window.open(e, "_self");
1046
1042
  }
1043
+ reload() {
1044
+ window.location.reload();
1045
+ }
1046
+ getCurrentHref() {
1047
+ return window.location.href;
1048
+ }
1049
+ getPath() {
1050
+ const e = window.location;
1051
+ return e.pathname + (e.search || "") + (e.hash || "");
1052
+ }
1053
+ getOrigin() {
1054
+ return window.origin;
1055
+ }
1047
1056
  }
1048
- const hn = () => fetch;
1049
- class se {
1057
+ const _n = () => fetch;
1058
+ class ne {
1050
1059
  constructor(e) {
1051
1060
  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;
1052
1061
  }
1053
1062
  }
1054
- const W = {}, _n = (n, e = new X()) => (s, t = "default") => (W[t] || (W[t] = new $(s, t, n, e)), W[t]), yn = async (n) => {
1063
+ const W = {}, yn = (n, e = new X()) => (s, t = "default") => (W[t] || (W[t] = new R(s, t, n, e)), W[t]), gn = async (n) => {
1055
1064
  const { parsedTokens: e, callbackPath: s } = await n.loginCallbackAsync();
1056
- return n.timeoutId = M(n, e.refreshToken, e.expiresAt), { callbackPath: s };
1057
- }, gn = (n) => Math.floor(Math.random() * n), L = class L {
1065
+ return n.timeoutId = K(n, e.refreshToken, e.expiresAt), { callbackPath: s };
1066
+ }, kn = (n) => Math.floor(Math.random() * n), L = class L {
1058
1067
  constructor(e, s = "default", t, o = new X()) {
1059
1068
  this.initPromise = null, this.tryKeepExistingSessionPromise = null, this.loginPromise = null, this.loginCallbackPromise = null, this.loginCallbackWithAutoTokensRenewPromise = null, this.userInfoPromise = null, this.renewTokensPromise = null, this.logoutPromise = null;
1060
1069
  let i = e.silent_login_uri;
1061
1070
  e.silent_redirect_uri && !e.silent_login_uri && (i = `${e.silent_redirect_uri.replace("-callback", "").replace("callback", "")}-login`);
1062
1071
  let r = e.refresh_time_before_tokens_expiration_in_second ?? 120;
1063
- r > 60 && (r = r - Math.floor(Math.random() * 40)), this.configuration = {
1072
+ r > 60 && (r = r - Math.floor(Math.random() * 40)), this.location = o ?? new X();
1073
+ const c = e.service_worker_update_require_callback ?? Fe(this.location);
1074
+ this.configuration = {
1064
1075
  ...e,
1065
1076
  silent_login_uri: i,
1066
1077
  monitor_session: e.monitor_session ?? !1,
1067
1078
  refresh_time_before_tokens_expiration_in_second: r,
1068
1079
  silent_login_timeout: e.silent_login_timeout ?? 12e3,
1069
- token_renew_mode: e.token_renew_mode ?? z.access_token_or_id_token_invalid,
1080
+ token_renew_mode: e.token_renew_mode ?? Y.access_token_or_id_token_invalid,
1070
1081
  demonstrating_proof_of_possession: e.demonstrating_proof_of_possession ?? !1,
1071
1082
  authority_timeout_wellknowurl_in_millisecond: e.authority_timeout_wellknowurl_in_millisecond ?? 1e4,
1072
- logout_tokens_to_invalidate: e.logout_tokens_to_invalidate ?? ["access_token", "refresh_token"]
1073
- }, this.location = o ?? new X(), this.getFetch = t ?? hn, this.configurationName = s, this.tokens = null, this.userInfo = null, this.events = [], this.timeoutId = null, this.synchroniseTokensAsync.bind(this), 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);
1083
+ logout_tokens_to_invalidate: e.logout_tokens_to_invalidate ?? ["access_token", "refresh_token"],
1084
+ service_worker_update_require_callback: c
1085
+ }, this.getFetch = t ?? _n, this.configurationName = s, this.tokens = null, this.userInfo = null, this.events = [], this.timeoutId = null, this.synchroniseTokensAsync.bind(this), 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);
1074
1086
  }
1075
1087
  subscribeEvents(e) {
1076
- const s = gn(9999999999999).toString();
1088
+ const s = kn(9999999999999).toString();
1077
1089
  return this.events.push({ id: s, func: e }), s;
1078
1090
  }
1079
1091
  removeEventSubscription(e) {
@@ -1094,14 +1106,14 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
1094
1106
  }
1095
1107
  _silentLoginCallbackFromIFrame() {
1096
1108
  if (this.configuration.silent_redirect_uri && this.configuration.silent_login_uri) {
1097
- const e = H(window.location.href);
1098
- window.parent.postMessage(`${this.configurationName}_oidc_tokens:${JSON.stringify({ tokens: this.tokens, sessionState: e.session_state })}`, window.location.origin);
1109
+ const e = this.location, s = G(e.getCurrentHref());
1110
+ window.parent.postMessage(`${this.configurationName}_oidc_tokens:${JSON.stringify({ tokens: this.tokens, sessionState: s.session_state })}`, e.getOrigin());
1099
1111
  }
1100
1112
  }
1101
1113
  _silentLoginErrorCallbackFromIFrame() {
1102
1114
  if (this.configuration.silent_redirect_uri && this.configuration.silent_login_uri) {
1103
- const e = H(window.location.href);
1104
- window.parent.postMessage(`${this.configurationName}_oidc_error:${JSON.stringify({ error: e.error })}`, window.location.origin);
1115
+ const e = this.location, s = G(e.getCurrentHref());
1116
+ window.parent.postMessage(`${this.configurationName}_oidc_error:${JSON.stringify({ error: s.error })}`, e.getOrigin());
1105
1117
  }
1106
1118
  }
1107
1119
  async silentLoginCallbackAsync() {
@@ -1116,7 +1128,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
1116
1128
  return this.initPromise;
1117
1129
  const t = async () => {
1118
1130
  if (s != null)
1119
- return new se({
1131
+ return new ne({
1120
1132
  authorization_endpoint: s.authorization_endpoint,
1121
1133
  end_session_endpoint: s.end_session_endpoint,
1122
1134
  revocation_endpoint: s.revocation_endpoint,
@@ -1125,8 +1137,8 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
1125
1137
  check_session_iframe: s.check_session_iframe,
1126
1138
  issuer: s.issuer
1127
1139
  });
1128
- const i = await x(this.configuration.service_worker_relative_url, this.configurationName) ? window.localStorage : null;
1129
- return await Ze(this.getFetch())(e, this.configuration.authority_time_cache_wellknowurl_in_second ?? 60 * 60, i, this.configuration.authority_timeout_wellknowurl_in_millisecond);
1140
+ const i = await E(this.configuration.service_worker_relative_url, this.configurationName) ? window.localStorage : null;
1141
+ return await en(this.getFetch())(e, this.configuration.authority_time_cache_wellknowurl_in_second ?? 60 * 60, i, this.configuration.authority_timeout_wellknowurl_in_millisecond);
1130
1142
  };
1131
1143
  return this.initPromise = t(), this.initPromise.then((o) => (this.initPromise = null, o));
1132
1144
  }
@@ -1137,230 +1149,230 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
1137
1149
  let s;
1138
1150
  if (this.tokens != null)
1139
1151
  return !1;
1140
- this.publishEvent(k.tryKeepExistingSessionAsync_begin, {});
1152
+ this.publishEvent(m.tryKeepExistingSessionAsync_begin, {});
1141
1153
  try {
1142
1154
  const t = this.configuration, o = await this.initAsync(t.authority, t.authority_configuration);
1143
- if (s = await x(t.service_worker_relative_url, this.configurationName), s) {
1155
+ if (s = await E(t.service_worker_relative_url, this.configurationName), s) {
1144
1156
  const { tokens: i } = await s.initAsync(o, "tryKeepExistingSessionAsync", t);
1145
1157
  if (i) {
1146
1158
  s.startKeepAliveServiceWorker(), this.tokens = i;
1147
1159
  const r = s.getLoginParams(this.configurationName);
1148
- this.timeoutId = M(this, this.tokens.refreshToken, this.tokens.expiresAt, r.extras);
1149
- const l = await s.getSessionStateAsync();
1150
- return await this.startCheckSessionAsync(o.check_session_iframe, t.client_id, l), this.publishEvent(k.tryKeepExistingSessionAsync_end, {
1160
+ this.timeoutId = K(this, this.tokens.refreshToken, this.tokens.expiresAt, r.extras);
1161
+ const c = await s.getSessionStateAsync();
1162
+ return await this.startCheckSessionAsync(o.check_session_iframe, t.client_id, c), this.publishEvent(m.tryKeepExistingSessionAsync_end, {
1151
1163
  success: !0,
1152
1164
  message: "tokens inside ServiceWorker are valid"
1153
1165
  }), !0;
1154
1166
  }
1155
- this.publishEvent(k.tryKeepExistingSessionAsync_end, {
1167
+ this.publishEvent(m.tryKeepExistingSessionAsync_end, {
1156
1168
  success: !1,
1157
1169
  message: "no exiting session found"
1158
1170
  });
1159
1171
  } else {
1160
- t.service_worker_relative_url && this.publishEvent(k.service_worker_not_supported_by_browser, {
1172
+ t.service_worker_relative_url && this.publishEvent(m.service_worker_not_supported_by_browser, {
1161
1173
  message: "service worker is not supported by this browser"
1162
1174
  });
1163
- const i = E(this.configurationName, t.storage ?? sessionStorage), { tokens: r } = await i.initAsync();
1175
+ const i = O(this.configurationName, t.storage ?? sessionStorage), { tokens: r } = await i.initAsync();
1164
1176
  if (r) {
1165
- this.tokens = ge(r, null, t.token_renew_mode);
1166
- const l = i.getLoginParams();
1167
- this.timeoutId = M(this, r.refreshToken, this.tokens.expiresAt, l.extras);
1177
+ this.tokens = _e(r, null, t.token_renew_mode);
1178
+ const c = i.getLoginParams();
1179
+ this.timeoutId = K(this, r.refreshToken, this.tokens.expiresAt, c.extras);
1168
1180
  const a = await i.getSessionStateAsync();
1169
- return await this.startCheckSessionAsync(o.check_session_iframe, t.client_id, a), this.publishEvent(k.tryKeepExistingSessionAsync_end, {
1181
+ return await this.startCheckSessionAsync(o.check_session_iframe, t.client_id, a), this.publishEvent(m.tryKeepExistingSessionAsync_end, {
1170
1182
  success: !0,
1171
1183
  message: "tokens inside storage are valid"
1172
1184
  }), !0;
1173
1185
  }
1174
1186
  }
1175
- return this.publishEvent(k.tryKeepExistingSessionAsync_end, {
1187
+ return this.publishEvent(m.tryKeepExistingSessionAsync_end, {
1176
1188
  success: !1,
1177
1189
  message: s ? "service worker sessions not retrieved" : "session storage sessions not retrieved"
1178
1190
  }), !1;
1179
1191
  } catch (t) {
1180
- return console.error(t), s && await s.clearAsync(), this.publishEvent(k.tryKeepExistingSessionAsync_error, "tokens inside ServiceWorker are invalid"), !1;
1192
+ return console.error(t), s && await s.clearAsync(), this.publishEvent(m.tryKeepExistingSessionAsync_error, "tokens inside ServiceWorker are invalid"), !1;
1181
1193
  }
1182
1194
  };
1183
1195
  return this.tryKeepExistingSessionPromise = e(), this.tryKeepExistingSessionPromise.then((s) => (this.tryKeepExistingSessionPromise = null, s));
1184
1196
  }
1185
1197
  async startCheckSessionAsync(e, s, t, o = !1) {
1186
- await Ue(this, W, this.configuration)(e, s, t, o);
1198
+ await Me(this, W, this.configuration)(e, s, t, o);
1187
1199
  }
1188
1200
  async loginAsync(e = void 0, s = null, t = !1, o = void 0, i = !1) {
1189
- return this.loginPromise !== null ? this.loginPromise : i ? Ve(window, this.configurationName, this.configuration, this.publishEvent.bind(this), this)(s, o) : (this.loginPromise = cn(window, this.configurationName, this.configuration, this.publishEvent.bind(this), this.initAsync.bind(this), this.location)(e, s, t, o), this.loginPromise.then((r) => (this.loginPromise = null, r)));
1201
+ return this.loginPromise !== null ? this.loginPromise : i ? Ue(window, this.configurationName, this.configuration, this.publishEvent.bind(this), this)(s, o) : (this.loginPromise = ln(this.configurationName, this.configuration, this.publishEvent.bind(this), this.initAsync.bind(this), this.location)(e, s, t, o), this.loginPromise.then((r) => (this.loginPromise = null, r)));
1190
1202
  }
1191
1203
  async loginCallbackAsync(e = !1) {
1192
1204
  if (this.loginCallbackPromise !== null)
1193
1205
  return this.loginCallbackPromise;
1194
1206
  const s = async () => {
1195
- const t = await ln(this)(e), o = t.tokens;
1196
- return this.tokens = o, await x(this.configuration.service_worker_relative_url, this.configurationName) || E(this.configurationName, this.configuration.storage).setTokens(o), this.publishEvent(L.eventNames.token_aquired, o), { parsedTokens: o, state: t.state, callbackPath: t.callbackPath };
1207
+ const t = await un(this)(e), o = t.tokens;
1208
+ return this.tokens = o, await E(this.configuration.service_worker_relative_url, this.configurationName) || O(this.configurationName, this.configuration.storage).setTokens(o), this.publishEvent(L.eventNames.token_aquired, o), { parsedTokens: o, state: t.state, callbackPath: t.callbackPath };
1197
1209
  };
1198
1210
  return this.loginCallbackPromise = s(), this.loginCallbackPromise.then((t) => (this.loginCallbackPromise = null, t));
1199
1211
  }
1200
1212
  async synchroniseTokensAsync(e, s = 0, t = !1, o = null, i) {
1201
1213
  for (; !navigator.onLine && document.hidden; )
1202
- await D(1e3), this.publishEvent(k.refreshTokensAsync, { message: "wait because navigator is offline and hidden" });
1214
+ await $(1e3), this.publishEvent(m.refreshTokensAsync, { message: "wait because navigator is offline and hidden" });
1203
1215
  let r = 6;
1204
1216
  for (; !navigator.onLine && r > 0; )
1205
- await D(1e3), r--, this.publishEvent(k.refreshTokensAsync, { message: `wait because navigator is offline try ${r}` });
1206
- let l = Math.floor(Math.random() * 15) + 10;
1207
- for (; document.hidden && l > 0; )
1208
- await D(1e3), l--, this.publishEvent(k.refreshTokensAsync, { message: `wait because navigator is hidden try ${l}` });
1209
- const f = document.hidden ? s : s + 1;
1217
+ await $(1e3), r--, this.publishEvent(m.refreshTokensAsync, { message: `wait because navigator is offline try ${r}` });
1218
+ let c = Math.floor(Math.random() * 15) + 10;
1219
+ for (; document.hidden && c > 0; )
1220
+ await $(1e3), c--, this.publishEvent(m.refreshTokensAsync, { message: `wait because navigator is hidden try ${c}` });
1221
+ const y = document.hidden ? s : s + 1;
1210
1222
  o || (o = {});
1211
- const c = this.configuration, _ = (u, y, d = null) => oe(this.configurationName, this.configuration, this.publishEvent.bind(this))(u, y, d), h = async () => {
1223
+ const l = this.configuration, u = (d, _, h = null) => te(this.configurationName, this.configuration, this.publishEvent.bind(this))(d, _, h), f = async () => {
1212
1224
  try {
1213
- let u;
1214
- const y = await x(c.service_worker_relative_url, this.configurationName);
1215
- y ? u = y.getLoginParams() : u = E(this.configurationName, c.storage).getLoginParams();
1216
- const d = await _({
1217
- ...u.extras,
1225
+ let d;
1226
+ const _ = await E(l.service_worker_relative_url, this.configurationName);
1227
+ _ ? d = _.getLoginParams() : d = O(this.configurationName, l.storage).getLoginParams();
1228
+ const h = await u({
1229
+ ...d.extras,
1218
1230
  ...o,
1219
1231
  prompt: "none"
1220
- }, u.state);
1221
- if (d)
1222
- return i(d.tokens), this.publishEvent(L.eventNames.token_renewed, {}), { tokens: d.tokens, status: "LOGGED" };
1223
- } catch (u) {
1224
- if (console.error(u), this.publishEvent(k.refreshTokensAsync_silent_error, { message: "exceptionSilent", exception: u.message }), u && u.message && u.message.startsWith("oidc"))
1225
- return i(null), this.publishEvent(k.refreshTokensAsync_error, { message: "refresh token silent" }), { tokens: null, status: "SESSION_LOST" };
1232
+ }, d.state);
1233
+ if (h)
1234
+ return i(h.tokens), this.publishEvent(L.eventNames.token_renewed, {}), { tokens: h.tokens, status: "LOGGED" };
1235
+ } catch (d) {
1236
+ if (console.error(d), this.publishEvent(m.refreshTokensAsync_silent_error, { message: "exceptionSilent", exception: d.message }), d && d.message && d.message.startsWith("oidc"))
1237
+ return i(null), this.publishEvent(m.refreshTokensAsync_error, { message: "refresh token silent" }), { tokens: null, status: "SESSION_LOST" };
1226
1238
  }
1227
- return this.publishEvent(k.refreshTokensAsync_error, { message: "refresh token silent return" }), await this.synchroniseTokensAsync(null, f, t, o, i);
1239
+ return this.publishEvent(m.refreshTokensAsync_error, { message: "refresh token silent return" }), await this.synchroniseTokensAsync(null, y, t, o, i);
1228
1240
  };
1229
1241
  if (s > 4)
1230
- return i(null), this.publishEvent(k.refreshTokensAsync_error, { message: "refresh token" }), { tokens: null, status: "SESSION_LOST" };
1242
+ return i(null), this.publishEvent(m.refreshTokensAsync_error, { message: "refresh token" }), { tokens: null, status: "SESSION_LOST" };
1231
1243
  try {
1232
- const { status: u, tokens: y, nonce: d } = await this.syncTokensInfoAsync(c, this.configurationName, this.tokens, t);
1233
- switch (u) {
1244
+ const { status: d, tokens: _, nonce: h } = await this.syncTokensInfoAsync(l, this.configurationName, this.tokens, t);
1245
+ switch (d) {
1234
1246
  case "SESSION_LOST":
1235
- return i(null), this.publishEvent(k.refreshTokensAsync_error, { message: "refresh token session lost" }), { tokens: null, status: "SESSION_LOST" };
1247
+ return i(null), this.publishEvent(m.refreshTokensAsync_error, { message: "refresh token session lost" }), { tokens: null, status: "SESSION_LOST" };
1236
1248
  case "NOT_CONNECTED":
1237
1249
  return i(null), { tokens: null, status: null };
1238
1250
  case "TOKENS_VALID":
1239
- return i(y), { tokens: y, status: "LOGGED_IN" };
1251
+ return i(_), { tokens: _, status: "LOGGED_IN" };
1240
1252
  case "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID":
1241
- return i(y), this.publishEvent(L.eventNames.token_renewed, { reason: "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID" }), { tokens: y, status: "LOGGED_IN" };
1253
+ return i(_), this.publishEvent(L.eventNames.token_renewed, { reason: "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID" }), { tokens: _, status: "LOGGED_IN" };
1242
1254
  case "LOGOUT_FROM_ANOTHER_TAB":
1243
- return i(null), this.publishEvent(k.logout_from_another_tab, { status: "session syncTokensAsync" }), { tokens: null, status: "LOGGED_OUT" };
1255
+ return i(null), this.publishEvent(m.logout_from_another_tab, { status: "session syncTokensAsync" }), { tokens: null, status: "LOGGED_OUT" };
1244
1256
  case "REQUIRE_SYNC_TOKENS":
1245
- return this.publishEvent(k.refreshTokensAsync_begin, { refreshToken: e, status: u, tryNumber: s }), await h();
1257
+ return this.publishEvent(m.refreshTokensAsync_begin, { refreshToken: e, status: d, tryNumber: s }), await f();
1246
1258
  default: {
1247
- if (this.publishEvent(k.refreshTokensAsync_begin, { refreshToken: e, status: u, tryNumber: s }), !e)
1248
- return await h();
1249
- const g = c.client_id, w = c.redirect_uri, T = c.authority, I = { ...c.token_request_extras ? c.token_request_extras : {} };
1250
- for (const [O, C] of Object.entries(o))
1251
- O.endsWith(":token_request") && (I[O.replace(":token_request", "")] = C);
1259
+ if (this.publishEvent(m.refreshTokensAsync_begin, { refreshToken: e, status: d, tryNumber: s }), !e)
1260
+ return await f();
1261
+ const g = l.client_id, A = l.redirect_uri, v = l.authority, D = { ...l.token_request_extras ? l.token_request_extras : {} };
1262
+ for (const [C, P] of Object.entries(o))
1263
+ C.endsWith(":token_request") && (D[C.replace(":token_request", "")] = P);
1252
1264
  return await (async () => {
1253
- const O = {
1265
+ const C = {
1254
1266
  client_id: g,
1255
- redirect_uri: w,
1267
+ redirect_uri: A,
1256
1268
  grant_type: "refresh_token",
1257
- refresh_token: y.refreshToken
1258
- }, C = await this.initAsync(T, c.authority_configuration), m = document.hidden ? 1e4 : 3e4 * 10, S = C.tokenEndpoint, A = {};
1259
- c.demonstrating_proof_of_possession && (A.DPoP = await this.generateDemonstrationOfProofOfPossessionAsync(y.accessToken, S, "POST"));
1260
- const b = await en(this.getFetch())(
1269
+ refresh_token: _.refreshToken
1270
+ }, P = await this.initAsync(v, l.authority_configuration), k = document.hidden ? 1e4 : 3e4 * 10, S = P.tokenEndpoint, x = {};
1271
+ l.demonstrating_proof_of_possession && (x.DPoP = await this.generateDemonstrationOfProofOfPossessionAsync(_.accessToken, S, "POST"));
1272
+ const p = await nn(this.getFetch())(
1261
1273
  S,
1262
- O,
1263
- I,
1264
- y,
1265
- A,
1266
- c.token_renew_mode,
1267
- m
1274
+ C,
1275
+ D,
1276
+ _,
1277
+ x,
1278
+ l.token_renew_mode,
1279
+ k
1268
1280
  );
1269
- if (b.success) {
1270
- const { isValid: B, reason: Y } = ke(b.data, d.nonce, C);
1271
- if (!B)
1272
- return i(null), this.publishEvent(k.refreshTokensAsync_error, { message: `refresh token return not valid tokens, reason: ${Y}` }), { tokens: null, status: "SESSION_LOST" };
1273
- if (i(b.data), b.demonstratingProofOfPossessionNonce) {
1274
- const re = await x(c.service_worker_relative_url, this.configurationName);
1275
- re ? await re.setDemonstratingProofOfPossessionNonce(b.demonstratingProofOfPossessionNonce) : await E(this.configurationName, c.storage).setDemonstratingProofOfPossessionNonce(b.demonstratingProofOfPossessionNonce);
1281
+ if (p.success) {
1282
+ const { isValid: N, reason: Ee } = ye(p.data, h.nonce, P);
1283
+ if (!N)
1284
+ return i(null), this.publishEvent(m.refreshTokensAsync_error, { message: `refresh token return not valid tokens, reason: ${Ee}` }), { tokens: null, status: "SESSION_LOST" };
1285
+ if (i(p.data), p.demonstratingProofOfPossessionNonce) {
1286
+ const ie = await E(l.service_worker_relative_url, this.configurationName);
1287
+ ie ? await ie.setDemonstratingProofOfPossessionNonce(p.demonstratingProofOfPossessionNonce) : await O(this.configurationName, l.storage).setDemonstratingProofOfPossessionNonce(p.demonstratingProofOfPossessionNonce);
1276
1288
  }
1277
- return this.publishEvent(k.refreshTokensAsync_end, { success: b.success }), this.publishEvent(L.eventNames.token_renewed, { reason: "REFRESH_TOKEN" }), { tokens: b.data, status: "LOGGED_IN" };
1289
+ return this.publishEvent(m.refreshTokensAsync_end, { success: p.success }), this.publishEvent(L.eventNames.token_renewed, { reason: "REFRESH_TOKEN" }), { tokens: p.data, status: "LOGGED_IN" };
1278
1290
  } else
1279
- return this.publishEvent(k.refreshTokensAsync_silent_error, {
1291
+ return this.publishEvent(m.refreshTokensAsync_silent_error, {
1280
1292
  message: "bad request",
1281
- tokenResponse: b
1282
- }), await this.synchroniseTokensAsync(e, f, t, o, i);
1293
+ tokenResponse: p
1294
+ }), await this.synchroniseTokensAsync(e, y, t, o, i);
1283
1295
  })();
1284
1296
  }
1285
1297
  }
1286
- } catch (u) {
1287
- return console.error(u), this.publishEvent(k.refreshTokensAsync_silent_error, { message: "exception", exception: u.message }), this.synchroniseTokensAsync(e, f, t, o, i);
1298
+ } catch (d) {
1299
+ return console.error(d), this.publishEvent(m.refreshTokensAsync_silent_error, { message: "exception", exception: d.message }), this.synchroniseTokensAsync(e, y, t, o, i);
1288
1300
  }
1289
1301
  }
1290
1302
  async generateDemonstrationOfProofOfPossessionAsync(e, s, t) {
1291
- const o = this.configuration, i = { ath: await ve(e) }, r = await x(o.service_worker_relative_url, this.configurationName);
1292
- let l = null, a;
1303
+ const o = this.configuration, i = { ath: await we(e) }, r = await E(o.service_worker_relative_url, this.configurationName);
1304
+ let c = null, a;
1293
1305
  if (r)
1294
- l = await r.getDemonstratingProofOfPossessionNonce(), a = await r.getDemonstratingProofOfPossessionJwkAsync();
1306
+ c = await r.getDemonstratingProofOfPossessionNonce(), a = await r.getDemonstratingProofOfPossessionJwkAsync();
1295
1307
  else {
1296
- const f = E(this.configurationName, o.storage);
1297
- a = await f.getDemonstratingProofOfPossessionJwkAsync(), l = await f.getDemonstratingProofOfPossessionNonce();
1308
+ const y = O(this.configurationName, o.storage);
1309
+ a = await y.getDemonstratingProofOfPossessionJwkAsync(), c = await y.getDemonstratingProofOfPossessionNonce();
1298
1310
  }
1299
- return l && (i.nonce = l), await Ie(a, t, s, i);
1311
+ return c && (i.nonce = c), await Oe(a, t, s, i);
1300
1312
  }
1301
1313
  async syncTokensInfoAsync(e, s, t, o = !1) {
1302
1314
  const i = { nonce: null };
1303
1315
  if (!t)
1304
1316
  return { tokens: null, status: "NOT_CONNECTED", nonce: i };
1305
1317
  let r = i;
1306
- const l = await this.initAsync(e.authority, e.authority_configuration), a = await x(e.service_worker_relative_url, s);
1318
+ const c = await this.initAsync(e.authority, e.authority_configuration), a = await E(e.service_worker_relative_url, s);
1307
1319
  if (a) {
1308
- const { status: _, tokens: h } = await a.initAsync(l, "syncTokensAsync", e);
1309
- if (_ === "LOGGED_OUT")
1320
+ const { status: u, tokens: f } = await a.initAsync(c, "syncTokensAsync", e);
1321
+ if (u === "LOGGED_OUT")
1310
1322
  return { tokens: null, status: "LOGOUT_FROM_ANOTHER_TAB", nonce: i };
1311
- if (_ === "SESSIONS_LOST")
1323
+ if (u === "SESSIONS_LOST")
1312
1324
  return { tokens: null, status: "SESSIONS_LOST", nonce: i };
1313
- if (!_ || !h)
1325
+ if (!u || !f)
1314
1326
  return { tokens: null, status: "REQUIRE_SYNC_TOKENS", nonce: i };
1315
- if (h.issuedAt !== t.issuedAt) {
1316
- const y = U(e.refresh_time_before_tokens_expiration_in_second, h.expiresAt) > 0 ? "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID" : "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID", d = await a.getNonceAsync();
1317
- return { tokens: h, status: y, nonce: d };
1327
+ if (f.issuedAt !== t.issuedAt) {
1328
+ const _ = M(e.refresh_time_before_tokens_expiration_in_second, f.expiresAt) > 0 ? "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID" : "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID", h = await a.getNonceAsync();
1329
+ return { tokens: f, status: _, nonce: h };
1318
1330
  }
1319
1331
  r = await a.getNonceAsync();
1320
1332
  } else {
1321
- const _ = E(s, e.storage ?? sessionStorage), { tokens: h, status: u } = await _.initAsync();
1322
- if (h) {
1323
- if (u === "SESSIONS_LOST")
1333
+ const u = O(s, e.storage ?? sessionStorage), { tokens: f, status: d } = await u.initAsync();
1334
+ if (f) {
1335
+ if (d === "SESSIONS_LOST")
1324
1336
  return { tokens: null, status: "SESSIONS_LOST", nonce: i };
1325
- if (h.issuedAt !== t.issuedAt) {
1326
- const d = U(e.refresh_time_before_tokens_expiration_in_second, h.expiresAt) > 0 ? "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID" : "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID", g = await _.getNonceAsync();
1327
- return { tokens: h, status: d, nonce: g };
1337
+ if (f.issuedAt !== t.issuedAt) {
1338
+ const h = M(e.refresh_time_before_tokens_expiration_in_second, f.expiresAt) > 0 ? "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID" : "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID", g = await u.getNonceAsync();
1339
+ return { tokens: f, status: h, nonce: g };
1328
1340
  }
1329
1341
  } else
1330
1342
  return { tokens: null, status: "LOGOUT_FROM_ANOTHER_TAB", nonce: i };
1331
- r = await _.getNonceAsync();
1343
+ r = await u.getNonceAsync();
1332
1344
  }
1333
- const c = U(e.refresh_time_before_tokens_expiration_in_second, t.expiresAt) > 0 ? "TOKENS_VALID" : "TOKENS_INVALID";
1334
- return o ? { tokens: t, status: "FORCE_REFRESH", nonce: r } : { tokens: t, status: c, nonce: r };
1345
+ const l = M(e.refresh_time_before_tokens_expiration_in_second, t.expiresAt) > 0 ? "TOKENS_VALID" : "TOKENS_INVALID";
1346
+ return o ? { tokens: t, status: "FORCE_REFRESH", nonce: r } : { tokens: t, status: l, nonce: r };
1335
1347
  }
1336
1348
  loginCallbackWithAutoTokensRenewAsync() {
1337
- return this.loginCallbackWithAutoTokensRenewPromise !== null ? this.loginCallbackWithAutoTokensRenewPromise : (this.loginCallbackWithAutoTokensRenewPromise = yn(this), this.loginCallbackWithAutoTokensRenewPromise.then((e) => (this.loginCallbackWithAutoTokensRenewPromise = null, e)));
1349
+ return this.loginCallbackWithAutoTokensRenewPromise !== null ? this.loginCallbackWithAutoTokensRenewPromise : (this.loginCallbackWithAutoTokensRenewPromise = gn(this), this.loginCallbackWithAutoTokensRenewPromise.then((e) => (this.loginCallbackWithAutoTokensRenewPromise = null, e)));
1338
1350
  }
1339
1351
  userInfoAsync(e = !1) {
1340
- return this.userInfoPromise !== null ? this.userInfoPromise : (this.userInfoPromise = fn(this)(e), this.userInfoPromise.then((s) => (this.userInfoPromise = null, s)));
1352
+ return this.userInfoPromise !== null ? this.userInfoPromise : (this.userInfoPromise = hn(this)(e), this.userInfoPromise.then((s) => (this.userInfoPromise = null, s)));
1341
1353
  }
1342
1354
  async renewTokensAsync(e = null) {
1343
1355
  if (this.renewTokensPromise !== null)
1344
1356
  return this.renewTokensPromise;
1345
1357
  if (this.timeoutId)
1346
- return K.clearTimeout(this.timeoutId), this.renewTokensPromise = we(this, this.tokens.refreshToken, !0, e), this.renewTokensPromise.then((s) => (this.renewTokensPromise = null, s));
1358
+ return J.clearTimeout(this.timeoutId), this.renewTokensPromise = me(this, this.tokens.refreshToken, !0, e), this.renewTokensPromise.then((s) => (this.renewTokensPromise = null, s));
1347
1359
  }
1348
1360
  async destroyAsync(e) {
1349
- return await un(this)(e);
1361
+ return await dn(this)(e);
1350
1362
  }
1351
1363
  async logoutSameTabAsync(e, s) {
1352
- this.configuration.monitor_session && this.configuration.client_id === e && s && this.tokens && this.tokens.idTokenPayload && this.tokens.idTokenPayload.sub === s && (this.publishEvent(k.logout_from_same_tab, { message: s }), await this.destroyAsync("LOGGED_OUT"));
1364
+ this.configuration.monitor_session && this.configuration.client_id === e && s && this.tokens && this.tokens.idTokenPayload && this.tokens.idTokenPayload.sub === s && (this.publishEvent(m.logout_from_same_tab, { message: s }), await this.destroyAsync("LOGGED_OUT"));
1353
1365
  }
1354
1366
  async logoutOtherTabAsync(e, s) {
1355
- this.configuration.monitor_session && this.configuration.client_id === e && s && this.tokens && this.tokens.idTokenPayload && this.tokens.idTokenPayload.sub === s && (await this.destroyAsync("LOGGED_OUT"), this.publishEvent(k.logout_from_another_tab, { message: "SessionMonitor", sub: s }));
1367
+ this.configuration.monitor_session && this.configuration.client_id === e && s && this.tokens && this.tokens.idTokenPayload && this.tokens.idTokenPayload.sub === s && (await this.destroyAsync("LOGGED_OUT"), this.publishEvent(m.logout_from_another_tab, { message: "SessionMonitor", sub: s }));
1356
1368
  }
1357
1369
  async logoutAsync(e = void 0, s = null) {
1358
- return this.logoutPromise ? this.logoutPromise : (this.logoutPromise = dn(this, W, this.getFetch(), window, console, this.location)(e, s), this.logoutPromise.then((t) => (this.logoutPromise = null, t)));
1370
+ return this.logoutPromise ? this.logoutPromise : (this.logoutPromise = fn(this, W, this.getFetch(), console, this.location)(e, s), this.logoutPromise.then((t) => (this.logoutPromise = null, t)));
1359
1371
  }
1360
1372
  };
1361
- L.getOrCreate = (e, s) => (t, o = "default") => _n(e, s)(t, o), L.eventNames = k;
1362
- let $ = L;
1363
- const V = class V {
1373
+ L.getOrCreate = (e, s) => (t, o = "default") => yn(e, s)(t, o), L.eventNames = m;
1374
+ let R = L;
1375
+ const U = class U {
1364
1376
  constructor(e) {
1365
1377
  this._oidc = e;
1366
1378
  }
@@ -1374,7 +1386,7 @@ const V = class V {
1374
1386
  this._oidc.publishEvent(e, s);
1375
1387
  }
1376
1388
  static get(e = "default") {
1377
- return new V($.get(e));
1389
+ return new U(R.get(e));
1378
1390
  }
1379
1391
  tryKeepExistingSessionAsync() {
1380
1392
  return this._oidc.tryKeepExistingSessionAsync();
@@ -1404,19 +1416,19 @@ const V = class V {
1404
1416
  return this._oidc.generateDemonstrationOfProofOfPossessionAsync(e, s, t);
1405
1417
  }
1406
1418
  async getValidTokenAsync(e = 200, s = 50) {
1407
- return De(this._oidc, e, s);
1419
+ return We(this._oidc, e, s);
1408
1420
  }
1409
1421
  async userInfoAsync(e = !1) {
1410
1422
  return this._oidc.userInfoAsync(e);
1411
1423
  }
1412
1424
  };
1413
- V.getOrCreate = (e, s = new X()) => (t, o = "default") => new V($.getOrCreate(e, s)(t, o)), V.eventNames = $.eventNames;
1414
- let ye = V;
1425
+ U.getOrCreate = (e, s = new X()) => (t, o = "default") => new U(R.getOrCreate(e, s)(t, o)), U.eventNames = R.eventNames;
1426
+ let he = U;
1415
1427
  export {
1416
- ye as OidcClient,
1428
+ he as OidcClient,
1417
1429
  X as OidcLocation,
1418
- z as TokenRenewMode,
1419
- hn as getFetchDefault,
1420
- H as getParseQueryStringFromLocation,
1421
- mn as getPath
1430
+ Y as TokenRenewMode,
1431
+ _n as getFetchDefault,
1432
+ G as getParseQueryStringFromLocation,
1433
+ pn as getPath
1422
1434
  };