@axa-fr/oidc-client 7.29.8 → 7.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +174 -0
  2. package/dist/events.d.ts +3 -0
  3. package/dist/events.d.ts.map +1 -1
  4. package/dist/fetch.d.ts +2 -2
  5. package/dist/fetch.d.ts.map +1 -1
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +1339 -871
  9. package/dist/index.umd.cjs +2 -2
  10. package/dist/initSession.d.ts +2 -0
  11. package/dist/initSession.d.ts.map +1 -1
  12. package/dist/initWorker.d.ts +1 -25
  13. package/dist/initWorker.d.ts.map +1 -1
  14. package/dist/jwt.d.ts.map +1 -1
  15. package/dist/legacyCompatibility.spec.d.ts +2 -0
  16. package/dist/legacyCompatibility.spec.d.ts.map +1 -0
  17. package/dist/login.d.ts +2 -1
  18. package/dist/login.d.ts.map +1 -1
  19. package/dist/logout.d.ts.map +1 -1
  20. package/dist/node_modules/@axa-fr/oidc-client-service-worker/dist/OidcServiceWorker.js +1049 -0
  21. package/dist/node_modules/@axa-fr/oidc-client-service-worker/dist/OidcTrustedDomains.js +31 -0
  22. package/dist/oidc.d.ts +6 -1
  23. package/dist/oidc.d.ts.map +1 -1
  24. package/dist/oidcClient.d.ts +13 -2
  25. package/dist/oidcClient.d.ts.map +1 -1
  26. package/dist/oidcError.d.ts +5 -0
  27. package/dist/oidcError.d.ts.map +1 -1
  28. package/dist/parseTokens.d.ts +10 -0
  29. package/dist/parseTokens.d.ts.map +1 -1
  30. package/dist/protocol.d.ts +7 -1
  31. package/dist/protocol.d.ts.map +1 -1
  32. package/dist/renewTokens.d.ts +0 -6
  33. package/dist/renewTokens.d.ts.map +1 -1
  34. package/dist/requests.d.ts +3 -3
  35. package/dist/requests.d.ts.map +1 -1
  36. package/dist/resourceParameters.d.ts +9 -0
  37. package/dist/resourceParameters.d.ts.map +1 -0
  38. package/dist/resourceTokens.d.ts +34 -0
  39. package/dist/resourceTokens.d.ts.map +1 -0
  40. package/dist/resourceTokens.spec.d.ts +2 -0
  41. package/dist/resourceTokens.spec.d.ts.map +1 -0
  42. package/dist/silentLogin.d.ts +2 -1
  43. package/dist/silentLogin.d.ts.map +1 -1
  44. package/dist/types.d.ts +28 -0
  45. package/dist/types.d.ts.map +1 -1
  46. package/dist/version.d.ts +1 -1
  47. package/package.json +3 -3
  48. package/src/events.ts +3 -0
  49. package/src/fetch.ts +115 -15
  50. package/src/index.ts +4 -0
  51. package/src/initSession.ts +9 -0
  52. package/src/initWorker.ts +65 -13
  53. package/src/jwt.spec.ts +17 -0
  54. package/src/jwt.ts +4 -1
  55. package/src/legacyCompatibility.spec.ts +142 -0
  56. package/src/login.ts +91 -29
  57. package/src/logout.ts +36 -0
  58. package/src/oidc.ts +71 -20
  59. package/src/oidcClient.ts +48 -3
  60. package/src/oidcError.ts +7 -0
  61. package/src/parseTokens.ts +14 -1
  62. package/src/protocol.ts +16 -1
  63. package/src/renewTokens.ts +19 -8
  64. package/src/requests.ts +13 -11
  65. package/src/resourceParameters.ts +85 -0
  66. package/src/resourceTokens.spec.ts +1271 -0
  67. package/src/resourceTokens.ts +708 -0
  68. package/src/silentLogin.spec.ts +87 -1
  69. package/src/silentLogin.ts +24 -22
  70. package/src/types.ts +34 -0
  71. package/src/version.ts +1 -1
package/dist/index.js CHANGED
@@ -1,5 +1,87 @@
1
- //#region src/events.ts
1
+ //#region src/oidcError.ts
2
2
  var e = {
3
+ INVALID_RESOURCE: "INVALID_RESOURCE",
4
+ INVALID_TARGET: "INVALID_TARGET",
5
+ RESOURCE_TOKEN_UNAVAILABLE: "RESOURCE_TOKEN_UNAVAILABLE",
6
+ RESOURCE_CONTEXT_MISMATCH: "RESOURCE_CONTEXT_MISMATCH",
7
+ RESOURCE_WORKER_UNSUPPORTED: "RESOURCE_WORKER_UNSUPPORTED",
8
+ LOGIN_REQUIRED: "LOGIN_REQUIRED",
9
+ CONSENT_REQUIRED: "CONSENT_REQUIRED",
10
+ INTERACTION_REQUIRED: "INTERACTION_REQUIRED",
11
+ OAUTH_ERROR: "OAUTH_ERROR",
12
+ TOKEN_REQUEST_FAILED: "TOKEN_REQUEST_FAILED",
13
+ SILENT_LOGIN_TIMEOUT: "SILENT_LOGIN_TIMEOUT",
14
+ INVALID_STATE: "INVALID_STATE",
15
+ INVALID_NONCE: "INVALID_NONCE",
16
+ DPOP_NONCE_REQUIRED: "DPOP_NONCE_REQUIRED",
17
+ NETWORK_ERROR: "NETWORK_ERROR",
18
+ STATE_MISSING: "STATE_MISSING",
19
+ STATE_MISMATCH: "STATE_MISMATCH",
20
+ NONCE_MISSING: "NONCE_MISSING",
21
+ ENDPOINT_UNAVAILABLE: "ENDPOINT_UNAVAILABLE",
22
+ REQUEST_FAILED: "REQUEST_FAILED",
23
+ INVALID_RESPONSE: "INVALID_RESPONSE"
24
+ }, t = new Set(Object.values(e)), n = /* @__PURE__ */ new Set([
25
+ "login",
26
+ "callback",
27
+ "refresh",
28
+ "logout",
29
+ "userinfo",
30
+ "api_request"
31
+ ]), r = class extends Error {
32
+ constructor(e, t, n) {
33
+ super(t), this.name = "OidcError", this.code = e, this.phase = n.phase, this.oauthError = n.oauthError, this.oauthErrorDescription = n.oauthErrorDescription, this.retryable = n.retryable, this.status = n.status, this.cause = n.cause, Object.setPrototypeOf(this, new.target.prototype);
34
+ }
35
+ }, i = (e) => e instanceof r, a = (e) => e === 408 || e === 429 || e !== void 0 && e >= 500, o = (t) => {
36
+ switch (t) {
37
+ case "invalid_target": return e.INVALID_TARGET;
38
+ case "login_required": return e.LOGIN_REQUIRED;
39
+ case "consent_required": return e.CONSENT_REQUIRED;
40
+ case "interaction_required": return e.INTERACTION_REQUIRED;
41
+ case "use_dpop_nonce": return e.DPOP_NONCE_REQUIRED;
42
+ default: return e.OAUTH_ERROR;
43
+ }
44
+ }, s = (t, n, i, s, c) => {
45
+ let l = o(t);
46
+ return new r(l, i, {
47
+ phase: s,
48
+ retryable: l !== e.LOGIN_REQUIRED && l !== e.CONSENT_REQUIRED && l !== e.INTERACTION_REQUIRED && (l === e.DPOP_NONCE_REQUIRED || t === "server_error" || t === "temporarily_unavailable" || a(c)),
49
+ oauthError: t,
50
+ oauthErrorDescription: n,
51
+ status: c
52
+ });
53
+ }, c = (t, n, i = "Network request failed") => {
54
+ let a = t instanceof Error && typeof t.message == "string" && t.message ? t.message : i;
55
+ return new r(e.NETWORK_ERROR, a, {
56
+ phase: n,
57
+ retryable: !0,
58
+ cause: t
59
+ });
60
+ }, l = (e) => e instanceof Error ? e.name === "AbortError" || e.name === "NetworkError" || e.message === "Network request failed" || e.message === "Failed to fetch" || e.message === "fetch failed" : !1, u = (e) => ({
61
+ name: e.name,
62
+ message: e.message,
63
+ code: e.code,
64
+ phase: e.phase,
65
+ retryable: e.retryable,
66
+ oauthError: e.oauthError,
67
+ oauthErrorDescription: e.oauthErrorDescription,
68
+ status: e.status
69
+ }), d = (e) => {
70
+ if (!e || typeof e != "object") return null;
71
+ let i = e;
72
+ if (typeof i.message != "string" || typeof i.code != "string" || !t.has(i.code) || typeof i.phase != "string" || !n.has(i.phase) || typeof i.retryable != "boolean") return null;
73
+ let a = new r(i.code, i.message, {
74
+ phase: i.phase,
75
+ retryable: i.retryable,
76
+ oauthError: typeof i.oauthError == "string" ? i.oauthError : void 0,
77
+ oauthErrorDescription: typeof i.oauthErrorDescription == "string" ? i.oauthErrorDescription : void 0,
78
+ status: typeof i.status == "number" ? i.status : void 0
79
+ });
80
+ return typeof i.name == "string" && i.name && (a.name = i.name), a;
81
+ }, f = {
82
+ resource_token_acquired: "resource_token_acquired",
83
+ resource_token_cleared: "resource_token_cleared",
84
+ resource_token_error: "resource_token_error",
3
85
  service_worker_not_supported_by_browser: "service_worker_not_supported_by_browser",
4
86
  token_acquired: "token_acquired",
5
87
  logout_from_another_tab: "logout_from_another_tab",
@@ -34,82 +116,86 @@ var e = {
34
116
  syncTokensAsync_error: "syncTokensAsync_error",
35
117
  tokensInvalidAndWaitingActionsToRefresh: "tokensInvalidAndWaitingActionsToRefresh",
36
118
  loadingTimeout_error: "loadingTimeout_error"
37
- }, t = (e, t, n) => {
119
+ }, p = (e, t, n) => {
38
120
  n == null ? delete e[t] : e[t] = JSON.stringify(n);
39
- }, n = (e, t, n) => {
121
+ }, m = (e, t, n) => {
40
122
  n == null ? delete e[t] : e[t] = n;
41
- }, r = (e) => {
123
+ }, h = (e) => {
42
124
  if (typeof e != "string" || e === "undefined" || e === "null" || e === "") return null;
43
125
  try {
44
126
  return JSON.parse(e);
45
127
  } catch {
46
128
  return null;
47
129
  }
48
- }, i = (e, i = sessionStorage, a) => {
49
- let o = a ?? i, s = (n) => (t(i, `oidc.${e}`, {
130
+ }, g = (e, t = sessionStorage, n) => {
131
+ let r = n ?? t, i = (i) => (p(t, `oidc.${e}`, {
50
132
  tokens: null,
51
- status: n
52
- }), delete i[`oidc.${e}.userInfo`], a && a !== i && (delete o[`oidc.login.${e}`], delete o[`oidc.state.${e}`], delete o[`oidc.code_verifier.${e}`], delete o[`oidc.nonce.${e}`]), Promise.resolve()), c = async () => {
53
- let n = r(i[`oidc.${e}`]);
133
+ status: i
134
+ }), delete t[`oidc.${e}.userInfo`], n && n !== t && (delete r[`oidc.login.${e}`], delete r[`oidc.state.${e}`], delete r[`oidc.code_verifier.${e}`], delete r[`oidc.nonce.${e}`]), Promise.resolve()), a = async () => {
135
+ let n = h(t[`oidc.${e}`]);
54
136
  return n ? Promise.resolve({
55
137
  tokens: n.tokens,
56
138
  status: n.status
57
- }) : (t(i, `oidc.${e}`, {
139
+ }) : (p(t, `oidc.${e}`, {
58
140
  tokens: null,
59
141
  status: null
60
142
  }), {
61
143
  tokens: null,
62
144
  status: null
63
145
  });
64
- }, l = (n) => {
65
- t(i, `oidc.${e}`, { tokens: n });
66
- }, u = async (t) => {
67
- n(i, `oidc.session_state.${e}`, t);
68
- }, d = async () => i[`oidc.session_state.${e}`], f = (t) => {
69
- n(o, `oidc.nonce.${e}`, t?.nonce);
70
- }, p = (n) => {
71
- t(i, `oidc.jwk.${e}`, n);
72
- }, m = () => r(i[`oidc.jwk.${e}`]), h = async () => ({ nonce: o[`oidc.nonce.${e}`] }), g = async (t) => {
73
- n(i, `oidc.dpop_nonce.${e}`, t);
74
- }, _ = () => i[`oidc.dpop_nonce.${e}`], v = () => {
75
- let t = r(i[`oidc.${e}`]);
76
- return t ? JSON.stringify({ tokens: t.tokens }) : null;
77
- }, y = {};
146
+ }, o = (n) => {
147
+ p(t, `oidc.${e}`, { tokens: n });
148
+ }, s = async (n) => {
149
+ m(t, `oidc.session_state.${e}`, n);
150
+ }, c = async () => t[`oidc.session_state.${e}`], l = (t) => {
151
+ m(r, `oidc.nonce.${e}`, t?.nonce);
152
+ }, u = (n) => {
153
+ p(t, `oidc.jwk.${e}`, n);
154
+ }, d = () => h(t[`oidc.jwk.${e}`]), f = async () => ({ nonce: r[`oidc.nonce.${e}`] }), g = async (n) => {
155
+ m(t, `oidc.dpop_nonce.${e}`, n);
156
+ }, _ = () => t[`oidc.dpop_nonce.${e}`], v = async (n) => {
157
+ m(t, `oidc.dpop_api_nonce.${e}`, n);
158
+ }, y = () => t[`oidc.dpop_api_nonce.${e}`], b = () => {
159
+ let n = h(t[`oidc.${e}`]);
160
+ return n ? JSON.stringify({ tokens: n.tokens }) : null;
161
+ }, x = {};
78
162
  return {
79
- clearAsync: s,
80
- initAsync: c,
81
- setTokens: l,
82
- getTokens: v,
83
- setSessionStateAsync: u,
84
- getSessionStateAsync: d,
85
- setNonceAsync: f,
86
- getNonceAsync: h,
87
- setLoginParams: (n) => {
88
- n == null ? (delete y[e], delete o[`oidc.login.${e}`]) : (y[e] = n, t(o, `oidc.login.${e}`, n));
163
+ clearAsync: i,
164
+ initAsync: a,
165
+ setTokens: o,
166
+ getTokens: b,
167
+ setSessionStateAsync: s,
168
+ getSessionStateAsync: c,
169
+ setNonceAsync: l,
170
+ getNonceAsync: f,
171
+ setLoginParams: (t) => {
172
+ t == null ? (delete x[e], delete r[`oidc.login.${e}`]) : (x[e] = t, p(r, `oidc.login.${e}`, t));
89
173
  },
90
174
  getLoginParams: () => {
91
- if (y[e]) return y[e];
92
- let t = r(o[`oidc.login.${e}`]);
93
- return t === null ? (console.warn(`storage[oidc.login.${e}] is empty, you should have an bad OIDC or code configuration somewhere.`), null) : (y[e] = t, t);
175
+ if (x[e]) return x[e];
176
+ let t = h(r[`oidc.login.${e}`]);
177
+ return t === null ? (console.warn(`storage[oidc.login.${e}] is empty, you should have an bad OIDC or code configuration somewhere.`), null) : (x[e] = t, t);
94
178
  },
95
- getStateAsync: async () => o[`oidc.state.${e}`],
179
+ getStateAsync: async () => r[`oidc.state.${e}`],
96
180
  setStateAsync: async (t) => {
97
- n(o, `oidc.state.${e}`, t);
181
+ m(r, `oidc.state.${e}`, t);
98
182
  },
99
- getCodeVerifierAsync: async () => o[`oidc.code_verifier.${e}`],
183
+ getCodeVerifierAsync: async () => r[`oidc.code_verifier.${e}`],
100
184
  setCodeVerifierAsync: async (t) => {
101
- n(o, `oidc.code_verifier.${e}`, t);
185
+ m(r, `oidc.code_verifier.${e}`, t);
102
186
  },
103
187
  setDemonstratingProofOfPossessionNonce: g,
104
188
  getDemonstratingProofOfPossessionNonce: _,
105
- setDemonstratingProofOfPossessionJwkAsync: p,
106
- getDemonstratingProofOfPossessionJwkAsync: m
189
+ setDemonstratingProofOfPossessionApiNonce: v,
190
+ getDemonstratingProofOfPossessionApiNonce: y,
191
+ setDemonstratingProofOfPossessionJwkAsync: u,
192
+ getDemonstratingProofOfPossessionJwkAsync: d
107
193
  };
108
- }, a = 2e3, o = console, s = class {
109
- constructor(e, t, n, r = a, i = !0) {
110
- this._callback = e, this._client_id = t, this._url = n, this._interval = r || a, this._stopOnError = i;
111
- let o = n.indexOf("/", n.indexOf("//") + 2);
112
- this._frame_origin = n.substring(0, o), this._frame = window.document.createElement("iframe"), this._frame.style.visibility = "hidden", this._frame.style.position = "absolute", this._frame.style.display = "none", this._frame.width = 0, this._frame.height = 0, this._frame.src = n;
194
+ }, _ = 2e3, v = console, y = class {
195
+ constructor(e, t, n, r = _, i = !0) {
196
+ this._callback = e, this._client_id = t, this._url = n, this._interval = r || _, this._stopOnError = i;
197
+ let a = n.indexOf("/", n.indexOf("//") + 2);
198
+ this._frame_origin = n.substring(0, a), this._frame = window.document.createElement("iframe"), this._frame.style.visibility = "hidden", this._frame.style.position = "absolute", this._frame.style.display = "none", this._frame.width = 0, this._frame.height = 0, this._frame.src = n;
113
199
  }
114
200
  load() {
115
201
  return new Promise((e) => {
@@ -119,91 +205,18 @@ var e = {
119
205
  });
120
206
  }
121
207
  _message(e) {
122
- e.origin === this._frame_origin && e.source === this._frame.contentWindow && (e.data === "error" ? (o.error("CheckSessionIFrame: error message from check session op iframe"), this._stopOnError && this.stop()) : e.data === "changed" ? (o.debug(e), o.debug("CheckSessionIFrame: changed message from check session op iframe"), this.stop(), this._callback()) : o.debug("CheckSessionIFrame: " + e.data + " message from check session op iframe"));
208
+ e.origin === this._frame_origin && e.source === this._frame.contentWindow && (e.data === "error" ? (v.error("CheckSessionIFrame: error message from check session op iframe"), this._stopOnError && this.stop()) : e.data === "changed" ? (v.debug(e), v.debug("CheckSessionIFrame: changed message from check session op iframe"), this.stop(), this._callback()) : v.debug("CheckSessionIFrame: " + e.data + " message from check session op iframe"));
123
209
  }
124
210
  start(e) {
125
- o.debug("CheckSessionIFrame.start :" + e), this.stop();
211
+ v.debug("CheckSessionIFrame.start :" + e), this.stop();
126
212
  let t = () => {
127
213
  this._frame.contentWindow.postMessage(this._client_id + " " + e, this._frame_origin);
128
214
  };
129
215
  t(), this._timer = window.setInterval(t, this._interval);
130
216
  }
131
217
  stop() {
132
- this._timer &&= (o.debug("CheckSessionIFrame.stop"), window.clearInterval(this._timer), null);
133
- }
134
- }, c = {
135
- LOGIN_REQUIRED: "LOGIN_REQUIRED",
136
- CONSENT_REQUIRED: "CONSENT_REQUIRED",
137
- INTERACTION_REQUIRED: "INTERACTION_REQUIRED",
138
- OAUTH_ERROR: "OAUTH_ERROR",
139
- TOKEN_REQUEST_FAILED: "TOKEN_REQUEST_FAILED",
140
- SILENT_LOGIN_TIMEOUT: "SILENT_LOGIN_TIMEOUT",
141
- INVALID_STATE: "INVALID_STATE",
142
- INVALID_NONCE: "INVALID_NONCE",
143
- DPOP_NONCE_REQUIRED: "DPOP_NONCE_REQUIRED",
144
- NETWORK_ERROR: "NETWORK_ERROR",
145
- STATE_MISSING: "STATE_MISSING",
146
- STATE_MISMATCH: "STATE_MISMATCH",
147
- NONCE_MISSING: "NONCE_MISSING",
148
- ENDPOINT_UNAVAILABLE: "ENDPOINT_UNAVAILABLE",
149
- REQUEST_FAILED: "REQUEST_FAILED",
150
- INVALID_RESPONSE: "INVALID_RESPONSE"
151
- }, l = new Set(Object.values(c)), u = /* @__PURE__ */ new Set([
152
- "login",
153
- "callback",
154
- "refresh",
155
- "logout",
156
- "userinfo",
157
- "api_request"
158
- ]), d = class extends Error {
159
- constructor(e, t, n) {
160
- super(t), this.name = "OidcError", this.code = e, this.phase = n.phase, this.oauthError = n.oauthError, this.oauthErrorDescription = n.oauthErrorDescription, this.retryable = n.retryable, this.status = n.status, this.cause = n.cause, Object.setPrototypeOf(this, new.target.prototype);
218
+ this._timer &&= (v.debug("CheckSessionIFrame.stop"), window.clearInterval(this._timer), null);
161
219
  }
162
- }, f = (e) => e instanceof d, p = (e) => e === 408 || e === 429 || e !== void 0 && e >= 500, m = (e) => {
163
- switch (e) {
164
- case "login_required": return c.LOGIN_REQUIRED;
165
- case "consent_required": return c.CONSENT_REQUIRED;
166
- case "interaction_required": return c.INTERACTION_REQUIRED;
167
- case "use_dpop_nonce": return c.DPOP_NONCE_REQUIRED;
168
- default: return c.OAUTH_ERROR;
169
- }
170
- }, h = (e, t, n, r, i) => {
171
- let a = m(e);
172
- return new d(a, n, {
173
- phase: r,
174
- retryable: a !== c.LOGIN_REQUIRED && a !== c.CONSENT_REQUIRED && a !== c.INTERACTION_REQUIRED && (a === c.DPOP_NONCE_REQUIRED || e === "server_error" || e === "temporarily_unavailable" || p(i)),
175
- oauthError: e,
176
- oauthErrorDescription: t,
177
- status: i
178
- });
179
- }, g = (e, t, n = "Network request failed") => {
180
- let r = e instanceof Error && typeof e.message == "string" && e.message ? e.message : n;
181
- return new d(c.NETWORK_ERROR, r, {
182
- phase: t,
183
- retryable: !0,
184
- cause: e
185
- });
186
- }, _ = (e) => e instanceof Error ? e.name === "AbortError" || e.name === "NetworkError" || e.message === "Network request failed" || e.message === "Failed to fetch" || e.message === "fetch failed" : !1, v = (e) => ({
187
- name: e.name,
188
- message: e.message,
189
- code: e.code,
190
- phase: e.phase,
191
- retryable: e.retryable,
192
- oauthError: e.oauthError,
193
- oauthErrorDescription: e.oauthErrorDescription,
194
- status: e.status
195
- }), y = (e) => {
196
- if (!e || typeof e != "object") return null;
197
- let t = e;
198
- if (typeof t.message != "string" || typeof t.code != "string" || !l.has(t.code) || typeof t.phase != "string" || !u.has(t.phase) || typeof t.retryable != "boolean") return null;
199
- let n = new d(t.code, t.message, {
200
- phase: t.phase,
201
- retryable: t.retryable,
202
- oauthError: typeof t.oauthError == "string" ? t.oauthError : void 0,
203
- oauthErrorDescription: typeof t.oauthErrorDescription == "string" ? t.oauthErrorDescription : void 0,
204
- status: typeof t.status == "number" ? t.status : void 0
205
- });
206
- return typeof t.name == "string" && t.name && (n.name = t.name), n;
207
220
  }, b = (function() {
208
221
  let e = typeof window > "u" ? global : window;
209
222
  return {
@@ -212,87 +225,89 @@ var e = {
212
225
  setInterval: setInterval.bind(e),
213
226
  clearInterval: clearInterval.bind(e)
214
227
  };
215
- })(), x = (t, n, r, i = "login") => (a = null, o = null, s = null) => {
228
+ })(), x = (t, n, i, a = "login") => (o = null, c = null, l = null) => {
216
229
  if (!n.silent_redirect_uri || !n.silent_login_uri) return Promise.resolve(null);
217
230
  try {
218
- r(e.silentLoginAsync_begin, {});
219
- let l = "";
220
- if (o && (a ??= {}, a.state = o), s != null && (a ??= {}, a.scope = s), a != null) for (let [e, t] of Object.entries(a)) t != null && (l === "" ? l = `?${encodeURIComponent(e)}=${encodeURIComponent(t)}` : l += `&${encodeURIComponent(e)}=${encodeURIComponent(t)}`);
221
- let u = n.silent_login_uri + l, f = u.indexOf("/", u.indexOf("//") + 2), p = u.substring(0, f), m = document.createElement("iframe");
222
- return m.width = "0px", m.height = "0px", m.id = `${t}_oidc_iframe`, m.setAttribute("src", u), m.style.display = "none", document.body.appendChild(m), new Promise((a, o) => {
223
- let s = !1, l = () => {
224
- window.removeEventListener("message", u), m.remove(), s = !0;
225
- }, u = (n) => {
226
- if (n.origin === p && n.source === m.contentWindow) {
227
- let c = `${t}_oidc_tokens:`, u = `${t}_oidc_error:`, d = `${t}_oidc_exception:`, f = n.data;
228
- if (f && typeof f == "string" && !s) {
229
- if (f.startsWith(c)) {
230
- let t = JSON.parse(n.data.replace(c, ""));
231
- r(e.silentLoginAsync_end, {}), a(t), l();
232
- } else if (f.startsWith(u)) {
233
- let t = JSON.parse(n.data.replace(u, "")), o = y(t.oidcError) ?? h(t.error, t.error_description, `Error from OIDC server: ${t.error} - ${t.error_description}`, i);
234
- r(e.silentLoginAsync_error, o), a({
231
+ i(f.silentLoginAsync_begin, {});
232
+ let u = "";
233
+ if (c && (o ??= {}, o.state = c), l != null && (o ??= {}, o.scope = l), o != null) for (let [e, t] of Object.entries(o)) t != null && (u === "" ? u = `?${encodeURIComponent(e)}=${encodeURIComponent(t)}` : u += `&${encodeURIComponent(e)}=${encodeURIComponent(t)}`);
234
+ let p = n.silent_login_uri + u, m = p.indexOf("/", p.indexOf("//") + 2), h = p.substring(0, m), g = document.createElement("iframe");
235
+ return g.width = "0px", g.height = "0px", g.id = `${t}_oidc_iframe`, g.setAttribute("src", p), g.style.display = "none", document.body.appendChild(g), new Promise((o, c) => {
236
+ let l = !1, u = () => {
237
+ window.removeEventListener("message", p), g.remove(), l = !0;
238
+ }, p = (e) => {
239
+ if (e.origin === h && e.source === g.contentWindow) {
240
+ let n = `${t}_oidc_tokens:`, r = `${t}_oidc_error:`, p = `${t}_oidc_exception:`, m = e.data;
241
+ if (m && typeof m == "string" && !l) {
242
+ if (m.startsWith(n)) {
243
+ let t = JSON.parse(e.data.replace(n, ""));
244
+ i(f.silentLoginAsync_end, {}), o(t), u();
245
+ } else if (m.startsWith(r)) {
246
+ let t = JSON.parse(e.data.replace(r, "")), n = d(t.oidcError) ?? s(t.error, t.error_description, `Error from OIDC server: ${t.error} - ${t.error_description}`, a);
247
+ i(f.silentLoginAsync_error, n), o({
235
248
  error: "oidc_" + t.error,
236
249
  tokens: null,
237
250
  sessionState: null,
238
- oidcError: o
239
- }), l();
240
- } else if (f.startsWith(d)) {
241
- let t = JSON.parse(n.data.replace(d, "")), i = y(t.oidcError) ?? Error(t.error);
242
- r(e.silentLoginAsync_error, i), o(i), l();
251
+ oidcError: n
252
+ }), u();
253
+ } else if (m.startsWith(p)) {
254
+ let t = JSON.parse(e.data.replace(p, "")), n = d(t.oidcError) ?? Error(t.error);
255
+ i(f.silentLoginAsync_error, n), c(n), u();
243
256
  }
244
257
  }
245
258
  }
246
259
  };
247
260
  try {
248
- window.addEventListener("message", u);
261
+ window.addEventListener("message", p);
249
262
  let t = n.silent_login_timeout;
250
263
  setTimeout(() => {
251
- if (!s) {
252
- l();
253
- let t = new d(c.SILENT_LOGIN_TIMEOUT, "timeout", {
254
- phase: i,
264
+ if (!l) {
265
+ u();
266
+ let t = new r(e.SILENT_LOGIN_TIMEOUT, "timeout", {
267
+ phase: a,
255
268
  retryable: !0
256
269
  });
257
- r(e.silentLoginAsync_error, t), o(t);
270
+ i(f.silentLoginAsync_error, t), c(t);
258
271
  }
259
272
  }, t);
260
- } catch (t) {
261
- l(), r(e.silentLoginAsync_error, t), o(t);
273
+ } catch (e) {
274
+ u(), i(f.silentLoginAsync_error, e), c(e);
262
275
  }
263
276
  });
264
- } catch (t) {
265
- throw r(e.silentLoginAsync_error, t), t;
277
+ } catch (e) {
278
+ throw i(f.silentLoginAsync_error, e), e;
266
279
  }
267
- }, S = (t, n, r, i, a) => (t = null, o = void 0) => {
280
+ }, S = (t, n, i, a, o) => (t = null, s = void 0) => {
268
281
  t = { ...t };
269
- let s = (e, t, o) => x(n, r, i.bind(a))(e, t, o);
282
+ let c = (e, t, r) => x(n, i, a.bind(o))(e, t, r);
270
283
  return (async () => {
271
- a.timeoutId && b.clearTimeout(a.timeoutId);
272
284
  let n;
273
285
  t && "state" in t && (n = t.state, delete t.state);
274
- try {
275
- let c = r.extras ? {
276
- ...r.extras,
277
- ...t
278
- } : t, l = await s({
279
- ...c,
280
- prompt: "none"
281
- }, n, o);
282
- if (l) return a.tokens = l.tokens, i(e.token_acquired, {}), a.timeoutId = W(a, a.tokens.expiresAt, t, o), {};
283
- } catch (e) {
284
- return e;
286
+ let l = i.extras ? {
287
+ ...i.extras,
288
+ ...t
289
+ } : t, u = await c({
290
+ ...l,
291
+ prompt: "none"
292
+ }, n, s);
293
+ if (u) {
294
+ if (u.oidcError) throw u.oidcError;
295
+ if (!u.tokens) throw new r(e.TOKEN_REQUEST_FAILED, "Silent login returned no tokens.", {
296
+ phase: "login",
297
+ retryable: !1
298
+ });
299
+ return o.timeoutId && b.clearTimeout(o.timeoutId), o.tokens = u.tokens, a(f.token_acquired, {}), o.timeoutId = q(o, o.tokens.expiresAt, t, s), {};
285
300
  }
286
- })();
301
+ })().catch((e) => e);
287
302
  }, C = (e, t, n) => (r, i, a, o = !1) => {
288
- let c = (t, r = void 0, i = void 0) => x(e.configurationName, n, e.publishEvent.bind(e))(t, r, i);
289
- return new Promise((l, u) => {
290
- n.silent_login_uri && n.silent_redirect_uri && n.monitor_session && r && a && !o ? (e.checkSessionIFrame = new s(() => {
303
+ let s = (t, r = void 0, i = void 0) => x(e.configurationName, n, e.publishEvent.bind(e))(t, r, i);
304
+ return new Promise((c, l) => {
305
+ n.silent_login_uri && n.silent_redirect_uri && n.monitor_session && r && a && !o ? (e.checkSessionIFrame = new y(() => {
291
306
  e.checkSessionIFrame.stop();
292
307
  let r = e.tokens;
293
308
  if (r === null) return;
294
309
  let i = r.idToken, a = r.idTokenPayload;
295
- return c({
310
+ return s({
296
311
  prompt: "none",
297
312
  id_token_hint: i,
298
313
  scope: n.scope || "openid"
@@ -308,10 +323,10 @@ var e = {
308
323
  for (let [, e] of Object.entries(t)) await e.logoutOtherTabAsync(n.client_id, a.sub);
309
324
  });
310
325
  }, i, r), e.checkSessionIFrame.load().then(() => {
311
- e.checkSessionIFrame.start(a), l(e.checkSessionIFrame);
326
+ e.checkSessionIFrame.start(a), c(e.checkSessionIFrame);
312
327
  }).catch((e) => {
313
- u(e);
314
- })) : l(null);
328
+ l(e);
329
+ })) : c(null);
315
330
  });
316
331
  };
317
332
  //#endregion
@@ -333,10 +348,10 @@ var D = (e) => {
333
348
  t += String.fromCharCode(e);
334
349
  }), T(t);
335
350
  };
336
- function O(e) {
351
+ function ee(e) {
337
352
  return T(E(e));
338
353
  }
339
- var k = {
354
+ var O = {
340
355
  importKeyAlgorithm: {
341
356
  name: "ECDSA",
342
357
  namedCurve: "P-256",
@@ -352,7 +367,7 @@ var k = {
352
367
  },
353
368
  digestAlgorithm: { name: "SHA-256" },
354
369
  jwtHeaderAlgorithm: "ES256"
355
- }, ee = { sign: (e) => async (t, n, r, i, a = "dpop+jwt") => {
370
+ }, k = { sign: (e) => async (t, n, r, i, a = "dpop+jwt") => {
356
371
  switch (t = Object.assign({}, t), n.typ = a, n.alg = i.jwtHeaderAlgorithm, n.alg) {
357
372
  case "ES256":
358
373
  n.jwk = {
@@ -373,11 +388,11 @@ var k = {
373
388
  default: throw Error("Unknown or not implemented JWS algorithm");
374
389
  }
375
390
  let o = {
376
- protected: O(JSON.stringify(n)),
377
- payload: O(JSON.stringify(r))
391
+ protected: ee(JSON.stringify(n)),
392
+ payload: ee(JSON.stringify(r))
378
393
  }, s = i.importKeyAlgorithm, c = await e.crypto.subtle.importKey("jwk", t, s, !0, ["sign"]), l = w(`${o.protected}.${o.payload}`), u = i.signAlgorithm, d = await e.crypto.subtle.sign(u, c, l);
379
394
  return o.signature = D(new Uint8Array(d)), `${o.protected}.${o.payload}.${o.signature}`;
380
- } }, te = {
395
+ } }, A = {
381
396
  generate: (e) => async (t) => {
382
397
  let n = t, r = await e.crypto.subtle.generateKey(n, !0, ["sign", "verify"]);
383
398
  return await e.crypto.subtle.exportKey("jwk", r.privateKey);
@@ -386,7 +401,7 @@ var k = {
386
401
  let t = Object.assign({}, e);
387
402
  return delete t.d, t.key_ops = ["verify"], t;
388
403
  }
389
- }, ne = { thumbprint: (e) => async (t, n) => {
404
+ }, j = { thumbprint: (e) => async (t, n) => {
390
405
  let r;
391
406
  switch (t.kty) {
392
407
  case "EC":
@@ -399,48 +414,50 @@ var k = {
399
414
  }
400
415
  let i = await e.crypto.subtle.digest(n, w(r));
401
416
  return D(new Uint8Array(i));
402
- } }, re = (e) => async (t) => await te.generate(e)(t), ie = (e) => (t) => async (n, r = "POST", i, a = {}) => {
403
- let o = {
417
+ } }, te = (e) => async (t) => await A.generate(e)(t), ne = (e) => (t) => async (n, r = "POST", i, a = {}) => {
418
+ let o = new URL(i, e.location?.href);
419
+ o.search = "", o.hash = "";
420
+ let s = {
404
421
  jti: btoa(e.crypto.randomUUID()),
405
422
  htm: r,
406
- htu: i,
423
+ htu: o.href,
407
424
  iat: Math.round(Date.now() / 1e3),
408
425
  ...a
409
- }, s = await ne.thumbprint(e)(n, t.digestAlgorithm);
410
- return await ee.sign(e)(n, { kid: s }, o, t);
411
- }, ae = () => typeof globalThis < "u" ? globalThis.crypto : void 0, oe = () => {
412
- let e = ae();
426
+ }, c = await j.thumbprint(e)(n, t.digestAlgorithm);
427
+ return await k.sign(e)(n, { kid: c }, s, t);
428
+ }, re = () => typeof globalThis < "u" ? globalThis.crypto : void 0, ie = () => {
429
+ let e = re();
413
430
  return {
414
431
  hasCrypto: !!e,
415
432
  hasSubtleCrypto: !!e?.subtle
416
433
  };
417
- }, se = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", ce = (e) => {
434
+ }, ae = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", oe = (e) => {
418
435
  let t = [];
419
436
  for (let n = 0; n < e.byteLength; n += 1) {
420
437
  let r = e[n] % 62;
421
- t.push(se[r]);
438
+ t.push(ae[r]);
422
439
  }
423
440
  return t.join("");
424
- }, A = (e) => {
425
- let t = new Uint8Array(e), n = ae();
441
+ }, se = (e) => {
442
+ let t = new Uint8Array(e), n = re();
426
443
  if (!n?.getRandomValues) throw Error("Web Crypto API is unavailable; secure random values cannot be generated.");
427
- return n.getRandomValues(t), ce(t);
444
+ return n.getRandomValues(t), oe(t);
428
445
  };
429
- function le(e) {
446
+ function ce(e) {
430
447
  let t = new ArrayBuffer(e.length), n = new Uint8Array(t);
431
448
  for (let t = 0; t < e.length; t++) n[t] = e.charCodeAt(t);
432
449
  return n;
433
450
  }
434
- function ue(e) {
451
+ function le(e) {
435
452
  return new Promise((t, n) => {
436
- crypto.subtle.digest("SHA-256", le(e)).then((e) => t(D(new Uint8Array(e))), (e) => n(e));
453
+ crypto.subtle.digest("SHA-256", ce(e)).then((e) => t(D(new Uint8Array(e))), (e) => n(e));
437
454
  });
438
455
  }
439
- var de = (e) => {
456
+ var ue = (e) => {
440
457
  if (e.length < 43 || e.length > 128) return Promise.reject(/* @__PURE__ */ Error("Invalid code length."));
441
- let { hasSubtleCrypto: t } = oe();
442
- return t ? ue(e) : Promise.reject(/* @__PURE__ */ Error("window.crypto.subtle is unavailable."));
443
- }, fe = (e) => !!(e.os === "iOS" && e.osVersion.startsWith("12") || e.os === "Mac OS X" && e.osVersion.startsWith("10_15_6")), pe = (e) => {
458
+ let { hasSubtleCrypto: t } = ie();
459
+ return t ? le(e) : Promise.reject(/* @__PURE__ */ Error("window.crypto.subtle is unavailable."));
460
+ }, de = (e) => !!(e.os === "iOS" && e.osVersion.startsWith("12") || e.os === "Mac OS X" && e.osVersion.startsWith("10_15_6")), fe = (e) => {
444
461
  let t = e.appVersion, n = e.userAgent, r = "-", i = [
445
462
  {
446
463
  s: "Windows 10",
@@ -576,7 +593,7 @@ var de = (e) => {
576
593
  osVersion: a
577
594
  };
578
595
  };
579
- function me() {
596
+ function pe() {
580
597
  let e = navigator.userAgent, t, n = e.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
581
598
  if (/trident/i.test(n[1])) return t = /\brv[ :]+(\d+)/g.exec(e) || [], {
582
599
  name: "ie",
@@ -602,53 +619,53 @@ function me() {
602
619
  version: n[1]
603
620
  };
604
621
  }
605
- var he = () => {
606
- let { name: e, version: t } = me();
607
- return e === "chrome" && parseInt(t) <= 70 || e === "opera" && (!t || parseInt(t.split(".")[0]) < 80) || e === "ie" ? !1 : !fe(pe(navigator));
608
- }, ge = async (t) => {
609
- let n;
610
- if (t.tokens != null) return !1;
611
- t.publishEvent(e.tryKeepExistingSessionAsync_begin, {});
622
+ var me = () => {
623
+ let { name: e, version: t } = pe();
624
+ return e === "chrome" && parseInt(t) <= 70 || e === "opera" && (!t || parseInt(t.split(".")[0]) < 80) || e === "ie" ? !1 : !de(fe(navigator));
625
+ }, he = async (e) => {
626
+ let t;
627
+ if (e.tokens != null) return !1;
628
+ e.publishEvent(f.tryKeepExistingSessionAsync_begin, {});
612
629
  try {
613
- let r = t.configuration, a = await t.initAsync(r.authority, r.authority_configuration);
614
- if (n = await $(r, t.configurationName), n) {
615
- let { tokens: i } = await n.initAsync(a, "tryKeepExistingSessionAsync", r);
630
+ let n = e.configuration, r = await e.initAsync(n.authority, n.authority_configuration);
631
+ if (t = await $(n, e.configurationName), t) {
632
+ let { tokens: i } = await t.initAsync(r, "tryKeepExistingSessionAsync", n);
616
633
  if (i) {
617
- n.startKeepAliveServiceWorker(), t.tokens = i;
618
- let o = n.getLoginParams(t.configurationName);
619
- t.timeoutId = W(t, t.tokens.expiresAt, o.extras, o.scope);
620
- let s = await n.getSessionStateAsync();
621
- return await t.startCheckSessionAsync(a.checkSessionIframe, r.client_id, s), r.preload_user_info && await t.userInfoAsync(), t.publishEvent(e.tryKeepExistingSessionAsync_end, {
634
+ t.startKeepAliveServiceWorker(), e.tokens = i;
635
+ let a = t.getLoginParams(e.configurationName);
636
+ e.timeoutId = q(e, e.tokens.expiresAt, a.extras, a.scope);
637
+ let o = await t.getSessionStateAsync();
638
+ return await e.startCheckSessionAsync(r.checkSessionIframe, n.client_id, o), n.preload_user_info && await e.userInfoAsync(), e.publishEvent(f.tryKeepExistingSessionAsync_end, {
622
639
  success: !0,
623
640
  message: "tokens inside ServiceWorker are valid"
624
641
  }), !0;
625
642
  }
626
- t.publishEvent(e.tryKeepExistingSessionAsync_end, {
643
+ e.publishEvent(f.tryKeepExistingSessionAsync_end, {
627
644
  success: !1,
628
645
  message: "no exiting session found"
629
646
  });
630
647
  } else {
631
- r.service_worker_relative_url && t.publishEvent(e.service_worker_not_supported_by_browser, { message: "service worker is not supported by this browser" });
632
- let n = i(t.configurationName, r.storage ?? sessionStorage, r.login_state_storage ?? r.storage ?? sessionStorage), { tokens: o } = await n.initAsync();
633
- if (o) {
634
- t.tokens = at(o, null, r.token_renew_mode);
635
- let i = n.getLoginParams();
636
- t.timeoutId = W(t, t.tokens.expiresAt, i.extras, i.scope);
637
- let s = await n.getSessionStateAsync();
638
- return await t.startCheckSessionAsync(a.checkSessionIframe, r.client_id, s), r.preload_user_info && await t.userInfoAsync(), t.publishEvent(e.tryKeepExistingSessionAsync_end, {
648
+ n.service_worker_relative_url && e.publishEvent(f.service_worker_not_supported_by_browser, { message: "service worker is not supported by this browser" });
649
+ let t = g(e.configurationName, n.storage ?? sessionStorage, n.login_state_storage ?? n.storage ?? sessionStorage), { tokens: i } = await t.initAsync();
650
+ if (i) {
651
+ e.tokens = Mt(i, null, n.token_renew_mode);
652
+ let a = t.getLoginParams();
653
+ e.timeoutId = q(e, e.tokens.expiresAt, a.extras, a.scope);
654
+ let o = await t.getSessionStateAsync();
655
+ return await e.startCheckSessionAsync(r.checkSessionIframe, n.client_id, o), n.preload_user_info && await e.userInfoAsync(), e.publishEvent(f.tryKeepExistingSessionAsync_end, {
639
656
  success: !0,
640
657
  message: "tokens inside storage are valid"
641
658
  }), !0;
642
659
  }
643
660
  }
644
- return t.publishEvent(e.tryKeepExistingSessionAsync_end, {
661
+ return e.publishEvent(f.tryKeepExistingSessionAsync_end, {
645
662
  success: !1,
646
- message: n ? "service worker sessions not retrieved" : "session storage sessions not retrieved"
663
+ message: t ? "service worker sessions not retrieved" : "session storage sessions not retrieved"
647
664
  }), !1;
648
- } catch (r) {
649
- return console.error(r), n && await n.clearAsync(), t.publishEvent(e.tryKeepExistingSessionAsync_error, "tokens inside ServiceWorker are invalid"), !1;
665
+ } catch (n) {
666
+ return console.error(n), t && await t.clearAsync(), e.publishEvent(f.tryKeepExistingSessionAsync_error, "tokens inside ServiceWorker are invalid"), !1;
650
667
  }
651
- }, j = class {
668
+ }, M = class {
652
669
  open(e) {
653
670
  window.location.href = e;
654
671
  }
@@ -665,52 +682,52 @@ var he = () => {
665
682
  getOrigin() {
666
683
  return window.origin;
667
684
  }
668
- }, M = {
685
+ }, N = {
669
686
  STATE_MISSING: "STATE_MISSING",
670
687
  STATE_MISMATCH: "STATE_MISMATCH",
671
688
  NONCE_MISSING: "NONCE_MISSING"
672
- }, _e = new Set(Object.values(M)), ve = (e) => typeof e == "string" && _e.has(e), N = class e extends d {
689
+ }, ge = new Set(Object.values(N)), _e = (e) => typeof e == "string" && ge.has(e), P = class e extends r {
673
690
  constructor(t, n, r = "callback") {
674
691
  super(t, n, {
675
692
  phase: r,
676
693
  retryable: !1
677
694
  }), this.name = "OidcStateError", Object.setPrototypeOf(this, e.prototype);
678
695
  }
679
- }, ye = (e) => e instanceof N || f(e) && ve(e.code), P = {
696
+ }, ve = (e) => e instanceof P || i(e) && _e(e.code), F = {
680
697
  ENDPOINT_UNAVAILABLE: "ENDPOINT_UNAVAILABLE",
681
698
  REQUEST_FAILED: "REQUEST_FAILED",
682
699
  INVALID_RESPONSE: "INVALID_RESPONSE"
683
- }, F = class e extends d {
700
+ }, I = class e extends r {
684
701
  constructor(t, n, r = {}) {
685
702
  super(t, n, {
686
703
  phase: "login",
687
- retryable: r.cause !== void 0 || p(r.status),
704
+ retryable: r.cause !== void 0 || a(r.status),
688
705
  status: r.status,
689
706
  oauthError: r.oauthError,
690
707
  oauthErrorDescription: r.oauthErrorDescription,
691
708
  cause: r.cause
692
709
  }), this.name = "PushedAuthorizationRequestError", Object.setPrototypeOf(this, e.prototype);
693
710
  }
694
- }, be = (e) => e instanceof F, I = {}, xe = (e, t = window.sessionStorage, n) => {
695
- if (!I[e] && t) {
711
+ }, ye = (e) => e instanceof I, be = {}, xe = (e, t = window.sessionStorage, n) => {
712
+ if (!be[e] && t) {
696
713
  let n = t.getItem(e);
697
- n && (I[e] = JSON.parse(n));
714
+ n && (be[e] = JSON.parse(n));
698
715
  }
699
- let r = I[e], i = 1e3 * n;
716
+ let r = be[e], i = 1e3 * n;
700
717
  return r && r.timestamp + i > Date.now() ? r.result : null;
701
718
  }, Se = (e, t, n = window.sessionStorage) => {
702
719
  let r = {
703
720
  result: t,
704
721
  timestamp: Date.now()
705
722
  };
706
- I[e] = r, n && n.setItem(e, JSON.stringify(r));
723
+ be[e] = r, n && n.setItem(e, JSON.stringify(r));
707
724
  }, Ce = 3600, we = (e) => async (t, n = Ce, r = window.sessionStorage, i = 1e4) => {
708
725
  let a = `${t}/.well-known/openid-configuration`, o = `oidc.server:${t}`, s = xe(o, r, n);
709
- if (s) return new Je(s);
726
+ if (s) return new yt(s);
710
727
  let c = await L(e)(a, {}, i);
711
728
  if (c.status !== 200) return null;
712
729
  let l = await c.json();
713
- return Se(o, l, r), new Je(l);
730
+ return Se(o, l, r), new yt(l);
714
731
  }, L = (e) => async (t, n = {}, r = 1e4, i = 0) => {
715
732
  let a;
716
733
  try {
@@ -731,27 +748,30 @@ var he = () => {
731
748
  throw console.error(a.message), a;
732
749
  }
733
750
  return a;
734
- }, Te = {
751
+ }, R = {
735
752
  refresh_token: "refresh_token",
736
753
  access_token: "access_token"
737
- }, Ee = (e) => {
754
+ }, Te = (e) => {
738
755
  let t = [];
739
- for (let n in e) t.push(`${encodeURIComponent(n)}=${encodeURIComponent(e[n])}`);
756
+ for (let n in e) {
757
+ let r = e[n], i = Array.isArray(r) ? r : [String(r)];
758
+ for (let e of i) t.push(`${encodeURIComponent(n)}=${encodeURIComponent(e)}`);
759
+ }
740
760
  return t.join("&");
741
- }, De = (e) => async (t, n, r = Te.refresh_token, i, a = {}, o = 1e4) => {
761
+ }, Ee = (e) => async (t, n, r = R.refresh_token, i, a = {}, o = 1e4) => {
742
762
  let s = {
743
763
  token: n,
744
764
  token_type_hint: r,
745
765
  client_id: i
746
766
  };
747
767
  for (let [e, t] of Object.entries(a)) s[e] === void 0 && (s[e] = t);
748
- let c = Ee(s), l = await L(e)(t, {
768
+ let c = Te(s), l = await L(e)(t, {
749
769
  method: "POST",
750
770
  headers: { "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8" },
751
771
  body: c
752
772
  }, o);
753
773
  if (l.status !== 200) {
754
- let e = await Oe(l);
774
+ let e = await De(l);
755
775
  return {
756
776
  success: !1,
757
777
  status: l.status,
@@ -763,15 +783,15 @@ var he = () => {
763
783
  success: !0,
764
784
  status: l.status
765
785
  };
766
- }, Oe = async (e) => {
786
+ }, De = async (e) => {
767
787
  try {
768
788
  return await e.json();
769
789
  } catch {
770
790
  return null;
771
791
  }
772
- }, ke = (e) => async (t, n, r = 1e4) => {
773
- if (n.request_uri !== void 0) throw new F(P.REQUEST_FAILED, "The request_uri parameter must not be included in a pushed authorization request.");
774
- let i = Ee(n), a;
792
+ }, Oe = (e) => async (t, n, r = 1e4) => {
793
+ if (n.request_uri !== void 0) throw new I(F.REQUEST_FAILED, "The request_uri parameter must not be included in a pushed authorization request.");
794
+ let i = Te(n), a;
775
795
  try {
776
796
  a = await L(e)(t, {
777
797
  method: "POST",
@@ -779,25 +799,25 @@ var he = () => {
779
799
  body: i
780
800
  }, r);
781
801
  } catch (e) {
782
- throw new F(P.REQUEST_FAILED, "The pushed authorization request could not be sent.", { cause: e });
802
+ throw new I(F.REQUEST_FAILED, "The pushed authorization request could not be sent.", { cause: e });
783
803
  }
784
- let o = await Oe(a);
804
+ let o = await De(a);
785
805
  if (a.status !== 201) {
786
806
  let e = typeof o?.error == "string" ? o.error : void 0, t = typeof o?.error_description == "string" ? o.error_description : void 0, n = [e, t].filter(Boolean).join(": ");
787
- throw new F(P.REQUEST_FAILED, `The pushed authorization request failed with HTTP status ${a.status}${n ? ` (${n})` : ""}.`, {
807
+ throw new I(F.REQUEST_FAILED, `The pushed authorization request failed with HTTP status ${a.status}${n ? ` (${n})` : ""}.`, {
788
808
  status: a.status,
789
809
  oauthError: e,
790
810
  oauthErrorDescription: t
791
811
  });
792
812
  }
793
- if (typeof o?.request_uri != "string" || o.request_uri.length === 0 || !Number.isInteger(o?.expires_in) || o.expires_in <= 0) throw new F(P.INVALID_RESPONSE, "The pushed authorization response must contain a non-empty request_uri and a positive integer expires_in.", { status: a.status });
813
+ if (typeof o?.request_uri != "string" || o.request_uri.length === 0 || !Number.isInteger(o?.expires_in) || o.expires_in <= 0) throw new I(F.INVALID_RESPONSE, "The pushed authorization response must contain a non-empty request_uri and a positive integer expires_in.", { status: a.status });
794
814
  return {
795
815
  request_uri: o.request_uri,
796
816
  expires_in: o.expires_in
797
817
  };
798
- }, Ae = (e) => async (t, n, r, i, a = {}, o, s = 1e4) => {
818
+ }, ke = (e) => async (t, n, r, i, a = {}, o, s = 1e4) => {
799
819
  for (let [e, t] of Object.entries(r)) n[e] === void 0 && (n[e] = t);
800
- let c = Ee(n), l = await L(e)(t, {
820
+ let c = Te(n), l = await L(e)(t, {
801
821
  method: "POST",
802
822
  headers: {
803
823
  "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
@@ -806,37 +826,37 @@ var he = () => {
806
826
  body: c
807
827
  }, s);
808
828
  if (l.status !== 200) {
809
- let e = await Oe(l);
829
+ let e = await De(l);
810
830
  return {
811
831
  success: !1,
812
832
  status: l.status,
813
833
  data: e,
814
834
  oauthError: typeof e?.error == "string" ? e.error : void 0,
815
835
  oauthErrorDescription: typeof e?.error_description == "string" ? e.error_description : void 0,
816
- demonstratingProofOfPossessionNonce: l.headers?.has(R) ? l.headers.get(R) : null
836
+ demonstratingProofOfPossessionNonce: l.headers?.has(z) ? l.headers.get(z) : null
817
837
  };
818
838
  }
819
839
  let u = await l.json(), d = null;
820
- return l.headers.has(R) && (d = l.headers.get(R)), {
840
+ return l.headers.has(z) && (d = l.headers.get(z)), {
821
841
  success: !0,
822
842
  status: l.status,
823
- data: ot(u, i, o),
843
+ data: Nt(u, i, o),
824
844
  demonstratingProofOfPossessionNonce: d
825
845
  };
826
- }, je = (e, t) => async (n, r, i) => {
846
+ }, Ae = (e, t) => async (n, r, i) => {
827
847
  r = r ? { ...r } : {};
828
- let a = A(128), o = await de(a);
848
+ let a = se(128), o = await ue(a);
829
849
  if (await e.setCodeVerifierAsync(a), await e.setStateAsync(r.state), r.code_challenge = o, r.code_challenge_method = "S256", i) {
830
- let e = await ke(i.fetch)(i.endpoint, r, i.timeoutMs);
831
- t.open(`${n}?client_id=${encodeURIComponent(r.client_id)}&request_uri=${encodeURIComponent(e.request_uri)}`);
850
+ let e = await Oe(i.fetch)(i.endpoint, r, i.timeoutMs);
851
+ t.open(`${n}?client_id=${encodeURIComponent(String(r.client_id))}&request_uri=${encodeURIComponent(e.request_uri)}`);
832
852
  return;
833
853
  }
834
854
  let s = "";
835
- if (r) for (let [e, t] of Object.entries(r)) s += s === "" ? "?" : "&", s += `${e}=${encodeURIComponent(t)}`;
855
+ if (r) for (let [e, t] of Object.entries(r)) for (let n of Array.isArray(t) ? t : [String(t)]) s += s === "" ? "?" : "&", s += `${e}=${encodeURIComponent(n)}`;
836
856
  t.open(`${n}${s}`);
837
- }, R = "DPoP-Nonce", Me = (e) => async (t, n, r, i, a = 1e4, o = !1) => {
857
+ }, z = "DPoP-Nonce", je = (e) => async (t, n, r, i, a = 1e4, o = !1) => {
838
858
  n = n ? { ...n } : {}, n.code_verifier = await e.getCodeVerifierAsync();
839
- let s = Ee(n), c = await L(fetch)(t, {
859
+ let s = Te(n), c = await L(fetch)(t, {
840
860
  method: "POST",
841
861
  headers: {
842
862
  "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
@@ -845,29 +865,87 @@ var he = () => {
845
865
  body: s
846
866
  }, a);
847
867
  if (c.status !== 200) {
848
- let t = await Oe(c), n = typeof t?.error == "string" ? t.error : void 0;
868
+ let t = await De(c), n = typeof t?.error == "string" ? t.error : void 0;
849
869
  return o && n === "use_dpop_nonce" || await Promise.all([e.setCodeVerifierAsync(null), e.setStateAsync(null)]), {
850
870
  success: !1,
851
871
  status: c.status,
852
872
  data: t,
853
873
  oauthError: n,
854
874
  oauthErrorDescription: typeof t?.error_description == "string" ? t.error_description : void 0,
855
- demonstratingProofOfPossessionNonce: c.headers?.has(R) ? c.headers.get(R) : null
875
+ demonstratingProofOfPossessionNonce: c.headers?.has(z) ? c.headers.get(z) : null
856
876
  };
857
877
  }
858
878
  await Promise.all([e.setCodeVerifierAsync(null), e.setStateAsync(null)]);
859
879
  let l = null;
860
- c.headers.has(R) && (l = c.headers.get(R));
880
+ c.headers.has(z) && (l = c.headers.get(z));
861
881
  let u = await c.json();
862
882
  return {
863
883
  success: !0,
864
884
  data: {
865
885
  state: n.state,
866
- tokens: ot(u, null, i),
886
+ tokens: Nt(u, null, i),
867
887
  demonstratingProofOfPossessionNonce: l
868
888
  }
869
889
  };
870
- }, Ne = (e) => {
890
+ }, Me = "x-oidc-resource", Ne = (e, t) => `${e}#resource=${encodeURIComponent(t)}`, Pe = (e) => {
891
+ let t = e.indexOf("#resource=");
892
+ return t < 0 ? void 0 : decodeURIComponent(e.slice(t + 10));
893
+ }, Fe = (e) => {
894
+ if (typeof e != "string" || !/^[a-z][a-z\d+.-]*:/i.test(e) || e.includes("#") || /\s/.test(e)) throw Error("A resource must be an absolute URI without whitespace or a fragment.");
895
+ new URL(e);
896
+ }, Ie = (e) => {
897
+ let t = new URL(e);
898
+ if (t.protocol !== "https:" && t.protocol !== "http:" || t.username || t.password || t.hash || /%2f|%5c/i.test(t.pathname)) throw Error("API destinations must be HTTP(S) URLs without credentials, fragments, or encoded separators.");
899
+ return t;
900
+ }, Le = (e) => {
901
+ let t = Ie(e);
902
+ if (t.search) throw Error("An API URL prefix must not contain a query.");
903
+ return t;
904
+ }, Re = (e, t) => {
905
+ let n = Ie(t).origin;
906
+ return e?.some((e) => e.allowedUrlPrefixes.some((e) => Le(e).origin === n)) ?? !1;
907
+ }, ze = (e, t) => {
908
+ let n = Ie(t);
909
+ return e.allowedUrlPrefixes.some((e) => {
910
+ let t = Le(e), r = t.pathname.replace(/\/+$/, "");
911
+ return n.origin === t.origin && (r === "" || n.pathname === r || n.pathname.startsWith(`${r}/`));
912
+ });
913
+ }, B = (e, t) => {
914
+ Fe(t);
915
+ let n = e?.filter((e) => e.resource === t) ?? [];
916
+ if (n.length !== 1 || n[0].allowedUrlPrefixes.length === 0) throw Error("The resource must be registered exactly once with permitted API URL prefixes.");
917
+ for (let e of n[0].allowedUrlPrefixes) ze(n[0], e);
918
+ return n[0];
919
+ }, Be = "1.1.0", Ve = {
920
+ SKIP_WAITING: "SKIP_WAITING",
921
+ CLAIM: "claim",
922
+ CLEAR: "clear",
923
+ INIT: "init",
924
+ SET_STATE: "setState",
925
+ GET_STATE: "getState",
926
+ SET_CODE_VERIFIER: "setCodeVerifier",
927
+ GET_CODE_VERIFIER: "getCodeVerifier",
928
+ SET_SESSION_STATE: "setSessionState",
929
+ GET_SESSION_STATE: "getSessionState",
930
+ SET_NONCE: "setNonce",
931
+ GET_NONCE: "getNonce",
932
+ SET_DPOP_NONCE: "setDemonstratingProofOfPossessionNonce",
933
+ GET_DPOP_NONCE: "getDemonstratingProofOfPossessionNonce",
934
+ SET_DPOP_JWK: "setDemonstratingProofOfPossessionJwk",
935
+ GET_DPOP_JWK: "getDemonstratingProofOfPossessionJwk"
936
+ }, He = {
937
+ ACCESS_TOKEN: "ACCESS_TOKEN_SECURED_BY_OIDC_SERVICE_WORKER",
938
+ REFRESH_TOKEN: "REFRESH_TOKEN_SECURED_BY_OIDC_SERVICE_WORKER",
939
+ NONCE_TOKEN: "NONCE_SECURED_BY_OIDC_SERVICE_WORKER",
940
+ CODE_VERIFIER: "CODE_VERIFIER_SECURED_BY_OIDC_SERVICE_WORKER"
941
+ }, Ue = "DPOP_SECURED_BY_OIDC_SERVICE_WORKER", We = {
942
+ TAB_ID: "oidc.tabId.",
943
+ STATE: "oidc.state.",
944
+ NONCE: "oidc.nonce.",
945
+ CODE_VERIFIER: "oidc.code_verifier.",
946
+ LOGIN_PARAMS: "oidc.login.",
947
+ SW_VERSION_MISMATCH_RELOAD: "oidc.sw.version_mismatch_reload."
948
+ }, Ge = "oidc.sw.controllerchange_reload_count", Ke = (e, t) => `${e}${t}`, qe = (e, t, n = "default") => `${e}_${t}#tabId=${n}`, Je = (e, t = "default") => `${Ue}_${e}#tabId=${t}`, Ye = (e) => typeof e == "string" && Object.values(Ve).includes(e), Xe = (e) => {
871
949
  let t = e.match(/^([a-z][\w-]+\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
872
950
  if (!t) throw Error("Invalid URL");
873
951
  let n = t[6], r = t[7];
@@ -885,147 +963,198 @@ var he = () => {
885
963
  search: n,
886
964
  hash: r
887
965
  };
888
- }, Pe = (e) => {
889
- let t = Ne(e), { path: n } = t;
966
+ }, Ze = (e) => {
967
+ let t = Xe(e), { path: n } = t;
890
968
  n.endsWith("/") && (n = n.slice(0, -1));
891
969
  let { hash: r } = t;
892
970
  return (r === "#" || r === "#_=_") && (r = ""), r && (n += r), n;
893
- }, z = (e) => {
894
- let { search: t } = Ne(e);
895
- return Fe(t);
896
- }, Fe = (e) => {
971
+ }, V = (e) => {
972
+ let { search: t } = Xe(e);
973
+ return Qe(t);
974
+ }, Qe = (e) => {
897
975
  let t = {};
898
976
  for (let n of e.split("&")) {
899
977
  let [e, r] = n.split("=");
900
978
  t[decodeURIComponent(e)] = decodeURIComponent(r);
901
979
  }
902
980
  return t;
903
- }, Ie = (t, n, r, a, o, s = () => window.fetch) => (c = void 0, l = null, u = !1, d = void 0) => {
904
- let f = l;
905
- return l = { ...l }, (async () => {
906
- let p = c || o.getPath();
907
- if ("state" in l || (l.state = A(16)), r(e.loginAsync_begin, {}), l) for (let e of Object.keys(l)) e.endsWith(":token_request") && delete l[e];
981
+ }, $e = "_oidc_resource", et = "oidc.resource_transaction.", H = (e, t) => t === void 0 ? e : Ne(e, t), tt = (t, n, i) => {
982
+ let a = i ?? n.resource;
983
+ if (a === void 0) return t;
984
+ let o = typeof a == "string" ? [a] : a;
985
+ if (o.length === 0) throw new r(e.INVALID_RESOURCE, "At least one resource is required.", {
986
+ phase: "login",
987
+ retryable: !1
988
+ });
989
+ for (let e of o) Fe(e), n.resources && B(n.resources, e);
990
+ let s = t.resource;
991
+ if (s !== void 0 && JSON.stringify(typeof s == "string" ? [s] : s) !== JSON.stringify(o)) throw new r(e.INVALID_RESOURCE, "Resource extras conflict with the selected resource.", {
992
+ phase: "login",
993
+ retryable: !1
994
+ });
995
+ return {
996
+ ...t,
997
+ resource: a
998
+ };
999
+ }, nt = (e, t, n) => {
1000
+ sessionStorage.setItem(`${et}${e}.${t}`, n);
1001
+ }, rt = (e, t) => {
1002
+ let { state: n } = V(t);
1003
+ return n ? sessionStorage.getItem(`${et}${e}.${n}`) ?? void 0 : void 0;
1004
+ }, it = (e, t) => {
1005
+ let { state: n } = V(t);
1006
+ n && sessionStorage.removeItem(`${et}${e}.${n}`);
1007
+ }, at = (e, t) => {
1008
+ let n = `${et}${e}.`;
1009
+ for (let e of Object.keys(sessionStorage)) e.startsWith(n) && (t === void 0 || sessionStorage.getItem(e) === t) && sessionStorage.removeItem(e);
1010
+ }, ot = (e, t, n, r, i, a = () => window.fetch) => (o = void 0, s = null, u = !1, d = void 0) => {
1011
+ let p = s;
1012
+ s = { ...s };
1013
+ let m = s[$e];
1014
+ delete s[$e];
1015
+ let h = H(e, m);
1016
+ return (async () => {
1017
+ let _ = o || i.getPath();
1018
+ if ("state" in s || (s.state = se(16)), m !== void 0 && nt(e, s.state, m), n(f.loginAsync_begin, {}), s) for (let e of Object.keys(s)) e.endsWith(":token_request") && delete s[e];
908
1019
  try {
909
- let e = u ? n.silent_redirect_uri : n.redirect_uri;
910
- d ||= n.scope;
911
- let r = n.extras ? {
912
- ...n.extras,
913
- ...l
914
- } : l;
915
- r.nonce ||= A(12);
916
- let c = { nonce: r.nonce }, m = await $(n, t), h = await a(n.authority, n.authority_configuration), g;
917
- if (m) m.setLoginParams({
918
- callbackPath: p,
919
- extras: f,
1020
+ let e = u ? t.silent_redirect_uri : t.redirect_uri;
1021
+ d ||= t.scope;
1022
+ let n = tt(t.extras ? {
1023
+ ...t.extras,
1024
+ ...s
1025
+ } : s, t, m);
1026
+ typeof n.scope == "string" && (d = n.scope), n.nonce ||= se(12);
1027
+ let o = { nonce: n.nonce }, c = await $(t, h), l = await r(t.authority, t.authority_configuration), f;
1028
+ if (c) c.setLoginParams({
1029
+ callbackPath: _,
1030
+ extras: p,
1031
+ scope: d,
1032
+ resource: m
1033
+ }), await c.initAsync(l, "loginAsync", {
1034
+ ...t,
920
1035
  scope: d
921
- }), await m.initAsync(h, "loginAsync", n), await m.setNonceAsync(c), m.startKeepAliveServiceWorker(), g = m;
1036
+ }), await c.setNonceAsync(o), c.startKeepAliveServiceWorker(), f = c;
922
1037
  else {
923
- let e = i(t, n.storage ?? sessionStorage, n.login_state_storage ?? n.storage ?? sessionStorage);
1038
+ let e = g(h, t.storage ?? sessionStorage, t.login_state_storage ?? t.storage ?? sessionStorage);
924
1039
  e.setLoginParams({
925
- callbackPath: p,
926
- extras: f,
927
- scope: d
928
- }), await e.setNonceAsync(c), g = e;
1040
+ callbackPath: _,
1041
+ extras: p,
1042
+ scope: d,
1043
+ resource: m
1044
+ }), await e.setNonceAsync(o), f = e;
929
1045
  }
930
- let _ = {
931
- client_id: n.client_id,
1046
+ let v = {
1047
+ client_id: t.client_id,
932
1048
  redirect_uri: e,
933
1049
  scope: d,
934
1050
  response_type: "code",
935
- ...r
936
- }, v = n.par ?? "disabled", y = h.pushedAuthorizationRequestEndpoint, b = h.requirePushedAuthorizationRequests;
937
- if (!y && (v === "required" || v === "auto" && b)) throw new F(P.ENDPOINT_UNAVAILABLE, "Pushed Authorization Requests are required, but the authorization server metadata does not provide a pushed_authorization_request_endpoint.");
938
- let x = v !== "disabled" && y ? {
939
- endpoint: y,
940
- fetch: s(),
941
- timeoutMs: n.par_request_timeout
1051
+ ...n
1052
+ }, y = t.par ?? "disabled", b = l.pushedAuthorizationRequestEndpoint, x = l.requirePushedAuthorizationRequests;
1053
+ if (!b && (y === "required" || y === "auto" && x)) throw new I(F.ENDPOINT_UNAVAILABLE, "Pushed Authorization Requests are required, but the authorization server metadata does not provide a pushed_authorization_request_endpoint.");
1054
+ let S = y !== "disabled" && b ? {
1055
+ endpoint: b,
1056
+ fetch: a(),
1057
+ timeoutMs: t.par_request_timeout
942
1058
  } : void 0;
943
- await je(g, o)(h.authorizationEndpoint, _, x);
944
- } catch (t) {
945
- let n = _(t) ? g(t, "login") : t;
946
- throw r(e.loginAsync_error, n), n;
1059
+ await Ae(f, i)(l.authorizationEndpoint, v, S);
1060
+ } catch (e) {
1061
+ let t = l(e) ? c(e, "login") : e;
1062
+ throw n(f.loginAsync_error, t), t;
947
1063
  }
948
1064
  })();
949
- }, Le = (t) => async (n = !1) => {
1065
+ }, st = (t) => async (n = !1, o) => {
950
1066
  try {
951
- t.publishEvent(e.loginCallbackAsync_begin, {});
952
- let r = t.configuration, a = r.client_id, o = n ? r.silent_redirect_uri : r.redirect_uri, s = r.authority, l = r.token_request_timeout, u = await t.initAsync(s, r.authority_configuration), f = z(t.location.getCurrentHref()), m = f.session_state, g = await $(r, t.configurationName), _, v, y, b;
953
- if (g) await g.initAsync(u, "loginCallbackAsync", r), await g.setSessionStateAsync(m), v = await g.getNonceAsync(), y = g.getLoginParams(), b = await g.getStateAsync(), g.startKeepAliveServiceWorker(), _ = g;
1067
+ t.publishEvent(f.loginCallbackAsync_begin, {});
1068
+ let i = t.configuration, c = H(t.configurationName, o), l = i.client_id, u = n ? i.silent_redirect_uri : i.redirect_uri, d = i.authority, p = i.token_request_timeout, m = await t.initAsync(d, i.authority_configuration), h = V(t.location.getCurrentHref()), _ = h.session_state, v = await $(i, c), y, b, x, S;
1069
+ if (v) await v.initAsync(m, "loginCallbackAsync", i), await v.setSessionStateAsync(_), b = await v.getNonceAsync(), x = v.getLoginParams(), S = await v.getStateAsync(), v.startKeepAliveServiceWorker(), y = v;
954
1070
  else {
955
- let e = i(t.configurationName, r.storage ?? sessionStorage, r.login_state_storage ?? r.storage ?? sessionStorage);
956
- await e.setSessionStateAsync(m), v = await e.getNonceAsync(), y = e.getLoginParams(), b = await e.getStateAsync(), _ = e;
1071
+ let e = g(c, i.storage ?? sessionStorage, i.login_state_storage ?? i.storage ?? sessionStorage);
1072
+ await e.setSessionStateAsync(_), b = await e.getNonceAsync(), x = e.getLoginParams(), S = await e.getStateAsync(), y = e;
957
1073
  }
958
- if (f.error || f.error_description) throw h(f.error, f.error_description, `Error from OIDC server: ${f.error} - ${f.error_description}`, n ? "refresh" : "callback");
959
- if (f.iss && f.iss !== u.issuer) throw console.error(), Error(`Issuer not valid (expected: ${u.issuer}, received: ${f.iss})`);
960
- if (f.state) {
961
- if (!b) throw new N(M.STATE_MISSING, "OIDC state is missing from storage. The login state may have been cleared between the authorization redirect and the callback (e.g., private browsing, storage cleared, or browser eviction).", n ? "refresh" : "callback");
962
- if (f.state !== b) throw new N(M.STATE_MISMATCH, `OIDC state does not match the stored one (expected: ${b}, received: ${f.state}).`, n ? "refresh" : "callback");
1074
+ if (h.error || h.error_description) throw s(h.error, h.error_description, `Error from OIDC server: ${h.error} - ${h.error_description}`, n ? "refresh" : "callback");
1075
+ if (h.iss && h.iss !== m.issuer) throw console.error(), Error(`Issuer not valid (expected: ${m.issuer}, received: ${h.iss})`);
1076
+ if (h.state) {
1077
+ if (!S) throw new P(N.STATE_MISSING, "OIDC state is missing from storage. The login state may have been cleared between the authorization redirect and the callback (e.g., private browsing, storage cleared, or browser eviction).", n ? "refresh" : "callback");
1078
+ if (h.state !== S) throw new P(N.STATE_MISMATCH, `OIDC state does not match the stored one (expected: ${S}, received: ${h.state}).`, n ? "refresh" : "callback");
963
1079
  }
964
- if (!v || !v.nonce) throw new N(M.NONCE_MISSING, "OIDC nonce is missing from storage. The login state may have been cleared between the authorization redirect and the callback (e.g., private browsing, storage cleared, or browser eviction).", n ? "refresh" : "callback");
965
- let x = {
966
- code: f.code,
1080
+ if (!b || !b.nonce) throw new P(N.NONCE_MISSING, "OIDC nonce is missing from storage. The login state may have been cleared between the authorization redirect and the callback (e.g., private browsing, storage cleared, or browser eviction).", n ? "refresh" : "callback");
1081
+ let C = tt({
1082
+ code: h.code,
967
1083
  grant_type: "authorization_code",
968
- client_id: r.client_id,
969
- redirect_uri: o
970
- }, S = {};
971
- if (r.token_request_extras) for (let [e, t] of Object.entries(r.token_request_extras)) S[e] = t;
972
- if (y?.extras) for (let [e, t] of Object.entries(y.extras)) e.endsWith(":token_request") && (S[e.replace(":token_request", "")] = t);
973
- let C = u.tokenEndpoint, w = {}, T;
974
- r.demonstrating_proof_of_possession && (g ? w.DPoP = `DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${t.configurationName}` : (T = await re(window)(r.demonstrating_proof_of_possession_configuration.generateKeyAlgorithm), await i(t.configurationName, r.storage, r.login_state_storage ?? r.storage).setDemonstratingProofOfPossessionJwkAsync(T), w.DPoP = await ie(window)(r.demonstrating_proof_of_possession_configuration)(T, "POST", C)));
975
- let E = await Me(_)(C, {
976
- ...x,
977
- ...S
978
- }, w, t.configuration.token_renew_mode, l, r.demonstrating_proof_of_possession);
979
- if (!E.success && E.oauthError === "use_dpop_nonce" && E.demonstratingProofOfPossessionNonce && r.demonstrating_proof_of_possession ? (await _.setDemonstratingProofOfPossessionNonce(E.demonstratingProofOfPossessionNonce), g || (w.DPoP = await ie(window)(r.demonstrating_proof_of_possession_configuration)(T, "POST", C, { nonce: E.demonstratingProofOfPossessionNonce })), E = await Me(_)(C, {
980
- ...x,
981
- ...S
982
- }, w, t.configuration.token_renew_mode, l)) : !E.success && r.demonstrating_proof_of_possession && await Promise.all([_.setCodeVerifierAsync(null), _.setStateAsync(null)]), !E.success) {
983
- let e = E.oauthError === "use_dpop_nonce" ? c.DPOP_NONCE_REQUIRED : c.TOKEN_REQUEST_FAILED;
984
- throw new d(e, "Token request failed", {
1084
+ client_id: i.client_id,
1085
+ redirect_uri: u
1086
+ }, i, o), w = {};
1087
+ if (i.token_request_extras) for (let [e, t] of Object.entries(i.token_request_extras)) w[e] = t;
1088
+ if (x?.extras) for (let [e, t] of Object.entries(x.extras)) e.endsWith(":token_request") && (w[e.replace(":token_request", "")] = t);
1089
+ let T = m.tokenEndpoint, E = {}, D;
1090
+ if (i.demonstrating_proof_of_possession) {
1091
+ if (v) E.DPoP = `DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${c}`;
1092
+ else {
1093
+ if (D = o === void 0 ? await te(window)(i.demonstrating_proof_of_possession_configuration.generateKeyAlgorithm) : await g(t.configurationName, i.storage).getDemonstratingProofOfPossessionJwkAsync(), !D) throw new r(e.RESOURCE_TOKEN_UNAVAILABLE, "The original OIDC DPoP key is unavailable.", {
1094
+ phase: "callback",
1095
+ retryable: !1
1096
+ });
1097
+ await g(c, i.storage, i.login_state_storage ?? i.storage).setDemonstratingProofOfPossessionJwkAsync(D), E.DPoP = await ne(window)(i.demonstrating_proof_of_possession_configuration)(D, "POST", T);
1098
+ }
1099
+ }
1100
+ let ee = tt({
1101
+ ...C,
1102
+ ...w
1103
+ }, i, o), O = await je(y)(T, ee, E, t.configuration.token_renew_mode, p, i.demonstrating_proof_of_possession);
1104
+ if (!O.success && O.oauthError === "use_dpop_nonce" && O.demonstratingProofOfPossessionNonce && i.demonstrating_proof_of_possession ? (await y.setDemonstratingProofOfPossessionNonce(O.demonstratingProofOfPossessionNonce), v || (E.DPoP = await ne(window)(i.demonstrating_proof_of_possession_configuration)(D, "POST", T, { nonce: O.demonstratingProofOfPossessionNonce })), O = await je(y)(T, ee, E, t.configuration.token_renew_mode, p)) : !O.success && i.demonstrating_proof_of_possession && await Promise.all([y.setCodeVerifierAsync(null), y.setStateAsync(null)]), !O.success) {
1105
+ let t = O.oauthError === "use_dpop_nonce" ? e.DPOP_NONCE_REQUIRED : e.TOKEN_REQUEST_FAILED;
1106
+ throw new r(t, "Token request failed", {
985
1107
  phase: n ? "refresh" : "callback",
986
- retryable: e === c.DPOP_NONCE_REQUIRED || p(E.status),
987
- status: E.status,
988
- oauthError: E.oauthError,
989
- oauthErrorDescription: E.oauthErrorDescription
1108
+ retryable: t === e.DPOP_NONCE_REQUIRED || a(O.status),
1109
+ status: O.status,
1110
+ oauthError: O.oauthError,
1111
+ oauthErrorDescription: O.oauthErrorDescription
990
1112
  });
991
1113
  }
992
- let D, O = E.data.tokens, k = E.data.demonstratingProofOfPossessionNonce;
993
- if (E.data.state !== S.state) throw new d(c.INVALID_STATE, "state is not valid", {
1114
+ let k, A = O.data.tokens;
1115
+ i.resources?.length && (A.scope ??= x?.scope ?? i.scope);
1116
+ let j = O.data.demonstratingProofOfPossessionNonce;
1117
+ if (O.data.state !== w.state) throw new r(e.INVALID_STATE, "state is not valid", {
994
1118
  phase: n ? "refresh" : "callback",
995
1119
  retryable: !1
996
1120
  });
997
- let { isValid: ee, reason: te } = lt(O, v.nonce, u);
998
- if (!ee) {
999
- let e = `Tokens are not OpenID valid, reason: ${te}`;
1000
- throw te.startsWith("Nonce does not match") ? new d(c.INVALID_NONCE, e, {
1121
+ if (o !== void 0 && A.idTokenPayload?.nonce !== b.nonce) throw new r(e.INVALID_NONCE, "Resource authorization requires the transaction nonce in a fresh ID token.", {
1122
+ phase: n ? "refresh" : "callback",
1123
+ retryable: !1
1124
+ });
1125
+ let { isValid: re, reason: ie } = It(A, b.nonce, m);
1126
+ if (!re) {
1127
+ let t = `Tokens are not OpenID valid, reason: ${ie}`;
1128
+ throw ie.startsWith("Nonce does not match") ? new r(e.INVALID_NONCE, t, {
1001
1129
  phase: n ? "refresh" : "callback",
1002
1130
  retryable: !1
1003
- }) : Error(e);
1131
+ }) : Error(t);
1004
1132
  }
1005
- if (g) {
1006
- if (O.refreshToken && !O.refreshToken.includes("SECURED_BY_OIDC_SERVICE_WORKER")) throw Error("Refresh token should be hidden by service worker");
1007
- if (k && O?.accessToken.includes("SECURED_BY_OIDC_SERVICE_WORKER")) throw Error("Demonstration of proof of possession require Access token not hidden by service worker");
1133
+ if (v) {
1134
+ if (A.refreshToken && !A.refreshToken.includes("SECURED_BY_OIDC_SERVICE_WORKER")) throw Error("Refresh token should be hidden by service worker");
1135
+ if (j && A?.accessToken.includes("SECURED_BY_OIDC_SERVICE_WORKER")) throw Error("Demonstration of proof of possession require Access token not hidden by service worker");
1008
1136
  }
1009
- if (g) await g.initAsync(u, "syncTokensAsync", r), D = g.getLoginParams(), k && await g.setDemonstratingProofOfPossessionNonce(k);
1137
+ if (v) await v.initAsync(m, "syncTokensAsync", i), k = v.getLoginParams(), j && await v.setDemonstratingProofOfPossessionNonce(j);
1010
1138
  else {
1011
- let e = i(t.configurationName, r.storage, r.login_state_storage ?? r.storage);
1012
- D = e.getLoginParams(), k && await e.setDemonstratingProofOfPossessionNonce(k);
1139
+ let e = g(c, i.storage, i.login_state_storage ?? i.storage);
1140
+ k = e.getLoginParams(), j && await e.setDemonstratingProofOfPossessionNonce(j);
1013
1141
  }
1014
- return await t.startCheckSessionAsync(u.checkSessionIframe, a, m, n), t.publishEvent(e.loginCallbackAsync_end, {}), {
1015
- tokens: O,
1142
+ return o === void 0 && await t.startCheckSessionAsync(m.checkSessionIframe, l, _, n), t.publishEvent(f.loginCallbackAsync_end, {}), {
1143
+ resource: o,
1144
+ tokens: A,
1016
1145
  state: "request.state",
1017
- callbackPath: D.callbackPath,
1018
- scope: f.scope,
1019
- extras: D.extras
1146
+ callbackPath: k.callbackPath,
1147
+ scope: h.scope,
1148
+ extras: k.extras
1020
1149
  };
1021
- } catch (r) {
1022
- let i = !f(r) && _(r) ? g(r, n ? "refresh" : "callback") : r;
1023
- throw console.error(i), t.publishEvent(e.loginCallbackAsync_error, i), i;
1150
+ } catch (e) {
1151
+ let r = !i(e) && l(e) ? c(e, n ? "refresh" : "callback") : e;
1152
+ throw console.error(r), t.publishEvent(f.loginCallbackAsync_error, r), r;
1024
1153
  }
1025
- }, Re = {
1154
+ }, ct = {
1026
1155
  access_token: "access_token",
1027
1156
  refresh_token: "refresh_token"
1028
- }, ze = (e, t) => {
1157
+ }, lt = (e, t) => {
1029
1158
  let n = {};
1030
1159
  if (e) {
1031
1160
  for (let [r, i] of Object.entries(e)) if (r.endsWith(t)) {
@@ -1035,184 +1164,497 @@ var he = () => {
1035
1164
  return n;
1036
1165
  }
1037
1166
  return n;
1038
- }, Be = (e) => {
1167
+ }, ut = (e) => {
1039
1168
  let t = {};
1040
1169
  if (e) {
1041
1170
  for (let [n, r] of Object.entries(e)) n.includes(":") || (t[n] = r);
1042
1171
  return t;
1043
1172
  }
1044
1173
  return t;
1045
- }, Ve = (e) => async (t) => {
1046
- b.clearTimeout(e.timeoutId), e.timeoutId = null, e.checkSessionIFrame && e.checkSessionIFrame.stop();
1174
+ }, dt = (e) => async (t) => {
1175
+ e.resourceTokens && await e.resourceTokens.clearAllAsync(), b.clearTimeout(e.timeoutId), e.timeoutId = null, e.checkSessionIFrame && e.checkSessionIFrame.stop();
1047
1176
  let n = await $(e.configuration, e.configurationName);
1048
- n ? await n.clearAsync(t) : await i(e.configurationName, e.configuration.storage, e.configuration.login_state_storage ?? e.configuration.storage).clearAsync(t), e.tokens = null, e.userInfo = null;
1049
- }, He = (t, n) => async () => {
1050
- let r = t.tokens?.idTokenPayload?.sub ?? null;
1051
- await t.destroyAsync("LOGGED_OUT");
1052
- for (let [, i] of Object.entries(n)) i === t ? t.publishEvent(e.logout_from_same_tab, {}) : await t.logoutSameTabAsync(t.configuration.client_id, r);
1053
- }, Ue = (e, t, n, r) => {
1177
+ n ? await n.clearAsync(t) : await g(e.configurationName, e.configuration.storage, e.configuration.login_state_storage ?? e.configuration.storage).clearAsync(t), e.tokens = null, e.userInfo = null;
1178
+ }, ft = (e, t) => async () => {
1179
+ let n = e.tokens?.idTokenPayload?.sub ?? null;
1180
+ await e.destroyAsync("LOGGED_OUT");
1181
+ for (let [, r] of Object.entries(t)) r === e ? e.publishEvent(f.logout_from_same_tab, {}) : await e.logoutSameTabAsync(e.configuration.client_id, n);
1182
+ }, pt = (e, t, n, r) => {
1054
1183
  "id_token_hint" in t || (t.id_token_hint = n), !("post_logout_redirect_uri" in t) && r !== null && (t.post_logout_redirect_uri = r);
1055
1184
  let i = "";
1056
1185
  for (let [e, n] of Object.entries(t)) n != null && (i += i === "" ? "?" : "&", i += `${e}=${encodeURIComponent(n)}`);
1057
1186
  return `${e}${i}`;
1058
- }, We = (t, n, r, i, a) => async (o = void 0, s = null) => {
1059
- let l = t.configuration, u;
1187
+ }, mt = (t, n, o, s, u) => async (d = void 0, p = null) => {
1188
+ let m = t.configuration, h;
1060
1189
  try {
1061
- u = await t.initAsync(l.authority, l.authority_configuration);
1062
- } catch (n) {
1063
- let r = _(n) ? g(n, "logout") : n;
1064
- throw t.publishEvent(e.logoutAsync_error, r), r;
1190
+ h = await t.initAsync(m.authority, m.authority_configuration);
1191
+ } catch (e) {
1192
+ let n = l(e) ? c(e, "logout") : e;
1193
+ throw t.publishEvent(f.logoutAsync_error, n), n;
1065
1194
  }
1066
- o && typeof o != "string" && (o = void 0, i.warn("callbackPathOrUrl path is not a string"));
1067
- let m = o ?? a.getPath(), h = !1;
1068
- o && (h = o.includes("https://") || o.includes("http://"));
1069
- let v = o === null ? null : h ? o : a.getOrigin() + m, y = t.tokens ? t.tokens.idToken : "";
1195
+ d && typeof d != "string" && (d = void 0, s.warn("callbackPathOrUrl path is not a string"));
1196
+ let g = d ?? u.getPath(), _ = !1;
1197
+ d && (_ = d.includes("https://") || d.includes("http://"));
1198
+ let v = d === null ? null : _ ? d : u.getOrigin() + g, y = t.tokens ? t.tokens.idToken : "";
1070
1199
  t.isLoggingOut = !0;
1071
1200
  try {
1072
1201
  try {
1073
- let n = u.revocationEndpoint;
1202
+ m.resources?.length && t.resourceTokens && await t.resourceTokens.withRefreshLockAsync(async () => {});
1203
+ let n = h.revocationEndpoint;
1074
1204
  if (n) {
1075
- let i = [], a = t.tokens ? t.tokens.accessToken : null;
1076
- if (a && l.logout_tokens_to_invalidate.includes(Re.access_token)) {
1077
- let e = ze(s, ":revoke_access_token"), t = De(r)(n, a, Te.access_token, l.client_id, e);
1205
+ let i = [], s = t.tokens ? t.tokens.accessToken : null;
1206
+ if (s && m.logout_tokens_to_invalidate.includes(ct.access_token)) {
1207
+ let e = lt(p, ":revoke_access_token"), t = Ee(o)(n, s, R.access_token, m.client_id, e);
1078
1208
  i.push(t);
1079
1209
  }
1080
- let o = t.tokens ? t.tokens.refreshToken : null;
1081
- if (o && l.logout_tokens_to_invalidate.includes(Re.refresh_token)) {
1082
- let e = ze(s, ":revoke_refresh_token"), t = De(r)(n, o, Te.refresh_token, l.client_id, e);
1210
+ let c = t.tokens ? t.tokens.refreshToken : null;
1211
+ if (c && m.logout_tokens_to_invalidate.includes(ct.refresh_token)) {
1212
+ let e = lt(p, ":revoke_refresh_token"), t = Ee(o)(n, c, R.refresh_token, m.client_id, e);
1083
1213
  i.push(t);
1084
1214
  }
1215
+ if (t.resourceTokens) {
1216
+ let e = await t.resourceTokens.getTokensToRevokeAsync(), r = new Set([s, c].filter(Boolean));
1217
+ for (let t of e) for (let [e, a] of [[R.access_token, t.accessToken], [R.refresh_token, t.refreshToken]]) a && !r.has(a) && m.logout_tokens_to_invalidate.includes(e) && (r.add(a), i.push(Ee(o)(n, a, e, m.client_id, lt(p, e === R.access_token ? ":revoke_access_token" : ":revoke_refresh_token"))));
1218
+ }
1085
1219
  if (i.length > 0) {
1086
1220
  let n = await Promise.all(i);
1087
- for (let r of n) r.success || t.publishEvent(e.logoutAsync_error, new d(c.REQUEST_FAILED, "Token revocation request failed", {
1221
+ for (let i of n) i.success || t.publishEvent(f.logoutAsync_error, new r(e.REQUEST_FAILED, "Token revocation request failed", {
1088
1222
  phase: "logout",
1089
- retryable: p(r.status),
1090
- status: r.status,
1091
- oauthError: r.oauthError,
1092
- oauthErrorDescription: r.oauthErrorDescription
1223
+ retryable: a(i.status),
1224
+ status: i.status,
1225
+ oauthError: i.oauthError,
1226
+ oauthErrorDescription: i.oauthErrorDescription
1093
1227
  }));
1094
1228
  }
1095
1229
  }
1096
- } catch (n) {
1097
- let r = !f(n) && _(n) ? g(n, "logout") : n;
1098
- t.publishEvent(e.logoutAsync_error, r), i.warn("logoutAsync: error when revoking tokens, if the error persist, you ay configure property logout_tokens_to_invalidate from configuration to avoid this error"), i.warn(r);
1230
+ } catch (e) {
1231
+ let n = !i(e) && l(e) ? c(e, "logout") : e;
1232
+ t.publishEvent(f.logoutAsync_error, n), s.warn("logoutAsync: error when revoking tokens, if the error persist, you ay configure property logout_tokens_to_invalidate from configuration to avoid this error"), s.warn(n);
1099
1233
  }
1100
- let o = ze(s, ":oidc");
1101
- if (o && o.no_reload === "true") {
1102
- await He(t, n)(), t.isLoggingOut = !1;
1234
+ let d = lt(p, ":oidc");
1235
+ if (d && d.no_reload === "true") {
1236
+ await ft(t, n)(), t.isLoggingOut = !1;
1103
1237
  return;
1104
1238
  }
1105
- let m = Be(s);
1106
- if (u.endSessionEndpoint) {
1107
- let e = Ue(u.endSessionEndpoint, m, y, v);
1108
- a.open(e);
1109
- } else a.reload();
1110
- await He(t, n)();
1111
- } catch (n) {
1239
+ let g = ut(p);
1240
+ if (h.endSessionEndpoint) {
1241
+ let e = pt(h.endSessionEndpoint, g, y, v);
1242
+ u.open(e);
1243
+ } else u.reload();
1244
+ await ft(t, n)();
1245
+ } catch (e) {
1112
1246
  t.isLoggingOut = !1;
1113
- let r = !f(n) && _(n) ? g(n, "logout") : n;
1114
- throw t.publishEvent(e.logoutAsync_error, r), r;
1247
+ let n = !i(e) && l(e) ? c(e, "logout") : e;
1248
+ throw t.publishEvent(f.logoutAsync_error, n), n;
1249
+ }
1250
+ }, U = (t) => new r(e.RESOURCE_TOKEN_UNAVAILABLE, t, {
1251
+ phase: "refresh",
1252
+ retryable: !1
1253
+ }), ht = class {
1254
+ constructor(e) {
1255
+ this.oidc = e, this.pending = /* @__PURE__ */ new Map(), this.cached = /* @__PURE__ */ new Map(), this.generations = /* @__PURE__ */ new Map(), this.generation = 0, this.refreshQueue = Promise.resolve(), this.renewalTimers = /* @__PURE__ */ new Map();
1256
+ }
1257
+ async contextAsync(e) {
1258
+ let { oidc: t } = this, n = H(t.configurationName, e), r = await t.initAsync(t.configuration.authority, t.configuration.authority_configuration), i = await $(t.configuration, n), a = g(n, t.configuration.storage, t.configuration.login_state_storage ?? t.configuration.storage), o = i ? await i.initAsync(r, "resource-token", t.configuration) : await a.initAsync(), s = [];
1259
+ if ("resourceContexts" in o && o.resourceContexts !== void 0) {
1260
+ if (!Array.isArray(o.resourceContexts) || o.resourceContexts.some((e) => typeof e != "string")) throw U("The worker returned invalid resource context metadata.");
1261
+ s.push(...o.resourceContexts);
1262
+ }
1263
+ return {
1264
+ storage: i ?? a,
1265
+ tokens: o.tokens,
1266
+ server: r,
1267
+ isWorker: i !== null,
1268
+ resourceContexts: s
1269
+ };
1270
+ }
1271
+ validate(t, n, i, a = this.oidc.tokens?.idTokenPayload?.sub) {
1272
+ let { oidc: o } = this, s = B(o.configuration.resources, t), c = n.resourceContext;
1273
+ if (!c || c.resource !== t || c.issuer !== i || c.clientId !== o.configuration.client_id || c.configurationName !== o.configurationName || c.subject !== a) throw new r(e.RESOURCE_CONTEXT_MISMATCH, "The token does not belong to this resource and OIDC session.", {
1274
+ phase: "refresh",
1275
+ retryable: !1
1276
+ });
1277
+ let l = n.accessTokenPayload;
1278
+ if (l?.iss !== void 0 && l.iss !== i || l && s.audiences && !s.audiences.some((e) => (typeof l.aud == "string" ? [l.aud] : Array.isArray(l.aud) ? l.aud : []).includes(e))) throw new r(e.RESOURCE_CONTEXT_MISMATCH, "Resource token issuer or configured audience does not match.", {
1279
+ phase: "refresh",
1280
+ retryable: !1
1281
+ });
1282
+ if (typeof n.accessToken != "string" || !n.accessToken || !Number.isFinite(n.expiresAt) || !Number.isFinite(n.issuedAt) || n.refreshToken != null && (typeof n.refreshToken != "string" || !n.refreshToken)) throw U("The provider did not return a usable resource token response.");
1283
+ if (s.scope && !s.scope.split(/\s+/).filter(Boolean).every((e) => (n.scope ?? "").split(/\s+/).includes(e))) throw U("The provider did not grant the required resource scopes.");
1115
1284
  }
1116
- }, B = /* @__PURE__ */ function(e) {
1285
+ publicToken(e, t) {
1286
+ return {
1287
+ resource: e,
1288
+ issuer: t.resourceContext.issuer,
1289
+ clientId: this.oidc.configuration.client_id,
1290
+ configurationName: this.oidc.configurationName,
1291
+ accessToken: t.accessToken,
1292
+ expiresAt: t.expiresAt,
1293
+ scope: t.scope,
1294
+ tokenType: t.tokenType
1295
+ };
1296
+ }
1297
+ updateSharedRefreshToken(e, t) {
1298
+ typeof e.refreshToken == "string" && e.refreshToken && this.oidc.tokens && (this.oidc.tokens = {
1299
+ ...this.oidc.tokens,
1300
+ refreshToken: e.refreshToken
1301
+ }, t || g(this.oidc.configurationName, this.oidc.configuration.storage).setTokens(this.oidc.tokens));
1302
+ }
1303
+ scheduleRenewal(e, t) {
1304
+ let n = this.renewalTimers.get(e);
1305
+ if (n && b.clearTimeout(n), this.oidc.configuration.token_automatic_renew_mode === "AutomaticOnlyWhenFetchExecuted") return;
1306
+ let r = Math.max(1e3, Math.min(2147483647, (t.expiresAt - Date.now() / 1e3 - this.renewalMargin(t)) * 1e3)), a = b.setTimeout(async () => {
1307
+ this.renewalTimers.delete(e);
1308
+ try {
1309
+ await this.getAccessTokenAsync(e, { forceRenew: !0 });
1310
+ } catch (e) {
1311
+ console.error("Resource renewal failed:", i(e) ? e.code : "unexpected error");
1312
+ }
1313
+ }, r);
1314
+ this.renewalTimers.set(e, a);
1315
+ }
1316
+ renewalMargin(e) {
1317
+ return Math.min(this.oidc.configuration.refresh_time_before_tokens_expiration_in_second, Math.max(0, (e.expiresAt - e.issuedAt) / 2));
1318
+ }
1319
+ async withRefreshLockAsync(e) {
1320
+ let t = async () => {
1321
+ if (navigator.locks) {
1322
+ let t = this.oidc.configuration;
1323
+ return navigator.locks.request(`${t.client_id}_${this.oidc.configurationName}_${t.authority}`, e);
1324
+ }
1325
+ return e();
1326
+ }, n = this.refreshQueue.then(t, t);
1327
+ return this.refreshQueue = n.then(() => void 0, () => void 0), n;
1328
+ }
1329
+ async acceptAuthorizationAsync(t, n) {
1330
+ let i = this.generation, a = this.generations.get(t) ?? 0, o = await this.contextAsync(t), s = await this.contextAsync();
1331
+ if (i !== this.generation || a !== (this.generations.get(t) ?? 0)) throw U("The resource authorization was cleared.");
1332
+ let c = n.idTokenPayload?.sub;
1333
+ if (typeof c != "string" || (this.oidc.tokens?.idTokenPayload?.sub ?? s.tokens?.idTokenPayload?.sub) !== c) throw new r(e.RESOURCE_CONTEXT_MISMATCH, "Resource authorization must preserve the authenticated subject.", {
1334
+ phase: "callback",
1335
+ retryable: !1
1336
+ });
1337
+ if (n.refreshToken && n.refreshToken === s.tokens?.refreshToken) throw U("The provider reused a refresh token across separate authorization transactions; use a multi-resource authorization grant instead.");
1338
+ let l = {
1339
+ ...n,
1340
+ scope: n.scope ?? B(this.oidc.configuration.resources, t).scope ?? this.oidc.configuration.scope,
1341
+ resourceContext: {
1342
+ resource: t,
1343
+ issuer: o.server.issuer,
1344
+ clientId: this.oidc.configuration.client_id,
1345
+ configurationName: this.oidc.configurationName,
1346
+ subject: c,
1347
+ grantResource: t
1348
+ }
1349
+ };
1350
+ this.validate(t, l, o.server.issuer, c), o.isWorker || g(H(this.oidc.configurationName, t), this.oidc.configuration.storage).setTokens(l), this.cached.set(t, l);
1351
+ }
1352
+ getAccessTokenAsync(t, n = {}) {
1353
+ let a = this.pending.get(t);
1354
+ if (a) return a;
1355
+ let o = this.generation, u = this.generations.get(t) ?? 0, d = this.oidc.tokens?.idTokenPayload?.sub, p = this.oidc.tokens?.idTokenPayload?.nonce, m = () => this.generation === o && (this.generations.get(t) ?? 0) === u && !this.oidc.isLoggingOut && this.oidc.tokens?.idTokenPayload?.sub === d && this.oidc.tokens?.idTokenPayload?.nonce === p, h = this.withRefreshLockAsync(async () => {
1356
+ let { oidc: i } = this, a = B(i.configuration.resources, t);
1357
+ if (!Number.isFinite(i.configuration.refresh_time_before_tokens_expiration_in_second) || i.configuration.refresh_time_before_tokens_expiration_in_second < 0) throw U("Configure a finite, non-negative renewal margin.");
1358
+ if (!i.tokens || typeof i.tokens.idTokenPayload?.sub != "string" || !m()) throw U("Sign in before requesting a resource token.");
1359
+ if (i.configuration.token_request_extras?.resource !== void 0 && i.configuration.token_request_extras.resource !== t) throw new r(e.INVALID_RESOURCE, "Token extras conflict with the selected resource.", {
1360
+ phase: "refresh",
1361
+ retryable: !1
1362
+ });
1363
+ let c = await this.contextAsync(t), l = await this.contextAsync();
1364
+ if (!m()) throw U("The resource transaction was cleared.");
1365
+ let h = l.tokens?.idTokenPayload?.nonce;
1366
+ if (!l.tokens || l.tokens.idTokenPayload?.sub !== d || !l.isWorker && h !== i.tokens.idTokenPayload?.nonce) throw U("The original OIDC session changed or is unavailable; restore it before requesting resource tokens.");
1367
+ let _ = c.tokens;
1368
+ if (_ && (this.validate(t, _, c.server.issuer), !n.forceRenew && Pt(_, this.renewalMargin(_)))) {
1369
+ let e = this.cached.get(t);
1370
+ return this.cached.set(t, _), this.scheduleRenewal(t, _), (e?.accessToken !== _.accessToken || e?.expiresAt !== _.expiresAt || e?.scope !== _.scope || e?.tokenType !== _.tokenType) && i.publishEvent(f.resource_token_acquired, { resource: t }), this.publicToken(t, _);
1371
+ }
1372
+ let v = typeof i.configuration.resource == "string" ? [i.configuration.resource] : i.configuration.resource ?? [], y = (l.tokens.scope ?? i.configuration.scope).split(/\s+/), b = !a.scope || a.scope.split(/\s+/).filter(Boolean).every((e) => y.includes(e)), S = _?.resourceContext ? _.resourceContext.grantResource : v.includes(t) && b ? null : t, C = S === null ? await this.contextAsync() : c, w = S === null && !b ? void 0 : C.tokens?.refreshToken, T = i.configuration.demonstrating_proof_of_possession || C.tokens?.tokenType?.toLowerCase() === "dpop";
1373
+ if (!m()) throw U("The resource transaction was cleared.");
1374
+ if (w) {
1375
+ let n = await C.storage.getNonceAsync(), l = c.isWorker ? { [Me]: encodeURIComponent(t) } : {};
1376
+ T && (l.DPoP = await this.generateProofAsync(t, {
1377
+ accessToken: C.tokens.accessToken,
1378
+ url: c.server.tokenEndpoint,
1379
+ method: "POST",
1380
+ grantResource: S
1381
+ }));
1382
+ let f = {
1383
+ client_id: i.configuration.client_id,
1384
+ grant_type: "refresh_token",
1385
+ refresh_token: w,
1386
+ resource: t,
1387
+ ...a.scope ? { scope: a.scope } : {}
1388
+ }, v = () => ke(i.getFetch())(c.server.tokenEndpoint, f, i.configuration.token_request_extras ?? {}, _, l, Y.access_token_invalid, i.configuration.token_request_timeout), y = await v();
1389
+ if (!y.success && y.oauthError === "use_dpop_nonce" && y.demonstratingProofOfPossessionNonce && T && (await C.storage.setDemonstratingProofOfPossessionNonce(y.demonstratingProofOfPossessionNonce), l.DPoP = await this.generateProofAsync(t, {
1390
+ accessToken: C.tokens.accessToken,
1391
+ url: c.server.tokenEndpoint,
1392
+ method: "POST",
1393
+ grantResource: S
1394
+ }), y = await v()), y.success) {
1395
+ let s = await this.contextAsync();
1396
+ if (!s.tokens || s.tokens.idTokenPayload?.sub !== d || !s.isWorker && s.tokens.idTokenPayload?.nonce !== h) throw U("The original OIDC session changed during resource renewal.");
1397
+ _ = y.data;
1398
+ let l = this.generation === o && i.tokens?.idTokenPayload?.sub === d && i.tokens?.idTokenPayload?.nonce === p;
1399
+ if (l && S === null && this.updateSharedRefreshToken(_, c.isWorker), _.idTokenPayload?.sub !== void 0 && _.idTokenPayload.sub !== d) throw new r(e.RESOURCE_CONTEXT_MISMATCH, "Resource renewal changed the authenticated subject.", {
1400
+ phase: "refresh",
1401
+ retryable: !1
1402
+ });
1403
+ let f = It(_, n?.nonce, c.server);
1404
+ if (!f.isValid) throw U(f.reason);
1405
+ if (_ = {
1406
+ ..._,
1407
+ scope: _.scope ?? a.scope ?? C.tokens.scope ?? i.configuration.scope,
1408
+ resourceContext: {
1409
+ resource: t,
1410
+ issuer: c.server.issuer,
1411
+ clientId: i.configuration.client_id,
1412
+ configurationName: i.configurationName,
1413
+ subject: d,
1414
+ grantResource: S
1415
+ }
1416
+ }, this.validate(t, _, c.server.issuer, d), !m()) throw l && i.isLoggingOut && u === (this.generations.get(t) ?? 0) && !c.isWorker && g(H(i.configurationName, t), i.configuration.storage).setTokens(_), U("The resource transaction was cleared.");
1417
+ y.demonstratingProofOfPossessionNonce && await C.storage.setDemonstratingProofOfPossessionNonce(y.demonstratingProofOfPossessionNonce), c.isWorker || g(H(i.configurationName, t), i.configuration.storage).setTokens(_), S === null && this.updateSharedRefreshToken(_, c.isWorker);
1418
+ } else if (y.oauthError !== "invalid_grant") throw s(y.oauthError, y.oauthErrorDescription, "Resource token request failed.", "refresh", y.status);
1419
+ else _ = null;
1420
+ } else _ = null;
1421
+ if (!_) {
1422
+ if (!m()) throw U("The resource transaction was cleared.");
1423
+ let e = a.scope ? [.../* @__PURE__ */ new Set(["openid", ...a.scope.split(" ")])].join(" ") : i.configuration.scope, n = await x(i.configurationName, i.configuration, i.publishEvent.bind(i), "refresh")({
1424
+ ...i.configuration.extras,
1425
+ prompt: "none",
1426
+ resource: t,
1427
+ [$e]: t
1428
+ }, null, e);
1429
+ if (!n) throw U("Configure silent_redirect_uri and silent_login_uri for resource authorization.");
1430
+ if (n.error) throw n.oidcError ?? s(n.error, void 0, "Resource silent authorization failed.", "refresh");
1431
+ if (!m() || n.resource !== t) throw U("The resource authorization transaction is no longer current.");
1432
+ await this.acceptAuthorizationAsync(t, n.tokens), c = await this.contextAsync(t), _ = c.tokens ?? this.cached.get(t);
1433
+ }
1434
+ if (!m()) throw U("The resource transaction was cleared.");
1435
+ if (this.validate(t, _, c.server.issuer), !Pt(_)) throw U("The resource access token is expired.");
1436
+ return this.cached.set(t, _), this.scheduleRenewal(t, _), i.publishEvent(f.resource_token_acquired, { resource: t }), this.publicToken(t, _);
1437
+ }).catch((n) => {
1438
+ let a = i(n) ? n : l(n) ? c(n, "refresh") : new r(e.RESOURCE_TOKEN_UNAVAILABLE, n instanceof Error ? n.message : "Resource token acquisition failed.", {
1439
+ phase: "refresh",
1440
+ retryable: !1,
1441
+ cause: n
1442
+ });
1443
+ throw this.oidc.publishEvent(f.resource_token_error, {
1444
+ resource: t,
1445
+ error: a
1446
+ }), a;
1447
+ }).finally(() => {
1448
+ this.pending.get(t) === h && this.pending.delete(t);
1449
+ });
1450
+ return this.pending.set(t, h), h;
1451
+ }
1452
+ async generateProofAsync(e, t) {
1453
+ let n = this.cached.get(e)?.resourceContext, r = t.grantResource === void 0 ? n ? n.grantResource : e : t.grantResource, i = await this.contextAsync(r ?? void 0);
1454
+ if (i.isWorker) return `DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${H(this.oidc.configurationName, e)}`;
1455
+ let a = await i.storage.getDemonstratingProofOfPossessionJwkAsync();
1456
+ if (!a) throw U("The resource DPoP grant key is unavailable.");
1457
+ let o = t.url === i.server.tokenEndpoint ? await i.storage.getDemonstratingProofOfPossessionNonce() : g(H(this.oidc.configurationName, e), this.oidc.configuration.storage).getDemonstratingProofOfPossessionApiNonce();
1458
+ return ne(window)(this.oidc.configuration.demonstrating_proof_of_possession_configuration)(a, t.method, t.url, {
1459
+ ath: await le(t.accessToken),
1460
+ ...o ? { nonce: o } : {}
1461
+ });
1462
+ }
1463
+ peek(e) {
1464
+ if (this.oidc.isLoggingOut) return null;
1465
+ let t = this.cached.get(e);
1466
+ return t && t.resourceContext?.subject === this.oidc.tokens?.idTokenPayload?.sub && Pt(t) ? this.publicToken(e, t) : null;
1467
+ }
1468
+ createApiNonceRecorder(e) {
1469
+ let t = this.generation, n = this.generations.get(e) ?? 0;
1470
+ return async (r) => {
1471
+ t !== this.generation || n !== (this.generations.get(e) ?? 0) || !this.peek(e) ? console.warn("Ignoring a resource API nonce response after its session was cleared.") : this.oidc.configuration.service_worker_relative_url || await g(H(this.oidc.configurationName, e), this.oidc.configuration.storage).setDemonstratingProofOfPossessionApiNonce(r);
1472
+ };
1473
+ }
1474
+ async getTokensToRevokeAsync() {
1475
+ if (!this.oidc.configuration.resources?.length) return [];
1476
+ let e = await this.contextAsync(), t = e.isWorker ? e.resourceContexts.map(Pe).filter((e) => e !== void 0) : this.oidc.configuration.resources.map((e) => e.resource), n = [];
1477
+ for (let e of t) {
1478
+ let t = await this.contextAsync(e);
1479
+ t.tokens && (this.validate(e, t.tokens, t.server.issuer), n.push(t.tokens));
1480
+ }
1481
+ return n;
1482
+ }
1483
+ async clearAsync(e) {
1484
+ B(this.oidc.configuration.resources, e), this.generations.set(e, (this.generations.get(e) ?? 0) + 1), at(this.oidc.configurationName, e), this.pending.delete(e), this.cached.delete(e);
1485
+ let t = this.renewalTimers.get(e);
1486
+ t && b.clearTimeout(t), this.renewalTimers.delete(e);
1487
+ let n = await this.contextAsync(e);
1488
+ await n.storage.clearAsync("LOGGED_OUT"), n.storage.setLoginParams(null), n.isWorker || (await g(H(this.oidc.configurationName, e), this.oidc.configuration.storage).setDemonstratingProofOfPossessionApiNonce(null), await Promise.all([
1489
+ n.storage.setStateAsync(null),
1490
+ n.storage.setCodeVerifierAsync(null),
1491
+ n.storage.setNonceAsync(null),
1492
+ n.storage.setDemonstratingProofOfPossessionJwkAsync(null),
1493
+ n.storage.setDemonstratingProofOfPossessionNonce(null)
1494
+ ])), this.oidc.publishEvent(f.resource_token_cleared, { resource: e });
1495
+ }
1496
+ async clearAllAsync() {
1497
+ if (this.oidc.configuration.resources?.length) {
1498
+ this.generation++, at(this.oidc.configurationName), this.pending.clear(), this.cached.clear();
1499
+ for (let e of this.renewalTimers.values()) b.clearTimeout(e);
1500
+ if (this.renewalTimers.clear(), !this.oidc.configuration.service_worker_relative_url) for (let e of this.oidc.configuration.resources ?? []) {
1501
+ let t = g(H(this.oidc.configurationName, e.resource), this.oidc.configuration.storage, this.oidc.configuration.login_state_storage ?? this.oidc.configuration.storage);
1502
+ await t.clearAsync("LOGGED_OUT"), t.setLoginParams(null), await Promise.all([
1503
+ t.setStateAsync(null),
1504
+ t.setCodeVerifierAsync(null),
1505
+ t.setNonceAsync(null),
1506
+ t.setDemonstratingProofOfPossessionJwkAsync(null),
1507
+ t.setDemonstratingProofOfPossessionNonce(null),
1508
+ t.setDemonstratingProofOfPossessionApiNonce(null)
1509
+ ]);
1510
+ }
1511
+ }
1512
+ }
1513
+ }, W = /* @__PURE__ */ function(e) {
1117
1514
  return e.AutomaticBeforeTokenExpiration = "AutomaticBeforeTokensExpiration", e.AutomaticOnlyWhenFetchExecuted = "AutomaticOnlyWhenFetchExecuted", e;
1118
- }({}), Ge = (t, n, r = !1, i = "api_request") => async (...a) => {
1119
- let [o, s, ...l] = a, u = s ? { ...s } : { method: "GET" }, f = new Headers();
1120
- u.headers && (f = u.headers instanceof Headers ? u.headers : new Headers(u.headers));
1121
- let p = (await ct({
1515
+ }({}), gt = (t, n, i = !1, a = "api_request") => async (...o) => {
1516
+ let [s, l, ...u] = o, d = typeof a == "string" ? a : "api_request", p = typeof a == "string" ? void 0 : a.resource, m;
1517
+ if (p === void 0 && d === "api_request" && n.configuration.resources?.length) try {
1518
+ let e = new URL(s instanceof Request ? s.url : s.toString(), window.location.href).toString();
1519
+ if (Re(n.configuration.resources, e)) throw Error("Select a resource explicitly when fetching a resource-managed API.");
1520
+ } catch (t) {
1521
+ let i = new r(e.INVALID_RESOURCE, t instanceof Error ? t.message : "Invalid resource destination.", {
1522
+ phase: d,
1523
+ retryable: !1,
1524
+ cause: t
1525
+ });
1526
+ throw n.publishEvent(f.apiRequest_error, i), i;
1527
+ }
1528
+ if (typeof a != "string" && Object.prototype.hasOwnProperty.call(a, "resource")) try {
1529
+ if (typeof p != "string") throw Error("An explicit resource identifier is required.");
1530
+ if (m = new URL(s instanceof Request ? s.url : s.toString(), window.location.href).toString(), !ze(B(n.configuration.resources, p), m)) throw Error("The destination does not belong to the selected resource.");
1531
+ if (l?.redirect === "follow") throw Error("Resource fetch cannot automatically follow redirects.");
1532
+ } catch (t) {
1533
+ let i = new r(e.INVALID_RESOURCE, t instanceof Error ? t.message : "Invalid resource destination.", {
1534
+ phase: d,
1535
+ retryable: !1,
1536
+ cause: t
1537
+ });
1538
+ throw n.publishEvent(f.apiRequest_error, i), i;
1539
+ }
1540
+ let h = p === void 0 ? l ? { ...l } : { method: "GET" } : {
1541
+ ...s instanceof Request ? {
1542
+ method: s.method,
1543
+ headers: s.headers,
1544
+ credentials: s.credentials
1545
+ } : { method: "GET" },
1546
+ ...l,
1547
+ redirect: l?.redirect ?? "error"
1548
+ }, g = new Headers();
1549
+ h.headers && (g = p === void 0 && h.headers instanceof Headers ? h.headers : new Headers(h.headers));
1550
+ let _ = {
1122
1551
  getTokens: () => n.tokens,
1123
1552
  configuration: {
1124
1553
  token_automatic_renew_mode: n.configuration.token_automatic_renew_mode,
1125
1554
  refresh_time_before_tokens_expiration_in_second: n.configuration.refresh_time_before_tokens_expiration_in_second
1126
1555
  },
1127
1556
  syncTokensInfoAsync: async () => {
1128
- let { status: e } = await et(n)(n.configuration, n.configurationName, n.tokens, !1);
1557
+ let { status: e } = await Et(n)(n.configuration, n.configurationName, n.tokens, !1);
1129
1558
  return e;
1130
1559
  },
1131
1560
  renewTokensAsync: n.renewTokensAsync.bind(n)
1132
- }))?.tokens?.accessToken;
1133
- if (f.has("Accept") || f.set("Accept", "application/json"), p) {
1134
- if (n.configuration.demonstrating_proof_of_possession && r) {
1135
- let e = await n.generateDemonstrationOfProofOfPossessionAsync(p, o.toString(), u.method);
1136
- f.set("Authorization", `DPoP ${p}`), f.set("DPoP", e);
1137
- } else f.set("Authorization", `Bearer ${p}`);
1138
- u.credentials ||= "same-origin";
1139
- }
1140
- let m = {
1141
- ...u,
1142
- headers: f
1143
- }, h;
1561
+ }, v = p === void 0 ? void 0 : await n.resourceTokens.getAccessTokenAsync(p), y = p === void 0 ? await Ft(_) : void 0, b = v?.accessToken ?? y?.tokens?.accessToken;
1562
+ if (g.has("Accept") || g.set("Accept", "application/json"), b) {
1563
+ if (n.configuration.demonstrating_proof_of_possession && i || v?.tokenType?.toLowerCase() === "dpop") {
1564
+ let e = p === void 0 ? await n.generateDemonstrationOfProofOfPossessionAsync(b, s.toString(), h.method) : await n.resourceTokens.generateProofAsync(p, {
1565
+ accessToken: b,
1566
+ url: m,
1567
+ method: h.method ?? "GET"
1568
+ });
1569
+ g.set("Authorization", `DPoP ${b}`), g.set("DPoP", e);
1570
+ } else g.set("Authorization", `Bearer ${b}`);
1571
+ h.credentials ||= "same-origin";
1572
+ }
1573
+ let x = {
1574
+ ...h,
1575
+ headers: g
1576
+ }, S = v && g.has("DPoP") ? n.resourceTokens.createApiNonceRecorder(p) : void 0;
1577
+ if (v && n.resourceTokens.peek(p)?.accessToken !== v.accessToken) {
1578
+ let t = new r(e.RESOURCE_TOKEN_UNAVAILABLE, "The selected resource token was cleared or changed before dispatch.", {
1579
+ phase: d,
1580
+ retryable: !1
1581
+ });
1582
+ throw n.publishEvent(f.apiRequest_error, t), t;
1583
+ }
1584
+ let C;
1144
1585
  try {
1145
- h = await t(o, m, ...l);
1146
- } catch (t) {
1147
- let r = g(t, i);
1148
- throw i === "api_request" && n.publishEvent(e.apiRequest_error, r), r;
1586
+ C = await t(s, x, ...u);
1587
+ } catch (e) {
1588
+ let t = c(e, d);
1589
+ throw d === "api_request" && n.publishEvent(f.apiRequest_error, t), t;
1149
1590
  }
1150
- if (!h.ok && h.headers?.has("DPoP-Nonce") && (h.status === 400 || h.status === 401 || h.headers.get("WWW-Authenticate")?.includes("use_dpop_nonce"))) {
1151
- let t = new d(c.DPOP_NONCE_REQUIRED, "DPoP nonce required", {
1152
- phase: i,
1591
+ let w = C.headers?.get("DPoP-Nonce");
1592
+ if (S && w && await S(w), !C.ok && C.headers?.has("DPoP-Nonce") && (C.status === 400 || C.status === 401 || C.headers.get("WWW-Authenticate")?.includes("use_dpop_nonce"))) {
1593
+ let t = new r(e.DPOP_NONCE_REQUIRED, "DPoP nonce required", {
1594
+ phase: d,
1153
1595
  retryable: !0,
1154
- status: h.status,
1596
+ status: C.status,
1155
1597
  oauthError: "use_dpop_nonce"
1156
1598
  });
1157
- i === "api_request" && n.publishEvent(e.apiRequest_error, t);
1599
+ d === "api_request" && n.publishEvent(f.apiRequest_error, t);
1158
1600
  }
1159
- return h;
1160
- }, Ke = (t) => async (n = !1, r = !1) => {
1601
+ return C;
1602
+ }, _t = (t) => async (n = !1, o = !1) => {
1161
1603
  try {
1162
1604
  if (t.userInfo != null && !n) return t.userInfo;
1163
1605
  let i = !n && t.configuration.storage?.getItem(`oidc.${t.configurationName}.userInfo`);
1164
1606
  if (i) return t.userInfo = JSON.parse(i), t.userInfo;
1165
- let a = t.configuration, o = (await t.initAsync(a.authority, a.authority_configuration)).userInfoEndpoint, s = await (async () => {
1166
- let n = await Ge(fetch, t, r, "userinfo")(o);
1607
+ let s = t.configuration, c = (await t.initAsync(s.authority, s.authority_configuration)).userInfoEndpoint, l = await (async () => {
1608
+ let n = await gt(fetch, t, o, "userinfo")(c);
1167
1609
  if (n.status !== 200) {
1168
- let r = n.headers?.has("DPoP-Nonce") && (n.status === 400 || n.status === 401 || n.headers.get("WWW-Authenticate")?.includes("use_dpop_nonce")), i = new d(r ? c.DPOP_NONCE_REQUIRED : c.REQUEST_FAILED, "UserInfo request failed", {
1610
+ let i = n.headers?.has("DPoP-Nonce") && (n.status === 400 || n.status === 401 || n.headers.get("WWW-Authenticate")?.includes("use_dpop_nonce")), o = new r(i ? e.DPOP_NONCE_REQUIRED : e.REQUEST_FAILED, "UserInfo request failed", {
1169
1611
  phase: "userinfo",
1170
- retryable: r || p(n.status),
1612
+ retryable: i || a(n.status),
1171
1613
  status: n.status,
1172
- oauthError: r ? "use_dpop_nonce" : void 0
1614
+ oauthError: i ? "use_dpop_nonce" : void 0
1173
1615
  });
1174
- return t.publishEvent(e.userInfoAsync_error, i), null;
1616
+ return t.publishEvent(f.userInfoAsync_error, o), null;
1175
1617
  }
1176
1618
  return n.json();
1177
1619
  })();
1178
- return t.userInfo = s, s && t.configuration.storage?.setItem(`oidc.${t.configurationName}.userInfo`, JSON.stringify(s)), s;
1179
- } catch (n) {
1180
- let r = f(n) ? n : _(n) ? g(n, "userinfo") : n;
1181
- throw t.publishEvent(e.userInfoAsync_error, r), r;
1620
+ return t.userInfo = l, l && t.configuration.storage?.setItem(`oidc.${t.configurationName}.userInfo`, JSON.stringify(l)), l;
1621
+ } catch (e) {
1622
+ let n = i(e) ? e : l(e) ? c(e, "userinfo") : e;
1623
+ throw t.publishEvent(f.userInfoAsync_error, n), n;
1182
1624
  }
1183
- }, qe = () => fetch, Je = class {
1625
+ }, vt = () => fetch, yt = class {
1184
1626
  constructor(e) {
1185
1627
  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, this.pushedAuthorizationRequestEndpoint = e.pushed_authorization_request_endpoint, this.requirePushedAuthorizationRequests = e.require_pushed_authorization_requests ?? !1;
1186
1628
  }
1187
- }, V = {}, Ye = (e, t = new j()) => (n, r = "default") => (V[r] || (V[r] = new H(n, r, e, t)), V[r]), Xe = async (e) => {
1629
+ }, G = {}, bt = (e, t = new M()) => (n, r = "default") => (G[r] || (G[r] = new K(n, r, e, t)), G[r]), xt = async (e) => {
1188
1630
  let { parsedTokens: t, callbackPath: n, extras: r, scope: i } = await e.loginCallbackAsync();
1189
- return e.timeoutId = W(e, t.expiresAt, r, i), { callbackPath: n };
1190
- }, H = class t {
1191
- constructor(e, t = "default", n, r = new j()) {
1631
+ return e.timeoutId = q(e, t.expiresAt, r, i), { callbackPath: n };
1632
+ }, K = class t {
1633
+ constructor(e, t = "default", n, r = new M()) {
1192
1634
  this.isLoggingOut = !1, this.initPromise = null, this.tryKeepExistingSessionPromise = null, this.loginPromise = null, this.loginCallbackPromise = null, this.loginCallbackWithAutoTokensRenewPromise = null, this.userInfoPromise = null, this.renewTokensPromise = null, this.clearSessionPromise = null, this.logoutPromise = null;
1193
1635
  let i = e.silent_login_uri;
1194
1636
  e.silent_redirect_uri && !e.silent_login_uri && (i = `${e.silent_redirect_uri.replace("-callback", "").replace("callback", "")}-login`);
1195
1637
  let a = e.refresh_time_before_tokens_expiration_in_second ?? 120;
1196
- a > 60 && (a -= Math.floor(Math.random() * 40)), this.location = r ?? new j(), this.configuration = {
1638
+ a > 60 && (a -= Math.floor(Math.random() * 40)), this.location = r ?? new M(), this.configuration = {
1197
1639
  ...e,
1198
1640
  silent_login_uri: i,
1199
- token_automatic_renew_mode: e.token_automatic_renew_mode ?? B.AutomaticBeforeTokenExpiration,
1641
+ token_automatic_renew_mode: e.token_automatic_renew_mode ?? W.AutomaticBeforeTokenExpiration,
1200
1642
  monitor_session: e.monitor_session ?? !1,
1201
1643
  refresh_time_before_tokens_expiration_in_second: a,
1202
1644
  silent_login_timeout: e.silent_login_timeout ?? 12e3,
1203
- token_renew_mode: e.token_renew_mode ?? q.access_token_or_id_token_invalid,
1645
+ token_renew_mode: e.token_renew_mode ?? Y.access_token_or_id_token_invalid,
1204
1646
  demonstrating_proof_of_possession: e.demonstrating_proof_of_possession ?? !1,
1205
1647
  authority_timeout_wellknowurl_in_millisecond: e.authority_timeout_wellknowurl_in_millisecond ?? 1e4,
1206
1648
  logout_tokens_to_invalidate: e.logout_tokens_to_invalidate ?? ["access_token", "refresh_token"],
1207
- service_worker_activate: e.service_worker_activate ?? he,
1208
- demonstrating_proof_of_possession_configuration: e.demonstrating_proof_of_possession_configuration ?? k,
1649
+ service_worker_activate: e.service_worker_activate ?? me,
1650
+ demonstrating_proof_of_possession_configuration: e.demonstrating_proof_of_possession_configuration ?? O,
1209
1651
  preload_user_info: e.preload_user_info ?? !1,
1210
1652
  par: e.par ?? "disabled",
1211
1653
  par_request_timeout: e.par_request_timeout ?? 1e4
1212
- }, this.getFetch = n ?? qe, this.configurationName = t, this.tokens = null, this.userInfo = null, this.events = [], this.timeoutId = null, this.loginCallbackWithAutoTokensRenewAsync.bind(this), this.initAsync.bind(this), this.loginCallbackAsync.bind(this), this.subscribeEvents.bind(this), this.removeEventSubscription.bind(this), this.publishEvent.bind(this), this.destroyAsync.bind(this), this.logoutAsync.bind(this), this.renewTokensAsync.bind(this), this.renewTokensOrThrowAsync.bind(this), this.initAsync(this.configuration.authority, this.configuration.authority_configuration);
1654
+ }, this.getFetch = n ?? vt, this.configurationName = t, this.tokens = null, this.userInfo = null, this.events = [], this.timeoutId = null, this.resourceTokens = new ht(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.renewTokensOrThrowAsync.bind(this), this.initAsync(this.configuration.authority, this.configuration.authority_configuration);
1213
1655
  }
1214
1656
  subscribeEvents(e) {
1215
- let t = A(16);
1657
+ let t = se(16);
1216
1658
  return this.events.push({
1217
1659
  id: t,
1218
1660
  func: e
@@ -1228,10 +1670,10 @@ var he = () => {
1228
1670
  });
1229
1671
  }
1230
1672
  static {
1231
- this.getOrCreate = (e, t) => (n, r = "default") => Ye(e, t)(n, r);
1673
+ this.getOrCreate = (e, t) => (n, r = "default") => bt(e, t)(n, r);
1232
1674
  }
1233
1675
  static get(e = "default") {
1234
- return Object.prototype.hasOwnProperty.call(V, e) ? V[e] : null;
1676
+ return Object.prototype.hasOwnProperty.call(G, e) ? G[e] : null;
1235
1677
  }
1236
1678
  static getOrThrow(e = "default") {
1237
1679
  let n = t.get(e);
@@ -1240,36 +1682,38 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
1240
1682
  return n;
1241
1683
  }
1242
1684
  static {
1243
- this.eventNames = e;
1685
+ this.eventNames = f;
1244
1686
  }
1245
- _silentLoginCallbackFromIFrame() {
1687
+ _silentLoginCallbackFromIFrame(e = this.tokens, t) {
1246
1688
  if (this.configuration.silent_redirect_uri && this.configuration.silent_login_uri) {
1247
- let e = this.location, t = z(e.getCurrentHref());
1689
+ let n = this.location, r = V(n.getCurrentHref());
1248
1690
  window.parent.postMessage(`${this.configurationName}_oidc_tokens:${JSON.stringify({
1249
- tokens: this.tokens,
1250
- sessionState: t.session_state
1251
- })}`, e.getOrigin());
1691
+ tokens: e,
1692
+ resource: t,
1693
+ sessionState: r.session_state
1694
+ })}`, n.getOrigin());
1252
1695
  }
1253
1696
  }
1254
1697
  _silentLoginErrorCallbackFromIFrame(e = null) {
1255
1698
  if (this.configuration.silent_redirect_uri && this.configuration.silent_login_uri) {
1256
- let t = this.location, n = z(t.getCurrentHref());
1699
+ let t = this.location, n = V(t.getCurrentHref());
1257
1700
  if (n.error) {
1258
- let e = h(n.error, n.error_description, `Error from OIDC server: ${n.error} - ${n.error_description}`, "refresh");
1701
+ let e = s(n.error, n.error_description, `Error from OIDC server: ${n.error} - ${n.error_description}`, "refresh");
1259
1702
  window.parent.postMessage(`${this.configurationName}_oidc_error:${JSON.stringify({
1260
1703
  error: n.error,
1261
1704
  error_description: n.error_description,
1262
- oidcError: v(e)
1705
+ oidcError: u(e)
1263
1706
  })}`, t.getOrigin());
1264
1707
  } else window.parent.postMessage(`${this.configurationName}_oidc_exception:${JSON.stringify({
1265
1708
  error: e == null ? "" : e.toString(),
1266
- oidcError: f(e) ? v(e) : void 0
1709
+ oidcError: i(e) ? u(e) : void 0
1267
1710
  })}`, t.getOrigin());
1268
1711
  }
1269
1712
  }
1270
1713
  async silentLoginCallbackAsync() {
1271
1714
  try {
1272
- await this.loginCallbackAsync(!0), this._silentLoginCallbackFromIFrame();
1715
+ let e = this.configuration.resources?.length ? rt(this.configurationName, this.location.getCurrentHref()) : void 0, t = await this.loginCallbackAsync(!0);
1716
+ this._silentLoginCallbackFromIFrame(t.parsedTokens, e);
1273
1717
  } catch (e) {
1274
1718
  console.error(e), this._silentLoginErrorCallbackFromIFrame(e);
1275
1719
  }
@@ -1277,7 +1721,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
1277
1721
  async initAsync(e, t) {
1278
1722
  if (this.initPromise !== null) return this.initPromise;
1279
1723
  let n = async () => {
1280
- if (t != null) return new Je({
1724
+ if (t != null) return new yt({
1281
1725
  authorization_endpoint: t.authorization_endpoint,
1282
1726
  end_session_endpoint: t.end_session_endpoint,
1283
1727
  revocation_endpoint: t.revocation_endpoint,
@@ -1296,50 +1740,65 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
1296
1740
  });
1297
1741
  }
1298
1742
  async tryKeepExistingSessionAsync() {
1299
- return this.tryKeepExistingSessionPromise === null ? (this.tryKeepExistingSessionPromise = ge(this), this.tryKeepExistingSessionPromise.finally(() => {
1743
+ return this.tryKeepExistingSessionPromise === null ? (this.tryKeepExistingSessionPromise = he(this), this.tryKeepExistingSessionPromise.finally(() => {
1300
1744
  this.tryKeepExistingSessionPromise = null;
1301
1745
  })) : this.tryKeepExistingSessionPromise;
1302
1746
  }
1303
1747
  async startCheckSessionAsync(e, t, n, r = !1) {
1304
- await C(this, V, this.configuration)(e, t, n, r);
1748
+ await C(this, G, this.configuration)(e, t, n, r);
1305
1749
  }
1306
1750
  async loginAsync(e = void 0, t = null, n = !1, r = void 0, i = !1) {
1307
- return this.logoutPromise && await this.logoutPromise, this.loginPromise === null ? (this.loginPromise = i ? S(window, this.configurationName, this.configuration, this.publishEvent.bind(this), this)(t, r) : Ie(this.configurationName, this.configuration, this.publishEvent.bind(this), this.initAsync.bind(this), this.location, this.getFetch)(e, t, n, r), this.loginPromise.finally(() => {
1751
+ return this.logoutPromise && await this.logoutPromise, this.loginPromise === null ? (this.loginPromise = (async () => (t?._oidc_resource === void 0 && this.configuration.resources?.length && await this.resourceTokens.clearAllAsync(), i ? S(window, this.configurationName, this.configuration, this.publishEvent.bind(this), this)(t, r) : ot(this.configurationName, this.configuration, this.publishEvent.bind(this), this.initAsync.bind(this), this.location, this.getFetch)(e, t, n, r)))(), this.loginPromise.catch((e) => {
1752
+ throw n && this._silentLoginErrorCallbackFromIFrame(e), e;
1753
+ }).finally(() => {
1308
1754
  this.loginPromise = null;
1309
1755
  })) : this.loginPromise;
1310
1756
  }
1311
- async loginCallbackAsync(e = !1) {
1757
+ async loginCallbackAsync(n = !1) {
1312
1758
  if (this.loginCallbackPromise !== null) return this.loginCallbackPromise;
1313
- let n = async () => {
1314
- let n = await Le(this)(e), r = n.tokens;
1315
- return this.tokens = r, await $(this.configuration, this.configurationName) || i(this.configurationName, this.configuration.storage, this.configuration.login_state_storage ?? this.configuration.storage).setTokens(r), this.publishEvent(t.eventNames.token_acquired, r), this.configuration.preload_user_info && await this.userInfoAsync(), {
1316
- parsedTokens: r,
1317
- state: n.state,
1318
- callbackPath: n.callbackPath,
1319
- scope: n.scope,
1320
- extras: n.extras
1759
+ let i = async () => {
1760
+ let i = this.configuration.resources?.length ? rt(this.configurationName, this.location.getCurrentHref()) : void 0, a = await st(this)(n, i), o = a.tokens;
1761
+ if (i !== void 0) {
1762
+ if (rt(this.configurationName, this.location.getCurrentHref()) !== i) throw new r(e.RESOURCE_TOKEN_UNAVAILABLE, "The resource authorization was cleared.", {
1763
+ phase: "callback",
1764
+ retryable: !1
1765
+ });
1766
+ return await this.resourceTokens.acceptAuthorizationAsync(i, o), it(this.configurationName, this.location.getCurrentHref()), {
1767
+ parsedTokens: o,
1768
+ state: a.state,
1769
+ callbackPath: a.callbackPath,
1770
+ scope: a.scope,
1771
+ extras: a.extras
1772
+ };
1773
+ }
1774
+ return await this.resourceTokens.clearAllAsync(), this.tokens = o, await $(this.configuration, H(this.configurationName, i)) || g(this.configurationName, this.configuration.storage, this.configuration.login_state_storage ?? this.configuration.storage).setTokens(o), this.publishEvent(t.eventNames.token_acquired, o), this.configuration.preload_user_info && await this.userInfoAsync(), {
1775
+ parsedTokens: o,
1776
+ state: a.state,
1777
+ callbackPath: a.callbackPath,
1778
+ scope: a.scope,
1779
+ extras: a.extras
1321
1780
  };
1322
1781
  };
1323
- return this.loginCallbackPromise = n(), this.loginCallbackPromise.finally(() => {
1782
+ return this.loginCallbackPromise = i(), this.loginCallbackPromise.finally(() => {
1324
1783
  this.loginCallbackPromise = null;
1325
1784
  });
1326
1785
  }
1327
1786
  async generateDemonstrationOfProofOfPossessionAsync(e, t, n, r = {}) {
1328
- let a = this.configuration, o = {
1329
- ath: await ue(e),
1787
+ let i = this.configuration, a = {
1788
+ ath: await le(e),
1330
1789
  ...r
1331
1790
  };
1332
- if (await $(a, this.configurationName)) return `DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${this.configurationName}#tabId=${mt(this.configurationName)}`;
1333
- let s = i(this.configurationName, a.storage, a.login_state_storage ?? a.storage), c = await s.getDemonstratingProofOfPossessionJwkAsync(), l = s.getDemonstratingProofOfPossessionNonce();
1334
- return l && (o.nonce = l), await ie(window)(a.demonstrating_proof_of_possession_configuration)(c, n, t, o);
1791
+ if (await $(i, this.configurationName)) return `DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${this.configurationName}#tabId=${Ut(this.configurationName)}`;
1792
+ let o = g(this.configurationName, i.storage, i.login_state_storage ?? i.storage), s = await o.getDemonstratingProofOfPossessionJwkAsync(), c = o.getDemonstratingProofOfPossessionNonce();
1793
+ return c && (a.nonce = c), await ne(window)(i.demonstrating_proof_of_possession_configuration)(s, n, t, a);
1335
1794
  }
1336
1795
  loginCallbackWithAutoTokensRenewAsync() {
1337
- return this.loginCallbackWithAutoTokensRenewPromise === null ? (this.loginCallbackWithAutoTokensRenewPromise = Xe(this), this.loginCallbackWithAutoTokensRenewPromise.finally(() => {
1796
+ return this.loginCallbackWithAutoTokensRenewPromise === null ? (this.loginCallbackWithAutoTokensRenewPromise = xt(this), this.loginCallbackWithAutoTokensRenewPromise.finally(() => {
1338
1797
  this.loginCallbackWithAutoTokensRenewPromise = null;
1339
1798
  })) : this.loginCallbackWithAutoTokensRenewPromise;
1340
1799
  }
1341
1800
  userInfoAsync(e = !1, t = !1) {
1342
- return this.userInfoPromise === null ? (this.userInfoPromise = Ke(this)(e, t), this.userInfoPromise.finally(() => {
1801
+ return this.userInfoPromise === null ? (this.userInfoPromise = _t(this)(e, t), this.userInfoPromise.finally(() => {
1343
1802
  this.userInfoPromise = null;
1344
1803
  })) : this.userInfoPromise;
1345
1804
  }
@@ -1347,7 +1806,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
1347
1806
  if (this.renewTokensPromise !== null) return this.renewTokensPromise;
1348
1807
  if (!this.timeoutId) return null;
1349
1808
  b.clearTimeout(this.timeoutId);
1350
- let n = Qe(this, !0, e, t);
1809
+ let n = wt(this, !0, e, t);
1351
1810
  return this.renewTokensPromise = n, n.finally(() => {
1352
1811
  this.renewTokensPromise === n && (this.renewTokensPromise = null);
1353
1812
  });
@@ -1355,67 +1814,67 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
1355
1814
  async renewTokensAsync(e = null, t = null) {
1356
1815
  return (await this.renewTokensResultAsync(e, t))?.tokens;
1357
1816
  }
1358
- async renewTokensOrThrowAsync(e = null, t = null) {
1359
- let n = await this.renewTokensResultAsync(e, t);
1360
- if (n?.error) throw n.error;
1361
- if (!n?.tokens) throw new d(c.TOKEN_REQUEST_FAILED, "Token renewal failed", {
1817
+ async renewTokensOrThrowAsync(t = null, n = null) {
1818
+ let i = await this.renewTokensResultAsync(t, n);
1819
+ if (i?.error) throw i.error;
1820
+ if (!i?.tokens) throw new r(e.TOKEN_REQUEST_FAILED, "Token renewal failed", {
1362
1821
  phase: "refresh",
1363
1822
  retryable: !1
1364
1823
  });
1365
- return n.tokens;
1824
+ return i.tokens;
1366
1825
  }
1367
1826
  async destroyAsync(e) {
1368
- return await Ve(this)(e);
1827
+ return await dt(this)(e);
1369
1828
  }
1370
1829
  async clearSessionAsync() {
1371
- return this.clearSessionPromise ? this.clearSessionPromise : (this.clearSessionPromise = He(this, V)(), this.clearSessionPromise.finally(() => {
1830
+ return this.clearSessionPromise ? this.clearSessionPromise : (this.clearSessionPromise = ft(this, G)(), this.clearSessionPromise.finally(() => {
1372
1831
  this.clearSessionPromise = null;
1373
1832
  }));
1374
1833
  }
1375
- async logoutSameTabAsync(t, n) {
1376
- this.configuration.monitor_session && this.configuration.client_id === t && n && this.tokens && this.tokens.idTokenPayload && this.tokens.idTokenPayload.sub === n && (await this.destroyAsync("LOGGED_OUT"), this.publishEvent(e.logout_from_same_tab, {
1834
+ async logoutSameTabAsync(e, t) {
1835
+ this.configuration.monitor_session && this.configuration.client_id === e && t && this.tokens && this.tokens.idTokenPayload && this.tokens.idTokenPayload.sub === t && (await this.destroyAsync("LOGGED_OUT"), this.publishEvent(f.logout_from_same_tab, {
1377
1836
  mmessage: "SessionMonitor",
1378
- sub: n
1837
+ sub: t
1379
1838
  }));
1380
1839
  }
1381
- async logoutOtherTabAsync(t, n) {
1382
- this.configuration.monitor_session && this.configuration.client_id === t && n && this.tokens && this.tokens.idTokenPayload && this.tokens.idTokenPayload.sub === n && (await this.destroyAsync("LOGGED_OUT"), this.publishEvent(e.logout_from_another_tab, {
1840
+ async logoutOtherTabAsync(e, t) {
1841
+ this.configuration.monitor_session && this.configuration.client_id === e && t && this.tokens && this.tokens.idTokenPayload && this.tokens.idTokenPayload.sub === t && (await this.destroyAsync("LOGGED_OUT"), this.publishEvent(f.logout_from_another_tab, {
1383
1842
  message: "SessionMonitor",
1384
- sub: n
1843
+ sub: t
1385
1844
  }));
1386
1845
  }
1387
1846
  async logoutAsync(e = void 0, t = null) {
1388
- return this.logoutPromise ? this.logoutPromise : (this.logoutPromise = We(this, V, this.getFetch(), console, this.location)(e, t), this.logoutPromise.finally(() => {
1847
+ return this.logoutPromise ? this.logoutPromise : (this.logoutPromise = mt(this, G, this.getFetch(), console, this.location)(e, t), this.logoutPromise.finally(() => {
1389
1848
  this.logoutPromise = null;
1390
1849
  }));
1391
1850
  }
1392
- }, U = (e, t) => {
1393
- let n = t?.oauthError === "use_dpop_nonce" ? c.DPOP_NONCE_REQUIRED : c.TOKEN_REQUEST_FAILED;
1394
- return new d(n, e, {
1851
+ }, St = (t, n) => {
1852
+ let i = n?.oauthError === "use_dpop_nonce" ? e.DPOP_NONCE_REQUIRED : e.TOKEN_REQUEST_FAILED;
1853
+ return new r(i, t, {
1395
1854
  phase: "refresh",
1396
- retryable: n === c.DPOP_NONCE_REQUIRED || p(t?.status),
1397
- status: t?.status,
1398
- oauthError: t?.oauthError,
1399
- oauthErrorDescription: t?.oauthErrorDescription
1855
+ retryable: i === e.DPOP_NONCE_REQUIRED || a(n?.status),
1856
+ status: n?.status,
1857
+ oauthError: n?.oauthError,
1858
+ oauthErrorDescription: n?.oauthErrorDescription
1400
1859
  });
1401
1860
  };
1402
- async function Ze(e, t, n, r = null) {
1861
+ async function Ct(e, t, n, r = null) {
1403
1862
  let a = (t) => {
1404
1863
  e.tokens = t;
1405
1864
  };
1406
- e.publishEvent(H.eventNames.syncTokensAsync_begin, {});
1865
+ e.publishEvent(K.eventNames.syncTokensAsync_begin, {});
1407
1866
  let o;
1408
1867
  try {
1409
- o = await K(e)(a, 0, 0, t, n, r);
1868
+ o = await Dt(e)(a, 0, 0, t, n, r);
1410
1869
  } catch (t) {
1411
- throw e.publishEvent(H.eventNames.syncTokensAsync_error, {
1870
+ throw e.publishEvent(K.eventNames.syncTokensAsync_error, {
1412
1871
  message: "sync tokens error",
1413
- error: f(t) ? t : void 0,
1872
+ error: i(t) ? t : void 0,
1414
1873
  exception: t
1415
1874
  }), t;
1416
1875
  }
1417
1876
  let { tokens: s, status: c } = o;
1418
- return e.publishEvent(H.eventNames.syncTokensAsync_end, { status: c }), await $(e.configuration, e.configurationName) || i(e.configurationName, e.configuration.storage, e.configuration.login_state_storage ?? e.configuration.storage).setTokens(e.tokens), e.tokens ? {
1877
+ return e.publishEvent(K.eventNames.syncTokensAsync_end, { status: c }), await $(e.configuration, e.configurationName) || g(e.configurationName, e.configuration.storage, e.configuration.login_state_storage ?? e.configuration.storage).setTokens(e.tokens), e.tokens ? {
1419
1878
  ...o,
1420
1879
  tokens: s
1421
1880
  } : (await e.destroyAsync(c), {
@@ -1423,29 +1882,30 @@ async function Ze(e, t, n, r = null) {
1423
1882
  tokens: null
1424
1883
  });
1425
1884
  }
1426
- async function Qe(e, t = !1, n = null, r = null) {
1885
+ async function wt(e, t = !1, n = null, r = null) {
1427
1886
  let i = e.configuration, a = `${i.client_id}_${e.configurationName}_${i.authority}`, o, s = await $(e.configuration, e.configurationName);
1428
- if (i?.storage === window?.sessionStorage && !s || !navigator.locks) o = await Ze(e, t, n, r);
1887
+ if (i.resources?.length && e.resourceTokens) o = await e.resourceTokens.withRefreshLockAsync(() => Ct(e, t, n, r));
1888
+ else if (i?.storage === window?.sessionStorage && !s || !navigator.locks) o = await Ct(e, t, n, r);
1429
1889
  else {
1430
1890
  let i = "retry";
1431
- for (; i === "retry";) i = await navigator.locks.request(a, { ifAvailable: !0 }, async (i) => i ? await Ze(e, t, n, r) : (e.publishEvent(H.eventNames.syncTokensAsync_lock_not_available, { lock: "lock not available" }), "retry"));
1891
+ for (; i === "retry";) i = await navigator.locks.request(a, { ifAvailable: !0 }, async (i) => i ? await Ct(e, t, n, r) : (e.publishEvent(K.eventNames.syncTokensAsync_lock_not_available, { lock: "lock not available" }), "retry"));
1432
1892
  o = i;
1433
1893
  }
1434
- return o.tokens ? (e.timeoutId &&= W(e, e.tokens.expiresAt, n, r), {
1894
+ return o.tokens ? (e.timeoutId &&= q(e, e.tokens.expiresAt, n, r), {
1435
1895
  ...o,
1436
1896
  tokens: e.tokens
1437
1897
  }) : o;
1438
1898
  }
1439
- async function $e(e, t = !1, n = null, r = null) {
1440
- return (await Qe(e, t, n, r)).tokens;
1899
+ async function Tt(e, t = !1, n = null, r = null) {
1900
+ return (await wt(e, t, n, r)).tokens;
1441
1901
  }
1442
- var W = (e, t, n = null, r = null) => {
1902
+ var q = (e, t, n = null, r = null) => {
1443
1903
  let i = e.configuration.refresh_time_before_tokens_expiration_in_second;
1444
1904
  return e.timeoutId && b.clearTimeout(e.timeoutId), b.setTimeout(async () => {
1445
- let a = { timeLeft: J(i, t) };
1446
- e.publishEvent(H.eventNames.token_timer, a), await $e(e, !1, n, r);
1905
+ let a = { timeLeft: X(i, t) };
1906
+ e.publishEvent(K.eventNames.token_timer, a), await Tt(e, !1, n, r);
1447
1907
  }, 1e3);
1448
- }, G = {
1908
+ }, J = {
1449
1909
  FORCE_REFRESH: "FORCE_REFRESH",
1450
1910
  SESSION_LOST: "SESSION_LOST",
1451
1911
  NOT_CONNECTED: "NOT_CONNECTED",
@@ -1455,297 +1915,297 @@ var W = (e, t, n = null, r = null) => {
1455
1915
  LOGOUT_FROM_ANOTHER_TAB: "LOGOUT_FROM_ANOTHER_TAB",
1456
1916
  REQUIRE_SYNC_TOKENS: "REQUIRE_SYNC_TOKENS",
1457
1917
  TOKENS_INVALID: "TOKENS_INVALID"
1458
- }, et = (e) => async (t, n, r, a = !1) => {
1459
- let o = { nonce: null };
1918
+ }, Et = (e) => async (t, n, r, i = !1) => {
1919
+ let a = { nonce: null };
1460
1920
  if (!r) return {
1461
1921
  tokens: null,
1462
- status: G.NOT_CONNECTED,
1463
- nonce: o
1922
+ status: J.NOT_CONNECTED,
1923
+ nonce: a
1464
1924
  };
1465
- let s, c = await e.initAsync(t.authority, t.authority_configuration), l = await $(t, n);
1466
- if (l) {
1467
- let { status: e, tokens: n } = await l.initAsync(c, "syncTokensAsync", t);
1925
+ let o, s = await e.initAsync(t.authority, t.authority_configuration), c = await $(t, n);
1926
+ if (c) {
1927
+ let { status: e, tokens: n } = await c.initAsync(s, "syncTokensAsync", t);
1468
1928
  if (e === "LOGGED_OUT") return {
1469
1929
  tokens: null,
1470
- status: G.LOGOUT_FROM_ANOTHER_TAB,
1471
- nonce: o
1930
+ status: J.LOGOUT_FROM_ANOTHER_TAB,
1931
+ nonce: a
1472
1932
  };
1473
1933
  if (e === "SESSIONS_LOST") return {
1474
1934
  tokens: null,
1475
- status: G.SESSION_LOST,
1476
- nonce: o
1935
+ status: J.SESSION_LOST,
1936
+ nonce: a
1477
1937
  };
1478
1938
  if (!e || !n) return {
1479
1939
  tokens: null,
1480
- status: G.REQUIRE_SYNC_TOKENS,
1481
- nonce: o
1940
+ status: J.REQUIRE_SYNC_TOKENS,
1941
+ nonce: a
1482
1942
  };
1483
1943
  if (n.issuedAt !== r.issuedAt) return {
1484
1944
  tokens: n,
1485
- status: J(t.refresh_time_before_tokens_expiration_in_second, n.expiresAt) > 0 ? G.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID : G.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID,
1486
- nonce: await l.getNonceAsync()
1945
+ status: X(t.refresh_time_before_tokens_expiration_in_second, n.expiresAt) > 0 ? J.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID : J.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID,
1946
+ nonce: await c.getNonceAsync()
1487
1947
  };
1488
- s = await l.getNonceAsync();
1948
+ o = await c.getNonceAsync();
1489
1949
  } else {
1490
- let a = i(n, t.storage ?? sessionStorage, t.login_state_storage ?? t.storage ?? sessionStorage), c = await a.initAsync(), { tokens: l } = c, { status: u } = c;
1491
- if (l &&= at(l, e.tokens, t.token_renew_mode), !l) return {
1950
+ let i = g(n, t.storage ?? sessionStorage, t.login_state_storage ?? t.storage ?? sessionStorage), s = await i.initAsync(), { tokens: c } = s, { status: l } = s;
1951
+ if (c &&= Mt(c, e.tokens, t.token_renew_mode), !c) return {
1492
1952
  tokens: null,
1493
- status: G.LOGOUT_FROM_ANOTHER_TAB,
1494
- nonce: o
1953
+ status: J.LOGOUT_FROM_ANOTHER_TAB,
1954
+ nonce: a
1495
1955
  };
1496
- if (u === "SESSIONS_LOST") return {
1956
+ if (l === "SESSIONS_LOST") return {
1497
1957
  tokens: null,
1498
- status: G.SESSION_LOST,
1499
- nonce: o
1958
+ status: J.SESSION_LOST,
1959
+ nonce: a
1500
1960
  };
1501
- if (l.issuedAt !== r.issuedAt) {
1502
- let e = J(t.refresh_time_before_tokens_expiration_in_second, l.expiresAt) > 0 ? G.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID : G.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID, n = await a.getNonceAsync();
1961
+ if (c.issuedAt !== r.issuedAt) {
1962
+ let e = X(t.refresh_time_before_tokens_expiration_in_second, c.expiresAt) > 0 ? J.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID : J.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID, n = await i.getNonceAsync();
1503
1963
  return {
1504
- tokens: l,
1964
+ tokens: c,
1505
1965
  status: e,
1506
1966
  nonce: n
1507
1967
  };
1508
1968
  }
1509
- s = await a.getNonceAsync();
1969
+ o = await i.getNonceAsync();
1510
1970
  }
1511
- let u = J(t.refresh_time_before_tokens_expiration_in_second, r.expiresAt) > 0 ? "TOKENS_VALID" : "TOKENS_INVALID";
1512
- return a ? {
1971
+ let l = X(t.refresh_time_before_tokens_expiration_in_second, r.expiresAt) > 0 ? "TOKENS_VALID" : "TOKENS_INVALID";
1972
+ return i ? {
1513
1973
  tokens: r,
1514
1974
  status: "FORCE_REFRESH",
1515
- nonce: s
1975
+ nonce: o
1516
1976
  } : {
1517
1977
  tokens: r,
1518
- status: u,
1519
- nonce: s
1978
+ status: l,
1979
+ nonce: o
1520
1980
  };
1521
- }, K = (t) => async (n, r = 0, a = 0, o = !1, s = null, l = null, u = null) => {
1981
+ }, Dt = (t) => async (n, a = 0, o = 0, s = !1, u = null, d = null, p = null) => {
1522
1982
  if (!navigator.onLine && document.hidden) return {
1523
1983
  tokens: t.tokens,
1524
1984
  status: "GIVE_UP"
1525
1985
  };
1526
- let p = 6, m = o ? 2 : 5;
1527
- for (; !navigator.onLine && p > 0;) await X({ milliseconds: 1e3 }), p--, t.publishEvent(e.refreshTokensAsync, { message: `wait because navigator is offline try ${p}` });
1528
- let h = document.hidden, v = h ? r : r + 1, y = h ? a + 1 : a;
1529
- if (r >= m || a >= 5) {
1986
+ let m = 6, h = s ? 2 : 5;
1987
+ for (; !navigator.onLine && m > 0;) await Bt({ milliseconds: 1e3 }), m--, t.publishEvent(f.refreshTokensAsync, { message: `wait because navigator is offline try ${m}` });
1988
+ let _ = document.hidden, v = _ ? a : a + 1, y = _ ? o + 1 : o;
1989
+ if (a >= h || o >= 5) {
1530
1990
  n(null);
1531
- let r = u ?? U("refresh token");
1532
- return t.publishEvent(e.refreshTokensAsync_error, {
1991
+ let e = p ?? St("refresh token");
1992
+ return t.publishEvent(f.refreshTokensAsync_error, {
1533
1993
  message: "refresh token",
1534
- error: r
1994
+ error: e
1535
1995
  }), {
1536
1996
  tokens: null,
1537
1997
  status: "SESSION_LOST",
1538
- error: r
1998
+ error: e
1539
1999
  };
1540
2000
  }
1541
- s ||= {};
2001
+ u ||= {};
1542
2002
  let b = t.configuration, S = (e, n = null, r = null) => x(t.configurationName, t.configuration, t.publishEvent.bind(t), "refresh")(e, n, r), C = async () => {
1543
2003
  try {
1544
- let r, a = await $(b, t.configurationName);
1545
- r = a ? a.getLoginParams() : i(t.configurationName, b.storage, b.login_state_storage ?? b.storage).getLoginParams();
2004
+ let i, a = await $(b, t.configurationName);
2005
+ i = a ? a.getLoginParams() : g(t.configurationName, b.storage, b.login_state_storage ?? b.storage).getLoginParams();
1546
2006
  let o = {};
1547
- if (r && r.extras) for (let [e, t] of Object.entries(r.extras)) t != null && (o[e] = t);
1548
- if (s) for (let [e, t] of Object.entries(s)) t != null && (o[e] = t);
1549
- o.prompt = "none", l && (o.scope = l);
1550
- let u = await S(o);
1551
- if (!u) {
2007
+ if (i && i.extras) for (let [e, t] of Object.entries(i.extras)) t != null && (o[e] = t);
2008
+ if (u) for (let [e, t] of Object.entries(u)) t != null && (o[e] = t);
2009
+ o.prompt = "none", d && (o.scope = d);
2010
+ let s = await S(o);
2011
+ if (!s) {
1552
2012
  n(null);
1553
- let r = U("refresh token silent not active");
1554
- return t.publishEvent(e.refreshTokensAsync_error, {
2013
+ let e = St("refresh token silent not active");
2014
+ return t.publishEvent(f.refreshTokensAsync_error, {
1555
2015
  message: "refresh token silent not active",
1556
- error: r
2016
+ error: e
1557
2017
  }), {
1558
2018
  tokens: null,
1559
2019
  status: "SESSION_LOST",
1560
- error: r
2020
+ error: e
1561
2021
  };
1562
2022
  }
1563
- if (u.error) {
2023
+ if (s.error) {
1564
2024
  n(null);
1565
- let r = u.oidcError ?? new d(c.OAUTH_ERROR, "refresh token silent", {
2025
+ let i = s.oidcError ?? new r(e.OAUTH_ERROR, "refresh token silent", {
1566
2026
  phase: "refresh",
1567
2027
  retryable: !1,
1568
- oauthError: u.error
2028
+ oauthError: s.error
1569
2029
  });
1570
- return t.publishEvent(e.refreshTokensAsync_error, {
2030
+ return t.publishEvent(f.refreshTokensAsync_error, {
1571
2031
  message: "refresh token silent",
1572
- error: r
2032
+ error: i
1573
2033
  }), {
1574
2034
  tokens: null,
1575
2035
  status: "SESSION_LOST",
1576
- error: r
2036
+ error: i
1577
2037
  };
1578
2038
  }
1579
- return n(u.tokens), t.publishEvent(H.eventNames.token_renewed, {}), {
1580
- tokens: u.tokens,
2039
+ return n(s.tokens), t.publishEvent(K.eventNames.token_renewed, {}), {
2040
+ tokens: s.tokens,
1581
2041
  status: "LOGGED"
1582
2042
  };
1583
- } catch (r) {
1584
- let i = f(r) || !_(r) ? r : g(r, "refresh");
1585
- return console.error(i), t.publishEvent(e.refreshTokensAsync_silent_error, {
2043
+ } catch (e) {
2044
+ let r = i(e) || !l(e) ? e : c(e, "refresh");
2045
+ return console.error(r), t.publishEvent(f.refreshTokensAsync_silent_error, {
1586
2046
  message: "exceptionSilent",
1587
- exception: i.message,
1588
- error: f(i) ? i : void 0
1589
- }), await K(t)(n, v, y, o, s, l, f(i) ? i : u);
2047
+ exception: r.message,
2048
+ error: i(r) ? r : void 0
2049
+ }), await Dt(t)(n, v, y, s, u, d, i(r) ? r : p);
1590
2050
  }
1591
2051
  };
1592
2052
  try {
1593
- let { status: f, tokens: p, nonce: m } = await et(t)(b, t.configurationName, t.tokens, o);
1594
- switch (f) {
1595
- case G.SESSION_LOST:
2053
+ let { status: i, tokens: c, nonce: l } = await Et(t)(b, t.configurationName, t.tokens, s);
2054
+ switch (i) {
2055
+ case J.SESSION_LOST:
1596
2056
  n(null);
1597
2057
  {
1598
- let n = u ?? U("refresh token session lost");
1599
- return t.publishEvent(e.refreshTokensAsync_error, {
2058
+ let e = p ?? St("refresh token session lost");
2059
+ return t.publishEvent(f.refreshTokensAsync_error, {
1600
2060
  message: "refresh token session lost",
1601
- error: n
2061
+ error: e
1602
2062
  }), {
1603
2063
  tokens: null,
1604
2064
  status: "SESSION_LOST",
1605
- error: n
2065
+ error: e
1606
2066
  };
1607
2067
  }
1608
- case G.NOT_CONNECTED: return n(null), {
2068
+ case J.NOT_CONNECTED: return n(null), {
1609
2069
  tokens: null,
1610
2070
  status: null
1611
2071
  };
1612
- case G.TOKENS_VALID: return n(p), {
1613
- tokens: p,
2072
+ case J.TOKENS_VALID: return n(c), {
2073
+ tokens: c,
1614
2074
  status: "LOGGED_IN"
1615
2075
  };
1616
- case G.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID: return n(p), t.publishEvent(H.eventNames.token_renewed, { reason: "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID" }), {
1617
- tokens: p,
2076
+ case J.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID: return n(c), t.publishEvent(K.eventNames.token_renewed, { reason: "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID" }), {
2077
+ tokens: c,
1618
2078
  status: "LOGGED_IN"
1619
2079
  };
1620
- case G.LOGOUT_FROM_ANOTHER_TAB: return n(null), t.publishEvent(e.logout_from_another_tab, { status: "session syncTokensAsync" }), {
2080
+ case J.LOGOUT_FROM_ANOTHER_TAB: return n(null), t.publishEvent(f.logout_from_another_tab, { status: "session syncTokensAsync" }), {
1621
2081
  tokens: null,
1622
2082
  status: "LOGGED_OUT"
1623
2083
  };
1624
- case G.REQUIRE_SYNC_TOKENS: return b.token_automatic_renew_mode == B.AutomaticOnlyWhenFetchExecuted && !o ? (t.publishEvent(e.tokensInvalidAndWaitingActionsToRefresh, {}), {
2084
+ case J.REQUIRE_SYNC_TOKENS: return b.token_automatic_renew_mode == W.AutomaticOnlyWhenFetchExecuted && !s ? (t.publishEvent(f.tokensInvalidAndWaitingActionsToRefresh, {}), {
1625
2085
  tokens: t.tokens,
1626
2086
  status: "GIVE_UP"
1627
- }) : (t.publishEvent(e.refreshTokensAsync_begin, { tryNumber: r }), await C());
2087
+ }) : (t.publishEvent(f.refreshTokensAsync_begin, { tryNumber: a }), await C());
1628
2088
  default: {
1629
- if (b.token_automatic_renew_mode == B.AutomaticOnlyWhenFetchExecuted && G.FORCE_REFRESH !== f) return t.publishEvent(e.tokensInvalidAndWaitingActionsToRefresh, {}), {
2089
+ if (b.token_automatic_renew_mode == W.AutomaticOnlyWhenFetchExecuted && J.FORCE_REFRESH !== i) return t.publishEvent(f.tokensInvalidAndWaitingActionsToRefresh, {}), {
1630
2090
  tokens: t.tokens,
1631
2091
  status: "GIVE_UP"
1632
2092
  };
1633
- if (t.publishEvent(e.refreshTokensAsync_begin, {
1634
- refreshToken: p.refreshToken,
1635
- status: f,
1636
- tryNumber: r,
1637
- backgroundTry: a
1638
- }), !p.refreshToken) return await C();
1639
- let u = b.client_id, h = b.redirect_uri, g = b.authority, _ = { ...b.token_request_extras ? b.token_request_extras : {} };
1640
- for (let [e, t] of Object.entries(s)) e.endsWith(":token_request") && (_[e.replace(":token_request", "")] = t);
2093
+ if (t.publishEvent(f.refreshTokensAsync_begin, {
2094
+ refreshToken: c.refreshToken,
2095
+ status: i,
2096
+ tryNumber: a,
2097
+ backgroundTry: o
2098
+ }), !c.refreshToken) return await C();
2099
+ let p = b.client_id, m = b.redirect_uri, h = b.authority, _ = { ...b.token_request_extras ? b.token_request_extras : {} };
2100
+ for (let [e, t] of Object.entries(u)) e.endsWith(":token_request") && (_[e.replace(":token_request", "")] = t);
1641
2101
  return await (async () => {
1642
- let r = {
1643
- client_id: u,
1644
- redirect_uri: h,
2102
+ let i = tt({
2103
+ client_id: p,
2104
+ redirect_uri: m,
1645
2105
  grant_type: "refresh_token",
1646
- refresh_token: p.refreshToken
1647
- }, a = await t.initAsync(g, b.authority_configuration), f = document.hidden ? 1e4 : 3e5, x = a.tokenEndpoint, S = {};
1648
- b.demonstrating_proof_of_possession && (S.DPoP = await t.generateDemonstrationOfProofOfPossessionAsync(p.accessToken, x, "POST"));
1649
- let C = await Ae(t.getFetch())(x, r, _, p, S, b.token_renew_mode, f);
2106
+ refresh_token: c.refreshToken
2107
+ }, b), a = await t.initAsync(h, b.authority_configuration), o = document.hidden ? 1e4 : 3e5, x = a.tokenEndpoint, S = {};
2108
+ b.demonstrating_proof_of_possession && (S.DPoP = await t.generateDemonstrationOfProofOfPossessionAsync(c.accessToken, x, "POST"));
2109
+ let C = await ke(t.getFetch())(x, i, tt(_, b), c, S, b.token_renew_mode, o);
1650
2110
  if (!C.success && C.oauthError === "use_dpop_nonce" && C.demonstratingProofOfPossessionNonce && b.demonstrating_proof_of_possession) {
1651
2111
  let e = await $(b, t.configurationName);
1652
- e ? await e.setDemonstratingProofOfPossessionNonce(C.demonstratingProofOfPossessionNonce) : await i(t.configurationName, b.storage, b.login_state_storage ?? b.storage).setDemonstratingProofOfPossessionNonce(C.demonstratingProofOfPossessionNonce), S.DPoP = await t.generateDemonstrationOfProofOfPossessionAsync(p.accessToken, x, "POST"), C = await Ae(t.getFetch())(x, r, _, p, S, b.token_renew_mode, f);
2112
+ e ? await e.setDemonstratingProofOfPossessionNonce(C.demonstratingProofOfPossessionNonce) : await g(t.configurationName, b.storage, b.login_state_storage ?? b.storage).setDemonstratingProofOfPossessionNonce(C.demonstratingProofOfPossessionNonce), S.DPoP = await t.generateDemonstrationOfProofOfPossessionAsync(c.accessToken, x, "POST"), C = await ke(t.getFetch())(x, i, _, c, S, b.token_renew_mode, o);
1653
2113
  }
1654
2114
  if (C.success) {
1655
- if (!m || !m.nonce) {
2115
+ if (!l || !l.nonce) {
1656
2116
  n(null);
1657
- let r = new N(M.NONCE_MISSING, "refresh token: nonce missing from storage", "refresh");
1658
- return t.publishEvent(e.refreshTokensAsync_error, {
2117
+ let e = new P(N.NONCE_MISSING, "refresh token: nonce missing from storage", "refresh");
2118
+ return t.publishEvent(f.refreshTokensAsync_error, {
1659
2119
  message: "refresh token: nonce missing from storage",
1660
- error: r
2120
+ error: e
1661
2121
  }), {
1662
2122
  tokens: null,
1663
2123
  status: "SESSION_LOST",
1664
- error: r
2124
+ error: e
1665
2125
  };
1666
2126
  }
1667
- let { isValid: r, reason: o } = lt(C.data, m.nonce, a);
1668
- if (!r) {
2127
+ let { isValid: i, reason: o } = It(C.data, l.nonce, a);
2128
+ if (!i) {
1669
2129
  n(null);
1670
- let r = new d(o.startsWith("Nonce does not match") ? c.INVALID_NONCE : c.TOKEN_REQUEST_FAILED, `refresh token return not valid tokens, reason: ${o}`, {
2130
+ let i = new r(o.startsWith("Nonce does not match") ? e.INVALID_NONCE : e.TOKEN_REQUEST_FAILED, `refresh token return not valid tokens, reason: ${o}`, {
1671
2131
  phase: "refresh",
1672
2132
  retryable: !1
1673
2133
  });
1674
- return t.publishEvent(e.refreshTokensAsync_error, {
2134
+ return t.publishEvent(f.refreshTokensAsync_error, {
1675
2135
  message: `refresh token return not valid tokens, reason: ${o}`,
1676
- error: r
2136
+ error: i
1677
2137
  }), {
1678
2138
  tokens: null,
1679
2139
  status: "SESSION_LOST",
1680
- error: r
2140
+ error: i
1681
2141
  };
1682
2142
  }
1683
2143
  if (n(C.data), C.demonstratingProofOfPossessionNonce) {
1684
2144
  let e = await $(b, t.configurationName);
1685
- e ? await e.setDemonstratingProofOfPossessionNonce(C.demonstratingProofOfPossessionNonce) : await i(t.configurationName, b.storage, b.login_state_storage ?? b.storage).setDemonstratingProofOfPossessionNonce(C.demonstratingProofOfPossessionNonce);
2145
+ e ? await e.setDemonstratingProofOfPossessionNonce(C.demonstratingProofOfPossessionNonce) : await g(t.configurationName, b.storage, b.login_state_storage ?? b.storage).setDemonstratingProofOfPossessionNonce(C.demonstratingProofOfPossessionNonce);
1686
2146
  }
1687
- return t.publishEvent(e.refreshTokensAsync_end, { success: C.success }), t.publishEvent(H.eventNames.token_renewed, { reason: "REFRESH_TOKEN" }), {
2147
+ return t.publishEvent(f.refreshTokensAsync_end, { success: C.success }), t.publishEvent(K.eventNames.token_renewed, { reason: "REFRESH_TOKEN" }), {
1688
2148
  tokens: C.data,
1689
2149
  status: "LOGGED_IN"
1690
2150
  };
1691
2151
  }
1692
2152
  {
1693
- let r = U("Token request failed", C);
1694
- return t.publishEvent(e.refreshTokensAsync_silent_error, {
2153
+ let e = St("Token request failed", C);
2154
+ return t.publishEvent(f.refreshTokensAsync_silent_error, {
1695
2155
  message: "bad request",
1696
2156
  tokenResponse: C,
1697
- error: r
1698
- }), C.status >= 400 && C.status < 500 ? (n(null), t.publishEvent(e.refreshTokensAsync_error, {
2157
+ error: e
2158
+ }), C.status >= 400 && C.status < 500 ? (n(null), t.publishEvent(f.refreshTokensAsync_error, {
1699
2159
  message: `session lost: ${C.status}`,
1700
- error: r
2160
+ error: e
1701
2161
  }), {
1702
2162
  tokens: null,
1703
2163
  status: "SESSION_LOST",
1704
- error: r
1705
- }) : await K(t)(n, v, y, o, s, l, r);
2164
+ error: e
2165
+ }) : await Dt(t)(n, v, y, s, u, d, e);
1706
2166
  }
1707
2167
  })();
1708
2168
  }
1709
2169
  }
1710
- } catch (r) {
1711
- let i = f(r) || !_(r) ? r : g(r, "refresh");
1712
- return console.error(i), t.publishEvent(e.refreshTokensAsync_silent_error, {
2170
+ } catch (e) {
2171
+ let r = i(e) || !l(e) ? e : c(e, "refresh");
2172
+ return console.error(r), t.publishEvent(f.refreshTokensAsync_silent_error, {
1713
2173
  message: "exception",
1714
- exception: i.message,
1715
- error: f(i) ? i : void 0
1716
- }), new Promise((e, r) => {
2174
+ exception: r.message,
2175
+ error: i(r) ? r : void 0
2176
+ }), new Promise((e, a) => {
1717
2177
  setTimeout(() => {
1718
- K(t)(n, v, y, o, s, l, f(i) ? i : u).then(e).catch(r);
2178
+ Dt(t)(n, v, y, s, u, d, i(r) ? r : p).then(e).catch(a);
1719
2179
  }, 1e3);
1720
2180
  });
1721
2181
  }
1722
- }, tt = (e) => decodeURIComponent(Array.prototype.map.call(atob(e), (e) => "%" + ("00" + e.charCodeAt(0).toString(16)).slice(-2)).join("")), nt = (e) => JSON.parse(tt(e.replaceAll(/-/g, "+").replaceAll(/_/g, "/"))), rt = (e) => {
2182
+ }, Ot = (e) => decodeURIComponent(Array.prototype.map.call(atob(e), (e) => "%" + ("00" + e.charCodeAt(0).toString(16)).slice(-2)).join("")), kt = (e) => JSON.parse(Ot(e.replaceAll(/-/g, "+").replaceAll(/_/g, "/"))), At = (e) => {
1723
2183
  try {
1724
2184
  if (!e) return null;
1725
2185
  let t = e.split(".");
1726
- return t.length === 3 ? nt(t[1]) : null;
2186
+ return t.length === 3 ? kt(t[1]) : null;
1727
2187
  } catch (e) {
1728
2188
  console.warn(e);
1729
2189
  }
1730
2190
  return null;
1731
- }, q = {
2191
+ }, Y = {
1732
2192
  access_token_or_id_token_invalid: "access_token_or_id_token_invalid",
1733
2193
  access_token_invalid: "access_token_invalid",
1734
2194
  id_token_invalid: "id_token_invalid"
1735
2195
  };
1736
- function it(e, t, n) {
2196
+ function jt(e, t, n) {
1737
2197
  return e.issuedAt ? typeof e.issuedAt == "string" ? parseInt(e.issuedAt, 10) : e.issuedAt : t && t.iat ? t.iat : n && n.iat ? n.iat : (/* @__PURE__ */ new Date()).getTime() / 1e3;
1738
2198
  }
1739
- var at = (e, t = null, n) => {
2199
+ var Mt = (e, t = null, n) => {
1740
2200
  if (!e) return null;
1741
2201
  let r, i = typeof e.expiresIn == "string" ? parseInt(e.expiresIn, 10) : e.expiresIn;
1742
- r = e.accessTokenPayload === void 0 ? rt(e.accessToken) : e.accessTokenPayload;
2202
+ r = e.accessTokenPayload === void 0 ? At(e.accessToken) : e.accessTokenPayload;
1743
2203
  let a;
1744
2204
  a = t != null && "idToken" in t && !("idToken" in e) ? t.idToken : e.idToken;
1745
- let o = e.idTokenPayload ? e.idTokenPayload : rt(a), s = o && o.exp ? o.exp : Number.MAX_VALUE, c = r && r.exp ? r.exp : e.issuedAt + i;
1746
- e.issuedAt = it(e, r, o);
2205
+ let o = e.idTokenPayload ? e.idTokenPayload : At(a), s = o && o.exp ? o.exp : Number.MAX_VALUE, c = r && r.exp ? r.exp : e.issuedAt + i;
2206
+ e.issuedAt = jt(e, r, o);
1747
2207
  let l;
1748
- l = e.expiresAt ? e.expiresAt : n === q.access_token_invalid ? c : n === q.id_token_invalid || s < c ? s : c;
2208
+ l = e.expiresAt ? e.expiresAt : n === Y.access_token_invalid ? c : n === Y.id_token_invalid || s < c ? s : c;
1749
2209
  let u = {
1750
2210
  ...e,
1751
2211
  idTokenPayload: o,
@@ -1761,40 +2221,40 @@ var at = (e, t = null, n) => {
1761
2221
  };
1762
2222
  }
1763
2223
  return u;
1764
- }, ot = (e, t, n) => {
2224
+ }, Nt = (e, t, n) => {
1765
2225
  if (!e) return null;
1766
2226
  e.issued_at ||= (/* @__PURE__ */ new Date()).getTime() / 1e3;
1767
2227
  let r = {
1768
2228
  accessToken: e.access_token,
1769
2229
  expiresIn: e.expires_in,
1770
2230
  idToken: e.id_token,
1771
- scope: e.scope,
2231
+ scope: e.scope ?? t?.scope,
1772
2232
  tokenType: e.token_type,
1773
2233
  issuedAt: e.issued_at
1774
2234
  };
1775
- return "refresh_token" in e && (r.refreshToken = e.refresh_token), e.accessTokenPayload !== void 0 && (r.accessTokenPayload = e.accessTokenPayload), e.idTokenPayload !== void 0 && (r.idTokenPayload = e.idTokenPayload), at(r, t, n);
1776
- }, J = (e, t) => {
2235
+ return e.resourceContext !== void 0 && Object.assign(r, { resourceContext: e.resourceContext }), "refresh_token" in e && (r.refreshToken = e.refresh_token), e.accessTokenPayload !== void 0 && (r.accessTokenPayload = e.accessTokenPayload), e.idTokenPayload !== void 0 && (r.idTokenPayload = e.idTokenPayload), Mt(r, t, n);
2236
+ }, X = (e, t) => {
1777
2237
  let n = t - (/* @__PURE__ */ new Date()).getTime() / 1e3;
1778
2238
  return Math.round(n - e);
1779
- }, st = (e, t = 0) => e ? J(t, e.expiresAt) > 0 : !1, ct = async (e, t = 200, n = 50) => {
2239
+ }, Pt = (e, t = 0) => e ? X(t, e.expiresAt) > 0 : !1, Ft = async (e, t = 200, n = 50) => {
1780
2240
  let r = n, i = await e.syncTokensInfoAsync();
1781
2241
  for (; [
1782
- G.REQUIRE_SYNC_TOKENS,
1783
- G.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID,
1784
- G.TOKENS_INVALID
2242
+ J.REQUIRE_SYNC_TOKENS,
2243
+ J.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID,
2244
+ J.TOKENS_INVALID
1785
2245
  ].includes(i) && r > 0;) {
1786
- if (e.configuration.token_automatic_renew_mode == B.AutomaticOnlyWhenFetchExecuted) {
2246
+ if (e.configuration.token_automatic_renew_mode == W.AutomaticOnlyWhenFetchExecuted) {
1787
2247
  await e.renewTokensAsync({});
1788
2248
  break;
1789
2249
  }
1790
- await X({ milliseconds: t }), --r, i = await e.syncTokensInfoAsync();
2250
+ await Bt({ milliseconds: t }), --r, i = await e.syncTokensInfoAsync();
1791
2251
  }
1792
2252
  return {
1793
- isTokensValid: st(e.getTokens()),
2253
+ isTokensValid: Pt(e.getTokens()),
1794
2254
  tokens: e.getTokens(),
1795
2255
  numberWaited: r - n
1796
2256
  };
1797
- }, lt = (e, t, n) => {
2257
+ }, It = (e, t, n) => {
1798
2258
  if (e.idTokenPayload) {
1799
2259
  let r = e.idTokenPayload;
1800
2260
  if (n.issuer !== r.iss) return {
@@ -1820,25 +2280,26 @@ var at = (e, t = null, n) => {
1820
2280
  isValid: !0,
1821
2281
  reason: ""
1822
2282
  };
1823
- }, ut = "7.29.8", dt = null, Y, X = ({ milliseconds: e }) => new Promise((t) => b.setTimeout(t, e)), ft = (e = "/") => {
2283
+ }, Lt = "7.30.0", Rt = null, zt, Bt = ({ milliseconds: e }) => new Promise((t) => b.setTimeout(t, e)), Vt = (e = "/") => {
1824
2284
  try {
1825
- Y = new AbortController(), fetch(`${e}OidcKeepAliveServiceWorker.json?minSleepSeconds=150`, { signal: Y.signal }).catch((e) => {
2285
+ zt = new AbortController(), fetch(`${e}OidcKeepAliveServiceWorker.json?minSleepSeconds=150`, { signal: zt.signal }).catch((e) => {
1826
2286
  console.log(e);
1827
- }), X({ milliseconds: 15e4 }).then(() => ft(e));
2287
+ }), Bt({ milliseconds: 15e4 }).then(() => Vt(e));
1828
2288
  } catch (e) {
1829
2289
  console.log(e);
1830
2290
  }
1831
- }, pt = () => {
1832
- Y && Y.abort();
1833
- }, mt = (e) => {
2291
+ }, Ht = () => {
2292
+ zt && zt.abort();
2293
+ }, Ut = (e) => {
2294
+ Pe(e) !== void 0 && (e = e.split("#resource=")[0]);
1834
2295
  let t = `oidc.tabId.${e}`, n = sessionStorage.getItem(t);
1835
2296
  if (n) return n;
1836
2297
  let r = globalThis.crypto.randomUUID();
1837
2298
  return sessionStorage.setItem(t, r), r;
1838
- }, ht = (e) => navigator.serviceWorker.controller ?? e.active ?? e.waiting ?? e.installing ?? null, Z = (e, t) => (n) => {
2299
+ }, Wt = (e) => navigator.serviceWorker.controller ?? e.active ?? e.waiting ?? e.installing ?? null, Z = (e, t) => (n) => {
1839
2300
  let r = t?.timeoutMs ?? 5e3;
1840
2301
  return new Promise((t, i) => {
1841
- let a = ht(e);
2302
+ let a = Wt(e);
1842
2303
  if (!a) {
1843
2304
  i(/* @__PURE__ */ Error("Service worker target not available (controller/active/waiting/installing missing)"));
1844
2305
  return;
@@ -1859,51 +2320,57 @@ var at = (e, t = null, n) => {
1859
2320
  let e = n?.configurationName;
1860
2321
  a.postMessage({
1861
2322
  ...n,
1862
- tabId: mt(e ?? "default")
2323
+ tabId: Ut(e ?? "default")
1863
2324
  }, [o.port2]);
1864
2325
  } catch (e) {
1865
2326
  c(), i(e);
1866
2327
  }
1867
2328
  });
1868
- }, gt = async (e) => navigator.serviceWorker.controller ? navigator.serviceWorker.controller : new Promise((t) => {
2329
+ }, Gt = async (e) => navigator.serviceWorker.controller ? navigator.serviceWorker.controller : new Promise((t) => {
1869
2330
  let n = !1, r = () => {
1870
2331
  n || (n = !0, navigator.serviceWorker.removeEventListener("controllerchange", r), t(navigator.serviceWorker.controller ?? null));
1871
2332
  };
1872
2333
  navigator.serviceWorker.addEventListener("controllerchange", r), b.setTimeout(() => {
1873
2334
  n || (n = !0, navigator.serviceWorker.removeEventListener("controllerchange", r), t(navigator.serviceWorker.controller ?? null));
1874
2335
  }, e);
1875
- }), _t = !1, Q = !1, vt = /* @__PURE__ */ new Map(), yt = (e) => e instanceof DOMException ? e.name === "AbortError" : e?.name === "AbortError", bt = "oidc.sw.controllerchange_reload_count", xt = 3, St = () => {
2336
+ }), Kt = !1, Q = !1, qt = /* @__PURE__ */ new Map(), Jt = (e) => e instanceof DOMException ? e.name === "AbortError" : e?.name === "AbortError", Yt = "oidc.sw.controllerchange_reload_count", Xt = 3, Zt = () => {
1876
2337
  try {
1877
- return parseInt(sessionStorage.getItem(bt) ?? "0", 10);
2338
+ return parseInt(sessionStorage.getItem(Yt) ?? "0", 10);
1878
2339
  } catch {
1879
2340
  return 0;
1880
2341
  }
1881
- }, Ct = () => {
1882
- let e = St() + 1;
2342
+ }, Qt = () => {
2343
+ let e = Zt() + 1;
1883
2344
  try {
1884
- sessionStorage.setItem(bt, String(e));
2345
+ sessionStorage.setItem(Yt, String(e));
1885
2346
  } catch {}
1886
2347
  return e;
1887
- }, wt = () => {
2348
+ }, $t = () => {
1888
2349
  try {
1889
- sessionStorage.removeItem(bt);
2350
+ sessionStorage.removeItem(Yt);
1890
2351
  } catch {}
1891
- }, $ = async (e, t) => {
1892
- let n = e.service_worker_relative_url;
1893
- if (typeof window > "u" || typeof navigator > "u" || !navigator.serviceWorker || !n || e.service_worker_activate() === !1) return null;
1894
- let r = `${n}?v=${ut}`, i = e.service_worker_register ? n : r;
1895
- vt.has(i) || vt.set(i, e.service_worker_register ? e.service_worker_register(n) : navigator.serviceWorker.register(r, { updateViaCache: "none" }));
1896
- let a = null;
2352
+ }, $ = async (t, n) => {
2353
+ let i = t.service_worker_relative_url, a = Pe(n), o = n.split("#resource=")[0], s = () => {
2354
+ if (a !== void 0 && i) throw new r(e.RESOURCE_WORKER_UNSUPPORTED, "Resource token isolation requires an available, compatible Service Worker.", {
2355
+ phase: "refresh",
2356
+ retryable: !1
2357
+ });
2358
+ return null;
2359
+ };
2360
+ if (typeof window > "u" || typeof navigator > "u" || !navigator.serviceWorker || !i || t.service_worker_activate() === !1) return s();
2361
+ let c = `${i}${i.includes("?") ? "&" : "?"}v=${Lt}`, l = t.service_worker_register ? i : c;
2362
+ qt.has(l) || qt.set(l, t.service_worker_register ? t.service_worker_register(i) : navigator.serviceWorker.register(c, { updateViaCache: "none" }));
2363
+ let u = null;
1897
2364
  try {
1898
- a = await vt.get(i);
2365
+ u = await qt.get(l);
1899
2366
  } catch (e) {
1900
- if (yt(e)) return vt.delete(i), console.warn("oidc-client: service worker registration was aborted (likely tab shutdown or backgrounding); falling back to non–service-worker mode.", e), null;
2367
+ if (Jt(e)) return qt.delete(l), console.warn("oidc-client: service worker registration was aborted (likely tab shutdown or backgrounding); falling back to non–service-worker mode.", e), s();
1901
2368
  throw e;
1902
2369
  }
1903
- let o = `oidc.sw.version_mismatch_reload.${t}`, s = async (e) => {
1904
- pt(), console.log("New SW waiting – SKIP_WAITING");
2370
+ let d = `oidc.sw.version_mismatch_reload.${n}`, f = async (e) => {
2371
+ Ht(), console.log("New SW waiting – SKIP_WAITING");
1905
2372
  try {
1906
- await new Promise((n, r) => {
2373
+ await new Promise((t, r) => {
1907
2374
  let i = new MessageChannel(), a = null, o = () => {
1908
2375
  try {
1909
2376
  a != null && (b.clearTimeout(a), a = null), i.port1.onmessage = null, i.port1.close(), i.port2.close();
@@ -1914,14 +2381,14 @@ var at = (e, t = null, n) => {
1914
2381
  a = b.setTimeout(() => {
1915
2382
  o(), r(/* @__PURE__ */ Error("SKIP_WAITING did not respond within 8000ms"));
1916
2383
  }, 8e3), i.port1.onmessage = (e) => {
1917
- o(), e?.data?.error ? r(e.data.error) : n();
2384
+ o(), e?.data?.error ? r(e.data.error) : t();
1918
2385
  };
1919
2386
  try {
1920
2387
  e.postMessage({
1921
2388
  type: "SKIP_WAITING",
1922
- configurationName: t,
2389
+ configurationName: n,
1923
2390
  data: null,
1924
- tabId: mt(t ?? "default")
2391
+ tabId: Ut(n ?? "default")
1925
2392
  }, [i.port2]);
1926
2393
  } catch (e) {
1927
2394
  o(), r(e);
@@ -1930,187 +2397,205 @@ var at = (e, t = null, n) => {
1930
2397
  } catch (e) {
1931
2398
  console.warn("SKIP_WAITING failed", e);
1932
2399
  }
1933
- }, c = async () => {
1934
- let e = a.waiting;
1935
- e ? await s(e) : console.warn("sendSkipWaiting called but no waiting service worker found");
1936
- }, l = (e) => {
1937
- pt(), e.addEventListener("statechange", async () => {
2400
+ }, p = async () => {
2401
+ let e = u.waiting;
2402
+ e ? await f(e) : console.warn("sendSkipWaiting called but no waiting service worker found");
2403
+ }, m = (e) => {
2404
+ Ht(), e.addEventListener("statechange", async () => {
1938
2405
  if (e.state === "installed" && navigator.serviceWorker.controller) {
1939
- if (St() >= xt) {
2406
+ if (Zt() >= Xt) {
1940
2407
  console.warn("SW trackInstallingWorker: skipping SKIP_WAITING because the reload budget is exhausted");
1941
2408
  return;
1942
2409
  }
1943
- await s(e);
2410
+ await f(e);
1944
2411
  }
1945
2412
  });
1946
2413
  };
1947
- a.addEventListener("updatefound", () => {
1948
- let e = a.installing;
1949
- e && l(e);
1950
- }), a.installing ? l(a.installing) : a.waiting && navigator.serviceWorker.controller && (St() < xt ? c() : console.warn("SW: a waiting worker exists but reload budget is exhausted – skipping activation")), a.update().catch((e) => {
2414
+ u.addEventListener("updatefound", () => {
2415
+ let e = u.installing;
2416
+ e && m(e);
2417
+ }), u.installing ? m(u.installing) : u.waiting && navigator.serviceWorker.controller && (Zt() < Xt ? p() : console.warn("SW: a waiting worker exists but reload budget is exhausted – skipping activation")), u.update().catch((e) => {
1951
2418
  console.error(e);
1952
2419
  });
1953
2420
  try {
1954
- await navigator.serviceWorker.ready, navigator.serviceWorker.controller || (await Z(a, { timeoutMs: 8e3 })({
2421
+ await navigator.serviceWorker.ready, navigator.serviceWorker.controller || (await Z(u, { timeoutMs: 8e3 })({
1955
2422
  type: "claim",
1956
- configurationName: t,
2423
+ configurationName: n,
1957
2424
  data: null
1958
- }), await gt(2e3));
2425
+ }), await Gt(2e3));
1959
2426
  } catch (e) {
1960
- return console.warn(`Failed init ServiceWorker ${e?.toString?.() ?? String(e)}`), null;
2427
+ return console.warn(`Failed init ServiceWorker ${e?.toString?.() ?? String(e)}`), s();
1961
2428
  }
1962
- _t || (_t = !0, navigator.serviceWorker.addEventListener("controllerchange", () => {
2429
+ Kt || (Kt = !0, navigator.serviceWorker.addEventListener("controllerchange", () => {
1963
2430
  if (Q) return;
1964
- let e = Ct();
1965
- e > xt ? console.warn(`SW controllerchange: reload budget exhausted (${e - 1} reloads). Skipping reload to avoid infinite loop.`) : (Q = !0, console.log("SW controller changed – reloading page"), pt(), window.location.reload());
2431
+ let e = Qt();
2432
+ e > Xt ? console.warn(`SW controllerchange: reload budget exhausted (${e - 1} reloads). Skipping reload to avoid infinite loop.`) : (Q = !0, console.log("SW controller changed – reloading page"), Ht(), window.location.reload());
1966
2433
  }));
1967
- let u = async (e) => Z(a)({
2434
+ let h = async (e) => Z(u)({
1968
2435
  type: "clear",
1969
2436
  data: { status: e },
1970
- configurationName: t
1971
- }), d = async (e, n, r) => {
1972
- let i = await Z(a)({
2437
+ configurationName: n
2438
+ }), g = async (t, i, s) => {
2439
+ let c = {
2440
+ token_renew_mode: s.token_renew_mode,
2441
+ client_id: s.client_id,
2442
+ scope: s.scope,
2443
+ resource: s.resource,
2444
+ resources: s.resources,
2445
+ service_worker_convert_all_requests_to_cors: s.service_worker_convert_all_requests_to_cors
2446
+ };
2447
+ if (a !== void 0 && (await Z(u)({
1973
2448
  type: "init",
2449
+ configurationName: o,
1974
2450
  data: {
1975
- oidcServerConfiguration: e,
1976
- where: n,
1977
- oidcConfiguration: {
1978
- token_renew_mode: r.token_renew_mode,
1979
- service_worker_convert_all_requests_to_cors: r.service_worker_convert_all_requests_to_cors
1980
- }
2451
+ oidcServerConfiguration: t,
2452
+ where: "resource-capability",
2453
+ oidcConfiguration: c
2454
+ }
2455
+ })).resourceTokenManagement !== !0) throw new r(e.RESOURCE_WORKER_UNSUPPORTED, "Update OidcServiceWorker.js before using resource tokens.", {
2456
+ phase: "refresh",
2457
+ retryable: !1
2458
+ });
2459
+ let l = await Z(u)({
2460
+ type: "init",
2461
+ data: {
2462
+ oidcServerConfiguration: t,
2463
+ where: i,
2464
+ oidcConfiguration: c
1981
2465
  },
1982
- configurationName: t
1983
- }), s = i.version;
1984
- if (s !== "7.29.8") {
1985
- console.warn(`Service worker ${s} version mismatch with js client version ${ut}, unregistering and reloading`);
1986
- let e = parseInt(sessionStorage.getItem(o) ?? "0", 10);
2466
+ configurationName: n
2467
+ }), f = l.version;
2468
+ if (f !== "7.30.0") {
2469
+ console.warn(`Service worker ${f} version mismatch with js client version ${Lt}, unregistering and reloading`);
2470
+ let e = parseInt(sessionStorage.getItem(d) ?? "0", 10);
1987
2471
  if (e < 3) {
1988
- if (sessionStorage.setItem(o, String(e + 1)), a.waiting) return await c(), await X({ milliseconds: 500 }), Q || (Q = !0, window.location.reload()), new Promise(() => {});
2472
+ if (sessionStorage.setItem(d, String(e + 1)), u.waiting) return await p(), await Bt({ milliseconds: 500 }), Q || (Q = !0, window.location.reload()), new Promise(() => {});
1989
2473
  {
1990
- pt();
2474
+ Ht();
1991
2475
  try {
1992
- await a.update();
2476
+ await u.update();
1993
2477
  } catch (e) {
1994
2478
  console.error(e);
1995
2479
  }
1996
- let e = await a.unregister();
1997
- return console.log(`Service worker unregistering ${e}`), await X({ milliseconds: 500 }), Q || (Q = !0, window.location.reload()), new Promise(() => {});
2480
+ let e = await u.unregister();
2481
+ return console.log(`Service worker unregistering ${e}`), await Bt({ milliseconds: 500 }), Q || (Q = !0, window.location.reload()), new Promise(() => {});
1998
2482
  }
1999
2483
  }
2000
2484
  console.error(`Service worker version mismatch persists after ${e} attempt(s). Continuing with mismatched version.`);
2001
- } else sessionStorage.removeItem(o), wt();
2485
+ } else sessionStorage.removeItem(d), $t();
2002
2486
  return {
2003
- tokens: ot(i.tokens, null, r.token_renew_mode),
2004
- status: i.status
2487
+ tokens: Nt(l.tokens, null, s.token_renew_mode),
2488
+ status: l.status,
2489
+ resourceContexts: l.resourceContexts
2005
2490
  };
2006
- }, f = (e = "/") => {
2007
- dt ?? (dt = "not_null", ft(e));
2008
- }, p = (e) => Z(a)({
2491
+ }, _ = (e = "/") => {
2492
+ Rt ?? (Rt = "not_null", Vt(e));
2493
+ }, v = (e) => Z(u)({
2009
2494
  type: "setSessionState",
2010
2495
  data: { sessionState: e },
2011
- configurationName: t
2012
- }), m = async () => (await Z(a)({
2496
+ configurationName: n
2497
+ }), y = async () => (await Z(u)({
2013
2498
  type: "getSessionState",
2014
2499
  data: null,
2015
- configurationName: t
2016
- })).sessionState, h = (e) => (sessionStorage[`oidc.nonce.${t}`] = e.nonce, Z(a)({
2500
+ configurationName: n
2501
+ })).sessionState, x = (e) => (a === void 0 && (sessionStorage[`oidc.nonce.${n}`] = e.nonce), Z(u)({
2017
2502
  type: "setNonce",
2018
2503
  data: { nonce: e },
2019
- configurationName: t
2020
- })), g = async (e = !0) => {
2021
- let n = (await Z(a)({
2504
+ configurationName: n
2505
+ })), S = async (e = !0) => {
2506
+ let t = (await Z(u)({
2022
2507
  type: "getNonce",
2023
2508
  data: null,
2024
- configurationName: t
2509
+ configurationName: n
2025
2510
  })).nonce;
2026
- return n || (n = sessionStorage[`oidc.nonce.${t}`], console.warn("nonce not found in service worker, using sessionStorage"), e && (await h(n), n = (await g(!1)).nonce)), { nonce: n };
2027
- }, _ = {}, v = (e) => {
2028
- e == null ? (delete _[t], delete localStorage[`oidc.login.${t}`]) : (_[t] = e, localStorage[`oidc.login.${t}`] = JSON.stringify(e));
2029
- }, y = () => {
2030
- if (_[t]) return _[t];
2031
- let e = localStorage[`oidc.login.${t}`];
2511
+ return a === void 0 && (t || (t = sessionStorage[`oidc.nonce.${n}`], console.warn("nonce not found in service worker, using sessionStorage"), e && (await x(t), t = (await S(!1)).nonce))), { nonce: t };
2512
+ }, C = {}, w = (e) => {
2513
+ e == null ? (delete C[n], delete localStorage[`oidc.login.${n}`]) : (C[n] = e, localStorage[`oidc.login.${n}`] = JSON.stringify(e));
2514
+ }, T = () => {
2515
+ if (C[n]) return C[n];
2516
+ let e = localStorage[`oidc.login.${n}`];
2032
2517
  if (typeof e != "string" || e === "" || e === "undefined" || e === "null") return null;
2033
2518
  try {
2034
- _[t] = JSON.parse(e);
2519
+ C[n] = JSON.parse(e);
2035
2520
  } catch {
2036
2521
  return null;
2037
2522
  }
2038
- return _[t];
2039
- }, x = async (e) => {
2040
- await Z(a)({
2523
+ return C[n];
2524
+ }, E = async (e) => {
2525
+ await Z(u)({
2041
2526
  type: "setDemonstratingProofOfPossessionNonce",
2042
2527
  data: { demonstratingProofOfPossessionNonce: e },
2043
- configurationName: t
2528
+ configurationName: n
2044
2529
  });
2045
- }, S = async () => (await Z(a)({
2530
+ }, D = async () => (await Z(u)({
2046
2531
  type: "getDemonstratingProofOfPossessionNonce",
2047
2532
  data: null,
2048
- configurationName: t
2049
- })).demonstratingProofOfPossessionNonce, C = async (e) => {
2050
- let n = JSON.stringify(e);
2051
- await Z(a)({
2533
+ configurationName: n
2534
+ })).demonstratingProofOfPossessionNonce, ee = async (e) => {
2535
+ let t = JSON.stringify(e);
2536
+ await Z(u)({
2052
2537
  type: "setDemonstratingProofOfPossessionJwk",
2053
- data: { demonstratingProofOfPossessionJwkJson: n },
2054
- configurationName: t
2538
+ data: { demonstratingProofOfPossessionJwkJson: t },
2539
+ configurationName: n
2055
2540
  });
2056
- }, w = async () => {
2057
- let e = await Z(a)({
2541
+ }, O = async () => {
2542
+ let e = await Z(u)({
2058
2543
  type: "getDemonstratingProofOfPossessionJwk",
2059
2544
  data: null,
2060
- configurationName: t
2545
+ configurationName: n
2061
2546
  });
2062
2547
  return e.demonstratingProofOfPossessionJwkJson ? JSON.parse(e.demonstratingProofOfPossessionJwkJson) : null;
2063
- }, T = async (e = !0) => {
2064
- let n = (await Z(a)({
2548
+ }, k = async (e = !0) => {
2549
+ let t = (await Z(u)({
2065
2550
  type: "getState",
2066
2551
  data: null,
2067
- configurationName: t
2552
+ configurationName: n
2068
2553
  })).state;
2069
- return n || (n = sessionStorage[`oidc.state.${t}`], console.warn("state not found in service worker, using sessionStorage"), e && (await E(n), n = await T(!1))), n;
2070
- }, E = async (e) => (sessionStorage[`oidc.state.${t}`] = e, Z(a)({
2554
+ return a === void 0 && (t || (t = sessionStorage[`oidc.state.${n}`], console.warn("state not found in service worker, using sessionStorage"), e && (await A(t), t = await k(!1)))), t;
2555
+ }, A = async (e) => (a === void 0 && (sessionStorage[`oidc.state.${n}`] = e), Z(u)({
2071
2556
  type: "setState",
2072
2557
  data: { state: e },
2073
- configurationName: t
2074
- })), D = async (e = !0) => {
2075
- let n = (await Z(a)({
2558
+ configurationName: n
2559
+ })), j = async (e = !0) => {
2560
+ let t = (await Z(u)({
2076
2561
  type: "getCodeVerifier",
2077
2562
  data: null,
2078
- configurationName: t
2563
+ configurationName: n
2079
2564
  })).codeVerifier;
2080
- return n || (n = sessionStorage[`oidc.code_verifier.${t}`], console.warn("codeVerifier not found in service worker, using sessionStorage"), e && (await O(n), n = await D(!1))), n;
2081
- }, O = async (e) => (sessionStorage[`oidc.code_verifier.${t}`] = e, Z(a)({
2565
+ return a === void 0 && (t || (t = sessionStorage[`oidc.code_verifier.${n}`], console.warn("codeVerifier not found in service worker, using sessionStorage"), e && (await te(t), t = await j(!1)))), t;
2566
+ }, te = async (e) => (a === void 0 && (sessionStorage[`oidc.code_verifier.${n}`] = e), Z(u)({
2082
2567
  type: "setCodeVerifier",
2083
2568
  data: { codeVerifier: e },
2084
- configurationName: t
2569
+ configurationName: n
2085
2570
  }));
2086
2571
  return {
2087
- clearAsync: u,
2088
- initAsync: d,
2089
- startKeepAliveServiceWorker: () => f(e.service_worker_keep_alive_path),
2090
- setSessionStateAsync: p,
2091
- getSessionStateAsync: m,
2092
- setNonceAsync: h,
2093
- getNonceAsync: g,
2094
- setLoginParams: v,
2095
- getLoginParams: y,
2096
- getStateAsync: T,
2097
- setStateAsync: E,
2098
- getCodeVerifierAsync: D,
2099
- setCodeVerifierAsync: O,
2100
- setDemonstratingProofOfPossessionNonce: x,
2101
- getDemonstratingProofOfPossessionNonce: S,
2102
- setDemonstratingProofOfPossessionJwkAsync: C,
2103
- getDemonstratingProofOfPossessionJwkAsync: w,
2104
- signalAsync: (e, n) => Z(a, n)({
2572
+ clearAsync: h,
2573
+ initAsync: g,
2574
+ startKeepAliveServiceWorker: () => _(t.service_worker_keep_alive_path),
2575
+ setSessionStateAsync: v,
2576
+ getSessionStateAsync: y,
2577
+ setNonceAsync: x,
2578
+ getNonceAsync: S,
2579
+ setLoginParams: w,
2580
+ getLoginParams: T,
2581
+ getStateAsync: k,
2582
+ setStateAsync: A,
2583
+ getCodeVerifierAsync: j,
2584
+ setCodeVerifierAsync: te,
2585
+ setDemonstratingProofOfPossessionNonce: E,
2586
+ getDemonstratingProofOfPossessionNonce: D,
2587
+ setDemonstratingProofOfPossessionJwkAsync: ee,
2588
+ getDemonstratingProofOfPossessionJwkAsync: O,
2589
+ signalAsync: (e, t) => Z(u, t)({
2105
2590
  ...e,
2106
- configurationName: e.configurationName ?? t
2591
+ configurationName: e.configurationName ?? n
2107
2592
  })
2108
2593
  };
2109
- }, Tt = async (e, t, n, r) => {
2594
+ }, en = async (e, t, n, r) => {
2110
2595
  let i = await $(e, t);
2111
2596
  if (!i) throw Error(`signalServiceWorkerAsync: no service worker registered for configuration "${t}"`);
2112
2597
  return i.signalAsync(n, r);
2113
- }, Et = class e {
2598
+ }, tn = class e {
2114
2599
  constructor(e) {
2115
2600
  this._oidc = e;
2116
2601
  }
@@ -2124,17 +2609,17 @@ var at = (e, t = null, n) => {
2124
2609
  this._oidc.publishEvent(e, t);
2125
2610
  }
2126
2611
  static {
2127
- this.getOrCreate = (t, n = new j()) => (r, i = "default") => new e(H.getOrCreate(t, n)(r, i));
2612
+ this.getOrCreate = (t, n = new M()) => (r, i = "default") => new e(K.getOrCreate(t, n)(r, i));
2128
2613
  }
2129
2614
  static get(t = "default") {
2130
- let n = H.get(t);
2615
+ let n = K.get(t);
2131
2616
  return n ? new e(n) : null;
2132
2617
  }
2133
2618
  static getOrThrow(t = "default") {
2134
- return new e(H.getOrThrow(t));
2619
+ return new e(K.getOrThrow(t));
2135
2620
  }
2136
2621
  static {
2137
- this.eventNames = H.eventNames;
2622
+ this.eventNames = K.eventNames;
2138
2623
  }
2139
2624
  tryKeepExistingSessionAsync() {
2140
2625
  return this._oidc.tryKeepExistingSessionAsync();
@@ -2174,21 +2659,33 @@ var at = (e, t = null, n) => {
2174
2659
  }
2175
2660
  async getValidTokenAsync(e = 200, t = 50) {
2176
2661
  let n = this._oidc;
2177
- return ct({
2662
+ return Ft({
2178
2663
  getTokens: () => n.tokens,
2179
2664
  configuration: {
2180
2665
  token_automatic_renew_mode: n.configuration.token_automatic_renew_mode,
2181
2666
  refresh_time_before_tokens_expiration_in_second: n.configuration.refresh_time_before_tokens_expiration_in_second
2182
2667
  },
2183
2668
  syncTokensInfoAsync: async () => {
2184
- let { status: e } = await et(n)(n.configuration, n.configurationName, n.tokens, !1);
2669
+ let { status: e } = await Et(n)(n.configuration, n.configurationName, n.tokens, !1);
2185
2670
  return e;
2186
2671
  },
2187
2672
  renewTokensAsync: n.renewTokensAsync.bind(n)
2188
2673
  }, e, t);
2189
2674
  }
2190
- fetchWithTokens(e, t = !1) {
2191
- return Ge(e, this._oidc, t);
2675
+ getAccessTokenForResourceAsync(e, t) {
2676
+ return this._oidc.resourceTokens.getAccessTokenAsync(e, t);
2677
+ }
2678
+ getAccessTokenForResource(e) {
2679
+ return this._oidc.resourceTokens.peek(e);
2680
+ }
2681
+ clearResourceTokensAsync(e) {
2682
+ return this._oidc.resourceTokens.clearAsync(e);
2683
+ }
2684
+ fetchForResource(e, t = window.fetch, n = {}) {
2685
+ return this.fetchWithTokens(t, n.demonstratingProofOfPossession ?? !1, { resource: e });
2686
+ }
2687
+ fetchWithTokens(e, t = !1, n = {}) {
2688
+ return gt(e, this._oidc, n.demonstratingProofOfPossession ?? t, n);
2192
2689
  }
2193
2690
  async userInfoAsync(e = !1, t = !1) {
2194
2691
  return this._oidc.userInfoAsync(e, t);
@@ -2197,37 +2694,8 @@ var at = (e, t = null, n) => {
2197
2694
  return this._oidc.userInfo;
2198
2695
  }
2199
2696
  async signalServiceWorker(e, t) {
2200
- return Tt(this._oidc.configuration, this._oidc.configurationName, e, t);
2697
+ return en(this._oidc.configuration, this._oidc.configurationName, e, t);
2201
2698
  }
2202
- }, Dt = "1.0.0", Ot = {
2203
- SKIP_WAITING: "SKIP_WAITING",
2204
- CLAIM: "claim",
2205
- CLEAR: "clear",
2206
- INIT: "init",
2207
- SET_STATE: "setState",
2208
- GET_STATE: "getState",
2209
- SET_CODE_VERIFIER: "setCodeVerifier",
2210
- GET_CODE_VERIFIER: "getCodeVerifier",
2211
- SET_SESSION_STATE: "setSessionState",
2212
- GET_SESSION_STATE: "getSessionState",
2213
- SET_NONCE: "setNonce",
2214
- GET_NONCE: "getNonce",
2215
- SET_DPOP_NONCE: "setDemonstratingProofOfPossessionNonce",
2216
- GET_DPOP_NONCE: "getDemonstratingProofOfPossessionNonce",
2217
- SET_DPOP_JWK: "setDemonstratingProofOfPossessionJwk",
2218
- GET_DPOP_JWK: "getDemonstratingProofOfPossessionJwk"
2219
- }, kt = {
2220
- ACCESS_TOKEN: "ACCESS_TOKEN_SECURED_BY_OIDC_SERVICE_WORKER",
2221
- REFRESH_TOKEN: "REFRESH_TOKEN_SECURED_BY_OIDC_SERVICE_WORKER",
2222
- NONCE_TOKEN: "NONCE_SECURED_BY_OIDC_SERVICE_WORKER",
2223
- CODE_VERIFIER: "CODE_VERIFIER_SECURED_BY_OIDC_SERVICE_WORKER"
2224
- }, At = "DPOP_SECURED_BY_OIDC_SERVICE_WORKER", jt = {
2225
- TAB_ID: "oidc.tabId.",
2226
- STATE: "oidc.state.",
2227
- NONCE: "oidc.nonce.",
2228
- CODE_VERIFIER: "oidc.code_verifier.",
2229
- LOGIN_PARAMS: "oidc.login.",
2230
- SW_VERSION_MISMATCH_RELOAD: "oidc.sw.version_mismatch_reload."
2231
- }, Mt = "oidc.sw.controllerchange_reload_count", Nt = (e, t) => `${e}${t}`, Pt = (e, t, n = "default") => `${e}_${t}#tabId=${n}`, Ft = (e, t = "default") => `${At}_${e}#tabId=${t}`, It = (e) => typeof e == "string" && Object.values(Ot).includes(e);
2699
+ };
2232
2700
  //#endregion
2233
- export { At as DPOP_TOKEN_PLACEHOLDER_PREFIX, Et as OidcClient, d as OidcError, c as OidcErrorCode, j as OidcLocation, N as OidcStateError, M as OidcStateErrorCode, Dt as PROTOCOL_VERSION, F as PushedAuthorizationRequestError, P as PushedAuthorizationRequestErrorCode, jt as STORAGE_KEY_PREFIX, Mt as SW_CONTROLLER_CHANGE_RELOAD_COUNT_KEY, Ot as ServiceWorkerMessageType, kt as TOKEN_PLACEHOLDERS, B as TokenAutomaticRenewMode, q as TokenRenewMode, Ft as buildDpopSecuredPlaceholder, Pt as buildSecuredTokenPlaceholder, Nt as buildStorageKey, qe as getFetchDefault, z as getParseQueryStringFromLocation, Pe as getPath, f as isOidcError, ye as isOidcStateError, be as isPushedAuthorizationRequestError, It as isServiceWorkerMessageType, Tt as signalServiceWorkerAsync };
2701
+ export { Ue as DPOP_TOKEN_PLACEHOLDER_PREFIX, tn as OidcClient, r as OidcError, e as OidcErrorCode, M as OidcLocation, P as OidcStateError, N as OidcStateErrorCode, Be as PROTOCOL_VERSION, I as PushedAuthorizationRequestError, F as PushedAuthorizationRequestErrorCode, We as STORAGE_KEY_PREFIX, Ge as SW_CONTROLLER_CHANGE_RELOAD_COUNT_KEY, Ve as ServiceWorkerMessageType, He as TOKEN_PLACEHOLDERS, W as TokenAutomaticRenewMode, Y as TokenRenewMode, Je as buildDpopSecuredPlaceholder, qe as buildSecuredTokenPlaceholder, Ke as buildStorageKey, vt as getFetchDefault, V as getParseQueryStringFromLocation, Ze as getPath, i as isOidcError, ve as isOidcStateError, ye as isPushedAuthorizationRequestError, Ye as isServiceWorkerMessageType, en as signalServiceWorkerAsync };