@axa-fr/oidc-client 7.20.1-beta.1399 → 7.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/dist/events.d.ts +1 -1
- package/dist/fetch.d.ts.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +89 -86
- package/dist/index.umd.cjs +2 -2
- package/dist/oidc.d.ts +1 -1
- package/dist/oidcClient.d.ts +1 -1
- package/dist/parseTokens.d.ts.map +1 -1
- package/dist/user.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/events.ts +1 -1
- package/src/fetch.ts +0 -3
- package/src/index.ts +7 -3
- package/src/parseTokens.ts +2 -1
- package/src/renewTokens.ts +2 -2
- package/src/user.ts +0 -1
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -161,7 +161,7 @@ oidcClient.tryKeepExistingSessionAsync().then(() => {
|
|
|
161
161
|
<h1>@axa-fr/oidc-client demo</h1>
|
|
162
162
|
<h2>Loading</h2>
|
|
163
163
|
</div>`;
|
|
164
|
-
return
|
|
164
|
+
return;
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
let tokens = oidcClient.tokens;
|
|
@@ -226,6 +226,10 @@ const configuration = {
|
|
|
226
226
|
authority_timeout_wellknowurl_in_millisecond: 10000, // Timeout in milliseconds of the openid well-known URL, default is 10 seconds, then an error is thrown
|
|
227
227
|
monitor_session: Boolean, // Add OpenID monitor session, default is false (more information https://openid.net/specs/openid-connect-session-1_0.html), if you need to set it to true consider https://infi.nl/nieuws/spa-necromancy/
|
|
228
228
|
token_renew_mode: String, // Optional, update tokens based on the selected token(s) lifetime: "access_token_or_id_token_invalid" (default), "access_token_invalid", "id_token_invalid"
|
|
229
|
+
token_automatic_renew_mode: TokenAutomaticRenewMode.AutomaticOnlyWhenFetchExecuted, // Optional, default is TokenAutomaticRenewMode.AutomaticBeforeTokensExpiration
|
|
230
|
+
// TokenAutomaticRenewMode.AutomaticBeforeTokensExpiration: renew tokens automatically before they expire
|
|
231
|
+
// TokenAutomaticRenewMode.AutomaticOnlyWhenFetchExecuted: renew tokens automatically only when fetch is executed
|
|
232
|
+
// It requires you to use fetch given by oidcClient.fetchWithTokens(fetch) or to use oidcClient.getValidTokenAsync()
|
|
229
233
|
logout_tokens_to_invalidate: Array<string>, // Optional tokens to invalidate during logout, default: ['access_token', 'refresh_token']
|
|
230
234
|
location: ILOidcLocation, // Optional, default is window.location, you can inject your own location object respecting the ILOidcLocation interface
|
|
231
235
|
demonstrating_proof_of_possession: Boolean, // Optional, default is false, if true, the the Demonstrating Proof of Possession will be activated //https://www.rfc-editor.org/rfc/rfc9449.html#name-protected-resource-access
|
package/dist/events.d.ts
CHANGED
|
@@ -26,6 +26,6 @@ export declare const eventNames: {
|
|
|
26
26
|
syncTokensAsync_lock_not_available: string;
|
|
27
27
|
syncTokensAsync_end: string;
|
|
28
28
|
syncTokensAsync_error: string;
|
|
29
|
-
|
|
29
|
+
tokensInvalidAndWaitingActionsToRefresh: string;
|
|
30
30
|
};
|
|
31
31
|
//# sourceMappingURL=events.d.ts.map
|
package/dist/fetch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAK9B,eAAO,MAAM,eAAe,UAAW,KAAK,cAAc,IAAI,GAAG,IAAI,KAAI,
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAK9B,eAAO,MAAM,eAAe,UAAW,KAAK,cAAc,IAAI,GAAG,IAAI,KAAI,KA+BxE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export { getFetchDefault } from './oidc.js';
|
|
2
2
|
export { TokenRenewMode } from './parseTokens.js';
|
|
3
3
|
export { getParseQueryStringFromLocation, getPath } from './route-utils';
|
|
4
|
-
export type { AuthorityConfiguration, Fetch, OidcConfiguration, StringMap
|
|
5
|
-
export {
|
|
4
|
+
export type { AuthorityConfiguration, Fetch, OidcConfiguration, StringMap } from './types.js';
|
|
5
|
+
export { OidcLocation } from './location.js';
|
|
6
|
+
export type { ILOidcLocation } from './location.js';
|
|
7
|
+
export { TokenAutomaticRenewMode } from './types.js';
|
|
6
8
|
export { type OidcUserInfo, OidcClient } from './oidcClient.js';
|
|
7
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,+BAA+B,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACzE,YAAY,EACV,sBAAsB,EACtB,KAAK,EACL,iBAAiB,EACjB,SAAS,EACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,KAAK,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -54,7 +54,7 @@ const p = {
|
|
|
54
54
|
syncTokensAsync_lock_not_available: "syncTokensAsync_lock_not_available",
|
|
55
55
|
syncTokensAsync_end: "syncTokensAsync_end",
|
|
56
56
|
syncTokensAsync_error: "syncTokensAsync_error",
|
|
57
|
-
|
|
57
|
+
tokensInvalidAndWaitingActionsToRefresh: "tokensInvalidAndWaitingActionsToRefresh"
|
|
58
58
|
}, I = (e, n = sessionStorage) => {
|
|
59
59
|
const t = (y) => (n[`oidc.${e}`] = JSON.stringify({ tokens: null, status: y }), Promise.resolve()), s = async () => {
|
|
60
60
|
if (!n[`oidc.${e}`])
|
|
@@ -103,8 +103,8 @@ const p = {
|
|
|
103
103
|
getDemonstratingProofOfPossessionJwkAsync: d
|
|
104
104
|
};
|
|
105
105
|
};
|
|
106
|
-
var
|
|
107
|
-
const Pe = (e) => decodeURIComponent(Array.prototype.map.call(atob(e), (n) => "%" + ("00" + n.charCodeAt(0).toString(16)).slice(-2)).join("")), Ie = (e) => JSON.parse(Pe(e.replaceAll(/-/g, "+").replaceAll(/_/g, "/"))),
|
|
106
|
+
var V = /* @__PURE__ */ ((e) => (e.AutomaticBeforeTokenExpiration = "AutomaticBeforeTokensExpiration", e.AutomaticOnlyWhenFetchExecuted = "AutomaticOnlyWhenFetchExecuted", e))(V || {});
|
|
107
|
+
const Pe = (e) => decodeURIComponent(Array.prototype.map.call(atob(e), (n) => "%" + ("00" + n.charCodeAt(0).toString(16)).slice(-2)).join("")), Ie = (e) => JSON.parse(Pe(e.replaceAll(/-/g, "+").replaceAll(/_/g, "/"))), ae = (e) => {
|
|
108
108
|
try {
|
|
109
109
|
return e && Ce(e, ".") === 2 ? Ie(e.split(".")[1]) : null;
|
|
110
110
|
} catch (n) {
|
|
@@ -129,10 +129,10 @@ const z = (e, n = null, t) => {
|
|
|
129
129
|
return null;
|
|
130
130
|
let s;
|
|
131
131
|
const o = typeof e.expiresIn == "string" ? parseInt(e.expiresIn, 10) : e.expiresIn;
|
|
132
|
-
e.accessTokenPayload !== void 0 ? s = e.accessTokenPayload : s =
|
|
132
|
+
e.accessTokenPayload !== void 0 ? s = e.accessTokenPayload : s = ae(e.accessToken);
|
|
133
133
|
let r;
|
|
134
134
|
n != null && "idToken" in n && !("idToken" in e) ? r = n.idToken : r = e.idToken;
|
|
135
|
-
const i = e.idTokenPayload ? e.idTokenPayload :
|
|
135
|
+
const i = e.idTokenPayload ? e.idTokenPayload : ae(r), l = i && i.exp ? i.exp : Number.MAX_VALUE, a = s && s.exp ? s.exp : e.issuedAt + o;
|
|
136
136
|
e.issuedAt = Ne(e, s, i);
|
|
137
137
|
let d;
|
|
138
138
|
e.expiresAt ? d = e.expiresAt : t === Z.access_token_invalid ? d = a : t === Z.id_token_invalid ? d = l : d = l < a ? l : a;
|
|
@@ -142,7 +142,7 @@ const z = (e, n = null, t) => {
|
|
|
142
142
|
return { ..._, refreshToken: c };
|
|
143
143
|
}
|
|
144
144
|
return _;
|
|
145
|
-
},
|
|
145
|
+
}, oe = (e, n, t) => {
|
|
146
146
|
if (!e)
|
|
147
147
|
return null;
|
|
148
148
|
if (!e.issued_at) {
|
|
@@ -161,14 +161,20 @@ const z = (e, n = null, t) => {
|
|
|
161
161
|
}, U = (e, n) => {
|
|
162
162
|
const t = (/* @__PURE__ */ new Date()).getTime() / 1e3, s = n - t;
|
|
163
163
|
return Math.round(s - e);
|
|
164
|
-
},
|
|
164
|
+
}, ce = (e) => e ? U(0, e.expiresAt) > 0 : !1, ge = async (e, n = 200, t = 50) => {
|
|
165
165
|
let s = t;
|
|
166
166
|
if (!e.tokens)
|
|
167
167
|
return null;
|
|
168
|
-
for (; !
|
|
169
|
-
e.configuration.token_automatic_renew_mode ==
|
|
168
|
+
for (; !ce(e.tokens) && s > 0; ) {
|
|
169
|
+
if (e.configuration.token_automatic_renew_mode == V.AutomaticOnlyWhenFetchExecuted) {
|
|
170
|
+
await e.renewTokensAsync({});
|
|
171
|
+
break;
|
|
172
|
+
} else
|
|
173
|
+
await M({ milliseconds: n });
|
|
174
|
+
s = s - 1;
|
|
175
|
+
}
|
|
170
176
|
return {
|
|
171
|
-
isTokensValid:
|
|
177
|
+
isTokensValid: ce(e.tokens),
|
|
172
178
|
tokens: e.tokens,
|
|
173
179
|
numberWaited: s - t
|
|
174
180
|
};
|
|
@@ -187,7 +193,7 @@ const z = (e, n = null, t) => {
|
|
|
187
193
|
return { isValid: !1, reason: `Nonce does not match (idTokenPayload nonce) ${s.nonce} !== (nonce) ${n}` };
|
|
188
194
|
}
|
|
189
195
|
return { isValid: !0, reason: "" };
|
|
190
|
-
},
|
|
196
|
+
}, B = function() {
|
|
191
197
|
const e = function() {
|
|
192
198
|
let a, d;
|
|
193
199
|
const _ = (function() {
|
|
@@ -287,9 +293,9 @@ const z = (e, n = null, t) => {
|
|
|
287
293
|
setInterval: i,
|
|
288
294
|
clearInterval: l
|
|
289
295
|
};
|
|
290
|
-
}(),
|
|
291
|
-
let
|
|
292
|
-
const M = ({ milliseconds: e }) => new Promise((n) =>
|
|
296
|
+
}(), le = "7.20.1";
|
|
297
|
+
let ue = null, q;
|
|
298
|
+
const M = ({ milliseconds: e }) => new Promise((n) => B.setTimeout(n, e)), me = (e = "/") => {
|
|
293
299
|
try {
|
|
294
300
|
q = new AbortController(), fetch(`${e}OidcKeepAliveServiceWorker.json?minSleepSeconds=150`, { signal: q.signal }).catch((s) => {
|
|
295
301
|
console.log(s);
|
|
@@ -338,9 +344,9 @@ const M = ({ milliseconds: e }) => new Promise((n) => J.setTimeout(n, e)), me =
|
|
|
338
344
|
},
|
|
339
345
|
configurationName: n
|
|
340
346
|
}), D = b.version;
|
|
341
|
-
return D !==
|
|
347
|
+
return D !== le && (console.warn(`Service worker ${D} version mismatch with js client version ${le}, unregistering and reloading`), await P.service_worker_update_require_callback(s, xe)), { tokens: oe(b.tokens, null, P.token_renew_mode), status: b.status };
|
|
342
348
|
}, i = (k = "/") => {
|
|
343
|
-
|
|
349
|
+
ue == null && (ue = "not_null", me(k));
|
|
344
350
|
}, l = (k) => O(s)({ type: "setSessionState", data: { sessionState: k }, configurationName: n }), a = async () => (await O(s)({ type: "getSessionState", data: null, configurationName: n })).sessionState, d = (k) => (sessionStorage[`oidc.nonce.${n}`] = k.nonce, O(s)({ type: "setNonce", data: { nonce: k }, configurationName: n })), _ = async () => {
|
|
345
351
|
let S = (await O(s)({ type: "getNonce", data: null, configurationName: n })).nonce;
|
|
346
352
|
return S || (S = sessionStorage[`oidc.nonce.${n}`], console.warn("nonce not found in service worker, using sessionStorage")), { nonce: S };
|
|
@@ -407,13 +413,13 @@ function $e(e) {
|
|
|
407
413
|
return String.fromCharCode(parseInt(s, 16));
|
|
408
414
|
});
|
|
409
415
|
}
|
|
410
|
-
const
|
|
416
|
+
const re = (e) => {
|
|
411
417
|
let n = "";
|
|
412
418
|
return e.forEach(function(t) {
|
|
413
419
|
n += String.fromCharCode(t);
|
|
414
420
|
}), we(n);
|
|
415
421
|
};
|
|
416
|
-
function
|
|
422
|
+
function _e(e) {
|
|
417
423
|
return we($e(e));
|
|
418
424
|
}
|
|
419
425
|
const Ke = {
|
|
@@ -443,24 +449,24 @@ const Ke = {
|
|
|
443
449
|
const i = {
|
|
444
450
|
// @ts-ignore
|
|
445
451
|
// JWT "headers" really means JWS "protected headers"
|
|
446
|
-
protected:
|
|
452
|
+
protected: _e(JSON.stringify(t)),
|
|
447
453
|
// @ts-ignore
|
|
448
454
|
// JWT "claims" are really a JSON-defined JWS "payload"
|
|
449
|
-
payload:
|
|
455
|
+
payload: _e(JSON.stringify(s))
|
|
450
456
|
}, l = o.importKeyAlgorithm, a = !0, d = ["sign"], _ = await e.crypto.subtle.importKey("jwk", n, l, a, d), c = pe(`${i.protected}.${i.payload}`), u = o.signAlgorithm, h = await e.crypto.subtle.sign(u, _, c);
|
|
451
|
-
return i.signature =
|
|
457
|
+
return i.signature = re(new Uint8Array(h)), `${i.protected}.${i.payload}.${i.signature}`;
|
|
452
458
|
};
|
|
453
|
-
var
|
|
454
|
-
const
|
|
459
|
+
var Fe = { sign: Ue };
|
|
460
|
+
const Ve = (e) => async (n) => {
|
|
455
461
|
const t = n, s = !0, o = ["sign", "verify"], r = await e.crypto.subtle.generateKey(t, s, o);
|
|
456
462
|
return await e.crypto.subtle.exportKey("jwk", r.privateKey);
|
|
457
463
|
}, Me = (e) => {
|
|
458
464
|
const n = Object.assign({}, e);
|
|
459
465
|
return delete n.d, n.key_ops = ["verify"], n;
|
|
460
|
-
},
|
|
461
|
-
generate:
|
|
466
|
+
}, Je = {
|
|
467
|
+
generate: Ve,
|
|
462
468
|
neuter: Me
|
|
463
|
-
},
|
|
469
|
+
}, Be = (e) => async (n, t) => {
|
|
464
470
|
let s;
|
|
465
471
|
switch (n.kty) {
|
|
466
472
|
case "EC":
|
|
@@ -473,10 +479,10 @@ const Fe = (e) => async (n) => {
|
|
|
473
479
|
throw new Error("Unknown or not implemented JWK type");
|
|
474
480
|
}
|
|
475
481
|
const o = await e.crypto.subtle.digest(t, pe(s));
|
|
476
|
-
return
|
|
482
|
+
return re(new Uint8Array(o));
|
|
477
483
|
};
|
|
478
|
-
var He = { thumbprint:
|
|
479
|
-
const je = (e) => async (n) => await
|
|
484
|
+
var He = { thumbprint: Be };
|
|
485
|
+
const je = (e) => async (n) => await Je.generate(e)(n), Ae = (e) => (n) => async (t, s = "POST", o, r = {}) => {
|
|
480
486
|
const i = {
|
|
481
487
|
// https://www.rfc-editor.org/rfc/rfc9449.html#name-concept
|
|
482
488
|
jti: btoa(qe()),
|
|
@@ -485,7 +491,7 @@ const je = (e) => async (n) => await Be.generate(e)(n), Ae = (e) => (n) => async
|
|
|
485
491
|
iat: Math.round(Date.now() / 1e3),
|
|
486
492
|
...r
|
|
487
493
|
}, l = await He.thumbprint(e)(t, n.digestAlgorithm);
|
|
488
|
-
return await
|
|
494
|
+
return await Fe.sign(e)(t, { kid: l }, i, n);
|
|
489
495
|
}, qe = () => {
|
|
490
496
|
const e = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx", n = "0123456789abcdef";
|
|
491
497
|
let t = 0, s = "";
|
|
@@ -495,20 +501,20 @@ const je = (e) => async (n) => await Be.generate(e)(n), Ae = (e) => (n) => async
|
|
|
495
501
|
}, Se = () => {
|
|
496
502
|
const e = typeof window < "u" && !!window.crypto, n = e && !!window.crypto.subtle;
|
|
497
503
|
return { hasCrypto: e, hasSubtleCrypto: n };
|
|
498
|
-
},
|
|
504
|
+
}, ee = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", Ge = (e) => {
|
|
499
505
|
const n = [];
|
|
500
506
|
for (let t = 0; t < e.byteLength; t += 1) {
|
|
501
|
-
const s = e[t] %
|
|
502
|
-
n.push(
|
|
507
|
+
const s = e[t] % ee.length;
|
|
508
|
+
n.push(ee[s]);
|
|
503
509
|
}
|
|
504
510
|
return n.join("");
|
|
505
|
-
},
|
|
511
|
+
}, ne = (e) => {
|
|
506
512
|
const n = new Uint8Array(e), { hasCrypto: t } = Se();
|
|
507
513
|
if (t)
|
|
508
514
|
window.crypto.getRandomValues(n);
|
|
509
515
|
else
|
|
510
516
|
for (let s = 0; s < e; s += 1)
|
|
511
|
-
n[s] = Math.random() *
|
|
517
|
+
n[s] = Math.random() * ee.length | 0;
|
|
512
518
|
return Ge(n);
|
|
513
519
|
};
|
|
514
520
|
function Ye(e) {
|
|
@@ -519,7 +525,7 @@ function Ye(e) {
|
|
|
519
525
|
}
|
|
520
526
|
function ve(e) {
|
|
521
527
|
return new Promise((n, t) => {
|
|
522
|
-
crypto.subtle.digest("SHA-256", Ye(e)).then((s) => n(
|
|
528
|
+
crypto.subtle.digest("SHA-256", Ye(e)).then((s) => n(re(new Uint8Array(s))), (s) => t(s));
|
|
523
529
|
});
|
|
524
530
|
}
|
|
525
531
|
const Xe = (e) => {
|
|
@@ -530,12 +536,12 @@ const Xe = (e) => {
|
|
|
530
536
|
}, ze = 60 * 60, Qe = (e) => async (n, t = ze, s = window.sessionStorage, o = 1e4) => {
|
|
531
537
|
const r = `${n}/.well-known/openid-configuration`, i = `oidc.server:${n}`, l = De(i, s, t);
|
|
532
538
|
if (l)
|
|
533
|
-
return new
|
|
539
|
+
return new se(l);
|
|
534
540
|
const a = await H(e)(r, {}, o);
|
|
535
541
|
if (a.status !== 200)
|
|
536
542
|
return null;
|
|
537
543
|
const d = await a.json();
|
|
538
|
-
return Re(i, d, s), new
|
|
544
|
+
return Re(i, d, s), new se(d);
|
|
539
545
|
}, H = (e) => async (n, t = {}, s = 1e4, o = 0) => {
|
|
540
546
|
let r;
|
|
541
547
|
try {
|
|
@@ -550,10 +556,10 @@ const Xe = (e) => {
|
|
|
550
556
|
throw console.error(i.message), i;
|
|
551
557
|
}
|
|
552
558
|
return r;
|
|
553
|
-
},
|
|
559
|
+
}, te = {
|
|
554
560
|
refresh_token: "refresh_token",
|
|
555
561
|
access_token: "access_token"
|
|
556
|
-
},
|
|
562
|
+
}, fe = (e) => async (n, t, s = te.refresh_token, o, r = {}, i = 1e4) => {
|
|
557
563
|
const l = {
|
|
558
564
|
token: t,
|
|
559
565
|
token_type_hint: s,
|
|
@@ -603,12 +609,12 @@ const Xe = (e) => {
|
|
|
603
609
|
return _.headers.has(G) && (u = _.headers.get(G)), {
|
|
604
610
|
success: !0,
|
|
605
611
|
status: _.status,
|
|
606
|
-
data:
|
|
612
|
+
data: oe(c, o, i),
|
|
607
613
|
demonstratingProofOfPossessionNonce: u
|
|
608
614
|
};
|
|
609
615
|
}, en = (e, n) => async (t, s) => {
|
|
610
616
|
s = s ? { ...s } : {};
|
|
611
|
-
const o =
|
|
617
|
+
const o = ne(128), r = await Xe(o);
|
|
612
618
|
await e.setCodeVerifierAsync(o), await e.setStateAsync(s.state), s.code_challenge = r, s.code_challenge_method = "S256";
|
|
613
619
|
let i = "";
|
|
614
620
|
if (s)
|
|
@@ -639,12 +645,12 @@ const Xe = (e) => {
|
|
|
639
645
|
success: !0,
|
|
640
646
|
data: {
|
|
641
647
|
state: t.state,
|
|
642
|
-
tokens:
|
|
648
|
+
tokens: oe(_, null, o),
|
|
643
649
|
demonstratingProofOfPossessionNonce: d
|
|
644
650
|
}
|
|
645
651
|
};
|
|
646
652
|
};
|
|
647
|
-
async function
|
|
653
|
+
async function de(e, n, t) {
|
|
648
654
|
const s = (l) => {
|
|
649
655
|
e.tokens = l;
|
|
650
656
|
}, { tokens: o, status: r } = await j(e)(0, n, t, s);
|
|
@@ -665,11 +671,11 @@ async function Te(e, n = !1, t = null) {
|
|
|
665
671
|
const s = e.configuration, o = `${s.client_id}_${e.configurationName}_${s.authority}`;
|
|
666
672
|
let r;
|
|
667
673
|
const i = await C(e.configuration, e.configurationName);
|
|
668
|
-
return (s == null ? void 0 : s.storage) === (window == null ? void 0 : window.sessionStorage) && !i ? r = await
|
|
674
|
+
return (s == null ? void 0 : s.storage) === (window == null ? void 0 : window.sessionStorage) && !i ? r = await de(e, n, t) : r = await navigator.locks.request(o, { ifAvailable: !0 }, async (l) => l ? await de(e, n, t) : (e.publishEvent(N.eventNames.syncTokensAsync_lock_not_available, { lock: "lock not available" }), await tn(e, s))), r ? (e.timeoutId && (e.timeoutId = J(e, e.tokens.expiresAt, t)), e.tokens) : null;
|
|
669
675
|
}
|
|
670
|
-
const
|
|
676
|
+
const J = (e, n, t = null) => {
|
|
671
677
|
const s = e.configuration.refresh_time_before_tokens_expiration_in_second;
|
|
672
|
-
return
|
|
678
|
+
return B.setTimeout(async () => {
|
|
673
679
|
const r = { timeLeft: U(s, n) };
|
|
674
680
|
e.publishEvent(N.eventNames.token_timer, r), await Te(e, !1, t);
|
|
675
681
|
}, 1e3);
|
|
@@ -724,7 +730,7 @@ const B = (e, n, t = null) => {
|
|
|
724
730
|
await M({ milliseconds: 1e3 }), r--, e.publishEvent(p.refreshTokensAsync, { message: `wait because navigator is offline try ${r}` });
|
|
725
731
|
const i = document.hidden, l = n + 1;
|
|
726
732
|
s || (s = {});
|
|
727
|
-
const a = e.configuration, d = (c, u = null, h = null) =>
|
|
733
|
+
const a = e.configuration, d = (c, u = null, h = null) => ie(e.configurationName, e.configuration, e.publishEvent.bind(e))(c, u, h), _ = async () => {
|
|
728
734
|
try {
|
|
729
735
|
let c;
|
|
730
736
|
const u = await C(a, e.configurationName);
|
|
@@ -755,10 +761,10 @@ const B = (e, n, t = null) => {
|
|
|
755
761
|
case x.LOGOUT_FROM_ANOTHER_TAB:
|
|
756
762
|
return o(null), e.publishEvent(p.logout_from_another_tab, { status: "session syncTokensAsync" }), { tokens: null, status: "LOGGED_OUT" };
|
|
757
763
|
case x.REQUIRE_SYNC_TOKENS:
|
|
758
|
-
return a.token_automatic_renew_mode ==
|
|
764
|
+
return a.token_automatic_renew_mode == V.AutomaticOnlyWhenFetchExecuted && x.FORCE_REFRESH !== c ? (e.publishEvent(p.tokensInvalidAndWaitingActionsToRefresh, {}), { tokens: e.tokens, status: "GIVE_UP" }) : (e.publishEvent(p.refreshTokensAsync_begin, { tryNumber: n }), await _());
|
|
759
765
|
default: {
|
|
760
|
-
if (a.token_automatic_renew_mode ==
|
|
761
|
-
return e.publishEvent(p.
|
|
766
|
+
if (a.token_automatic_renew_mode == V.AutomaticOnlyWhenFetchExecuted && x.FORCE_REFRESH !== c)
|
|
767
|
+
return e.publishEvent(p.tokensInvalidAndWaitingActionsToRefresh, {}), { tokens: e.tokens, status: "GIVE_UP" };
|
|
762
768
|
if (e.publishEvent(p.refreshTokensAsync_begin, { refreshToken: u.refreshToken, status: c, tryNumber: n }), !u.refreshToken)
|
|
763
769
|
return await _();
|
|
764
770
|
const g = a.client_id, m = a.redirect_uri, f = a.authority, A = { ...a.token_request_extras ? a.token_request_extras : {} };
|
|
@@ -801,7 +807,7 @@ const B = (e, n, t = null) => {
|
|
|
801
807
|
} catch (c) {
|
|
802
808
|
return console.error(c), e.publishEvent(p.refreshTokensAsync_silent_error, { message: "exception", exception: c.message }), j(e)(l, t, s, o);
|
|
803
809
|
}
|
|
804
|
-
},
|
|
810
|
+
}, ie = (e, n, t) => (s = null, o = null, r = null) => {
|
|
805
811
|
if (!n.silent_redirect_uri || !n.silent_login_uri)
|
|
806
812
|
return Promise.resolve(null);
|
|
807
813
|
try {
|
|
@@ -847,9 +853,9 @@ const B = (e, n, t = null) => {
|
|
|
847
853
|
}
|
|
848
854
|
}, on = (e, n, t, s, o) => (r = null, i = void 0) => {
|
|
849
855
|
r = { ...r };
|
|
850
|
-
const l = (d, _, c) =>
|
|
856
|
+
const l = (d, _, c) => ie(n, t, s.bind(o))(d, _, c);
|
|
851
857
|
return (async () => {
|
|
852
|
-
o.timeoutId &&
|
|
858
|
+
o.timeoutId && B.clearTimeout(o.timeoutId);
|
|
853
859
|
let d;
|
|
854
860
|
r && "state" in r && (d = r.state, delete r.state);
|
|
855
861
|
try {
|
|
@@ -858,13 +864,13 @@ const B = (e, n, t = null) => {
|
|
|
858
864
|
prompt: "none"
|
|
859
865
|
}, d, i);
|
|
860
866
|
if (c)
|
|
861
|
-
return o.tokens = c.tokens, s(p.token_aquired, {}), o.timeoutId =
|
|
867
|
+
return o.tokens = c.tokens, s(p.token_aquired, {}), o.timeoutId = J(o, o.tokens.expiresAt, r), {};
|
|
862
868
|
} catch (_) {
|
|
863
869
|
return _;
|
|
864
870
|
}
|
|
865
871
|
})();
|
|
866
872
|
}, rn = (e, n, t) => (s, o, r, i = !1) => {
|
|
867
|
-
const l = (a, d = void 0, _ = void 0) =>
|
|
873
|
+
const l = (a, d = void 0, _ = void 0) => ie(e.configurationName, t, e.publishEvent.bind(e))(a, d, _);
|
|
868
874
|
return new Promise((a, d) => {
|
|
869
875
|
if (t.silent_login_uri && t.silent_redirect_uri && t.monitor_session && s && r && !i) {
|
|
870
876
|
const _ = () => {
|
|
@@ -942,14 +948,14 @@ const B = (e, n, t = null) => {
|
|
|
942
948
|
const d = i;
|
|
943
949
|
return i = { ...i }, (async () => {
|
|
944
950
|
const c = r || o.getPath();
|
|
945
|
-
if ("state" in i || (i.state =
|
|
951
|
+
if ("state" in i || (i.state = ne(16)), t(p.loginAsync_begin, {}), i)
|
|
946
952
|
for (const u of Object.keys(i))
|
|
947
953
|
u.endsWith(":token_request") && delete i[u];
|
|
948
954
|
try {
|
|
949
955
|
const u = l ? n.silent_redirect_uri : n.redirect_uri;
|
|
950
956
|
a || (a = n.scope);
|
|
951
957
|
const h = n.extras ? { ...n.extras, ...i } : i;
|
|
952
|
-
h.nonce || (h.nonce =
|
|
958
|
+
h.nonce || (h.nonce = ne(12));
|
|
953
959
|
const g = { nonce: h.nonce }, m = await C(n, e), f = await s(n.authority, n.authority_configuration);
|
|
954
960
|
let w;
|
|
955
961
|
if (m)
|
|
@@ -1044,7 +1050,7 @@ const B = (e, n, t = null) => {
|
|
|
1044
1050
|
} catch (t) {
|
|
1045
1051
|
throw console.error(t), e.publishEvent(p.loginCallbackAsync_error, t), t;
|
|
1046
1052
|
}
|
|
1047
|
-
},
|
|
1053
|
+
}, he = {
|
|
1048
1054
|
access_token: "access_token",
|
|
1049
1055
|
refresh_token: "refresh_token"
|
|
1050
1056
|
}, Q = (e, n) => {
|
|
@@ -1067,7 +1073,7 @@ const B = (e, n, t = null) => {
|
|
|
1067
1073
|
}
|
|
1068
1074
|
return n;
|
|
1069
1075
|
}, _n = (e) => async (n) => {
|
|
1070
|
-
|
|
1076
|
+
B.clearTimeout(e.timeoutId), e.timeoutId = null, e.checkSessionIFrame && e.checkSessionIFrame.stop();
|
|
1071
1077
|
const t = await C(e.configuration, e.configurationName);
|
|
1072
1078
|
t ? await t.clearAsync(n) : await I(e.configurationName, e.configuration.storage).clearAsync(n), e.tokens = null, e.userInfo = null;
|
|
1073
1079
|
}, fn = (e, n, t, s, o) => async (r = void 0, i = null) => {
|
|
@@ -1081,22 +1087,22 @@ const B = (e, n, t = null) => {
|
|
|
1081
1087
|
const w = a.revocationEndpoint;
|
|
1082
1088
|
if (w) {
|
|
1083
1089
|
const A = [], v = e.tokens ? e.tokens.accessToken : null;
|
|
1084
|
-
if (v && l.logout_tokens_to_invalidate.includes(
|
|
1085
|
-
const y = Q(i, ":revoke_access_token"), k =
|
|
1090
|
+
if (v && l.logout_tokens_to_invalidate.includes(he.access_token)) {
|
|
1091
|
+
const y = Q(i, ":revoke_access_token"), k = fe(t)(
|
|
1086
1092
|
w,
|
|
1087
1093
|
v,
|
|
1088
|
-
|
|
1094
|
+
te.access_token,
|
|
1089
1095
|
l.client_id,
|
|
1090
1096
|
y
|
|
1091
1097
|
);
|
|
1092
1098
|
A.push(k);
|
|
1093
1099
|
}
|
|
1094
1100
|
const T = e.tokens ? e.tokens.refreshToken : null;
|
|
1095
|
-
if (T && l.logout_tokens_to_invalidate.includes(
|
|
1096
|
-
const y = Q(i, ":revoke_refresh_token"), k =
|
|
1101
|
+
if (T && l.logout_tokens_to_invalidate.includes(he.refresh_token)) {
|
|
1102
|
+
const y = Q(i, ":revoke_refresh_token"), k = fe(t)(
|
|
1097
1103
|
w,
|
|
1098
1104
|
T,
|
|
1099
|
-
|
|
1105
|
+
te.refresh_token,
|
|
1100
1106
|
l.client_id,
|
|
1101
1107
|
y
|
|
1102
1108
|
);
|
|
@@ -1128,11 +1134,7 @@ const B = (e, n, t = null) => {
|
|
|
1128
1134
|
const [s, o, ...r] = t, i = o ? { ...o } : { method: "GET" };
|
|
1129
1135
|
let l = new Headers();
|
|
1130
1136
|
i.headers && (l = i.headers instanceof Headers ? i.headers : new Headers(i.headers));
|
|
1131
|
-
const a = n;
|
|
1132
|
-
console.log("before", ee);
|
|
1133
|
-
const d = await ee(a);
|
|
1134
|
-
console.log("getValidToken", d);
|
|
1135
|
-
const _ = (u = d == null ? void 0 : d.tokens) == null ? void 0 : u.accessToken;
|
|
1137
|
+
const a = n, d = await ge(a), _ = (u = d == null ? void 0 : d.tokens) == null ? void 0 : u.accessToken;
|
|
1136
1138
|
if (l.has("Accept") || l.set("Accept", "application/json"), _) {
|
|
1137
1139
|
if (a.configuration.demonstrating_proof_of_possession) {
|
|
1138
1140
|
const h = await a.generateDemonstrationOfProofOfPossessionAsync(_, s.toString(), i.method);
|
|
@@ -1144,7 +1146,7 @@ const B = (e, n, t = null) => {
|
|
|
1144
1146
|
const c = { ...i, headers: l };
|
|
1145
1147
|
return await e(s, c, ...r);
|
|
1146
1148
|
}, dn = (e) => async (n = !1) => {
|
|
1147
|
-
if (
|
|
1149
|
+
if (e.userInfo != null && !n)
|
|
1148
1150
|
return e.userInfo;
|
|
1149
1151
|
const t = e.configuration, o = (await e.initAsync(t.authority, t.authority_configuration)).userInfoEndpoint, i = await (async () => {
|
|
1150
1152
|
const a = await Ee(fetch, e)(o);
|
|
@@ -1263,7 +1265,7 @@ const kn = () => {
|
|
|
1263
1265
|
if (o) {
|
|
1264
1266
|
n.startKeepAliveServiceWorker(), e.tokens = o;
|
|
1265
1267
|
const r = n.getLoginParams(e.configurationName);
|
|
1266
|
-
e.timeoutId =
|
|
1268
|
+
e.timeoutId = J(e, e.tokens.expiresAt, r.extras);
|
|
1267
1269
|
const i = await n.getSessionStateAsync();
|
|
1268
1270
|
return await e.startCheckSessionAsync(s.check_session_iframe, t.client_id, i), e.publishEvent(p.tryKeepExistingSessionAsync_end, {
|
|
1269
1271
|
success: !0,
|
|
@@ -1282,7 +1284,7 @@ const kn = () => {
|
|
|
1282
1284
|
if (r) {
|
|
1283
1285
|
e.tokens = z(r, null, t.token_renew_mode);
|
|
1284
1286
|
const i = o.getLoginParams();
|
|
1285
|
-
e.timeoutId =
|
|
1287
|
+
e.timeoutId = J(e, e.tokens.expiresAt, i.extras);
|
|
1286
1288
|
const l = await o.getSessionStateAsync();
|
|
1287
1289
|
return await e.startCheckSessionAsync(s.check_session_iframe, t.client_id, l), e.publishEvent(p.tryKeepExistingSessionAsync_end, {
|
|
1288
1290
|
success: !0,
|
|
@@ -1298,15 +1300,15 @@ const kn = () => {
|
|
|
1298
1300
|
return console.error(t), n && await n.clearAsync(), e.publishEvent(p.tryKeepExistingSessionAsync_error, "tokens inside ServiceWorker are invalid"), !1;
|
|
1299
1301
|
}
|
|
1300
1302
|
}, pn = () => fetch;
|
|
1301
|
-
class
|
|
1303
|
+
class se {
|
|
1302
1304
|
constructor(n) {
|
|
1303
1305
|
this.authorizationEndpoint = n.authorization_endpoint, this.tokenEndpoint = n.token_endpoint, this.revocationEndpoint = n.revocation_endpoint, this.userInfoEndpoint = n.userinfo_endpoint, this.checkSessionIframe = n.check_session_iframe, this.issuer = n.issuer, this.endSessionEndpoint = n.end_session_endpoint;
|
|
1304
1306
|
}
|
|
1305
1307
|
}
|
|
1306
1308
|
const W = {}, wn = (e, n = new X()) => (t, s = "default") => (W[s] || (W[s] = new N(t, s, e, n)), W[s]), An = async (e) => {
|
|
1307
1309
|
const { parsedTokens: n, callbackPath: t } = await e.loginCallbackAsync();
|
|
1308
|
-
return e.timeoutId =
|
|
1309
|
-
}, Sn = (e) => Math.floor(Math.random() * e),
|
|
1310
|
+
return e.timeoutId = J(e, n.expiresAt), { callbackPath: t };
|
|
1311
|
+
}, Sn = (e) => Math.floor(Math.random() * e), F = class F {
|
|
1310
1312
|
constructor(n, t = "default", s, o = new X()) {
|
|
1311
1313
|
this.initPromise = null, this.tryKeepExistingSessionPromise = null, this.loginPromise = null, this.loginCallbackPromise = null, this.loginCallbackWithAutoTokensRenewPromise = null, this.userInfoPromise = null, this.renewTokensPromise = null, this.logoutPromise = null;
|
|
1312
1314
|
let r = n.silent_login_uri;
|
|
@@ -1317,7 +1319,7 @@ const W = {}, wn = (e, n = new X()) => (t, s = "default") => (W[s] || (W[s] = ne
|
|
|
1317
1319
|
this.configuration = {
|
|
1318
1320
|
...n,
|
|
1319
1321
|
silent_login_uri: r,
|
|
1320
|
-
token_automatic_renew_mode: n.token_automatic_renew_mode ??
|
|
1322
|
+
token_automatic_renew_mode: n.token_automatic_renew_mode ?? V.AutomaticBeforeTokenExpiration,
|
|
1321
1323
|
monitor_session: n.monitor_session ?? !1,
|
|
1322
1324
|
refresh_time_before_tokens_expiration_in_second: i,
|
|
1323
1325
|
silent_login_timeout: n.silent_login_timeout ?? 12e3,
|
|
@@ -1374,7 +1376,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
1374
1376
|
return this.initPromise;
|
|
1375
1377
|
const s = async () => {
|
|
1376
1378
|
if (t != null)
|
|
1377
|
-
return new
|
|
1379
|
+
return new se({
|
|
1378
1380
|
authorization_endpoint: t.authorization_endpoint,
|
|
1379
1381
|
end_session_endpoint: t.end_session_endpoint,
|
|
1380
1382
|
revocation_endpoint: t.revocation_endpoint,
|
|
@@ -1402,7 +1404,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
1402
1404
|
return this.loginCallbackPromise;
|
|
1403
1405
|
const t = async () => {
|
|
1404
1406
|
const s = await ln(this)(n), o = s.tokens;
|
|
1405
|
-
return this.tokens = o, await C(this.configuration, this.configurationName) || I(this.configurationName, this.configuration.storage).setTokens(o), this.publishEvent(
|
|
1407
|
+
return this.tokens = o, await C(this.configuration, this.configurationName) || I(this.configurationName, this.configuration.storage).setTokens(o), this.publishEvent(F.eventNames.token_aquired, o), { parsedTokens: o, state: s.state, callbackPath: s.callbackPath };
|
|
1406
1408
|
};
|
|
1407
1409
|
return this.loginCallbackPromise = t(), this.loginCallbackPromise.then((s) => (this.loginCallbackPromise = null, s));
|
|
1408
1410
|
}
|
|
@@ -1428,7 +1430,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
1428
1430
|
if (this.renewTokensPromise !== null)
|
|
1429
1431
|
return this.renewTokensPromise;
|
|
1430
1432
|
if (this.timeoutId)
|
|
1431
|
-
return
|
|
1433
|
+
return B.clearTimeout(this.timeoutId), this.renewTokensPromise = Te(this, !0, n), this.renewTokensPromise.then((t) => (this.renewTokensPromise = null, t));
|
|
1432
1434
|
}
|
|
1433
1435
|
async destroyAsync(n) {
|
|
1434
1436
|
return await _n(this)(n);
|
|
@@ -1443,8 +1445,8 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
1443
1445
|
return this.logoutPromise ? this.logoutPromise : (this.logoutPromise = fn(this, W, this.getFetch(), console, this.location)(n, t), this.logoutPromise.then((s) => (this.logoutPromise = null, s)));
|
|
1444
1446
|
}
|
|
1445
1447
|
};
|
|
1446
|
-
|
|
1447
|
-
let N =
|
|
1448
|
+
F.getOrCreate = (n, t) => (s, o = "default") => wn(n, t)(s, o), F.eventNames = p;
|
|
1449
|
+
let N = F;
|
|
1448
1450
|
const K = class K {
|
|
1449
1451
|
constructor(n) {
|
|
1450
1452
|
this._oidc = n;
|
|
@@ -1489,7 +1491,7 @@ const K = class K {
|
|
|
1489
1491
|
return this._oidc.generateDemonstrationOfProofOfPossessionAsync(n, t, s, o);
|
|
1490
1492
|
}
|
|
1491
1493
|
async getValidTokenAsync(n = 200, t = 50) {
|
|
1492
|
-
return
|
|
1494
|
+
return ge(this._oidc, n, t);
|
|
1493
1495
|
}
|
|
1494
1496
|
fetchWithTokens(n) {
|
|
1495
1497
|
return Ee(n, this);
|
|
@@ -1499,10 +1501,11 @@ const K = class K {
|
|
|
1499
1501
|
}
|
|
1500
1502
|
};
|
|
1501
1503
|
K.getOrCreate = (n, t = new X()) => (s, o = "default") => new K(N.getOrCreate(n, t)(s, o)), K.eventNames = N.eventNames;
|
|
1502
|
-
let
|
|
1504
|
+
let ye = K;
|
|
1503
1505
|
export {
|
|
1504
|
-
|
|
1506
|
+
ye as OidcClient,
|
|
1505
1507
|
X as OidcLocation,
|
|
1508
|
+
V as TokenAutomaticRenewMode,
|
|
1506
1509
|
Z as TokenRenewMode,
|
|
1507
1510
|
pn as getFetchDefault,
|
|
1508
1511
|
Y as getParseQueryStringFromLocation,
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(N,Y){typeof exports=="object"&&typeof module<"u"?Y(exports):typeof define=="function"&&define.amd?define(["exports"],Y):(N=typeof globalThis<"u"?globalThis:N||self,Y(N["oidc-client"]={}))})(this,function(N){"use strict";const R=console;class Ce{constructor(n,t,s,o=2e3,r=!0){this._callback=n,this._client_id=t,this._url=s,this._interval=o||2e3,this._stopOnError=r;const i=s.indexOf("/",s.indexOf("//")+2);this._frame_origin=s.substr(0,i),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=s}load(){return new Promise(n=>{this._frame.onload=()=>{n()},window.document.body.appendChild(this._frame),this._boundMessageEvent=this._message.bind(this),window.addEventListener("message",this._boundMessageEvent,!1)})}_message(n){n.origin===this._frame_origin&&n.source===this._frame.contentWindow&&(n.data==="error"?(R.error("CheckSessionIFrame: error message from check session op iframe"),this._stopOnError&&this.stop()):n.data==="changed"?(R.debug(n),R.debug("CheckSessionIFrame: changed message from check session op iframe"),this.stop(),this._callback()):R.debug("CheckSessionIFrame: "+n.data+" message from check session op iframe"))}start(n){R.debug("CheckSessionIFrame.start :"+n),this.stop();const t=()=>{this._frame.contentWindow.postMessage(this._client_id+" "+n,this._frame_origin)};t(),this._timer=window.setInterval(t,this._interval)}stop(){this._timer&&(R.debug("CheckSessionIFrame.stop"),window.clearInterval(this._timer),this._timer=null)}}const p={service_worker_not_supported_by_browser:"service_worker_not_supported_by_browser",token_aquired:"token_aquired",logout_from_another_tab:"logout_from_another_tab",logout_from_same_tab:"logout_from_same_tab",token_renewed:"token_renewed",token_timer:"token_timer",loginAsync_begin:"loginAsync_begin",loginAsync_error:"loginAsync_error",loginCallbackAsync_begin:"loginCallbackAsync_begin",loginCallbackAsync_end:"loginCallbackAsync_end",loginCallbackAsync_error:"loginCallbackAsync_error",refreshTokensAsync_begin:"refreshTokensAsync_begin",refreshTokensAsync:"refreshTokensAsync",refreshTokensAsync_end:"refreshTokensAsync_end",refreshTokensAsync_error:"refreshTokensAsync_error",refreshTokensAsync_silent_error:"refreshTokensAsync_silent_error",tryKeepExistingSessionAsync_begin:"tryKeepExistingSessionAsync_begin",tryKeepExistingSessionAsync_end:"tryKeepExistingSessionAsync_end",tryKeepExistingSessionAsync_error:"tryKeepExistingSessionAsync_error",silentLoginAsync_begin:"silentLoginAsync_begin",silentLoginAsync:"silentLoginAsync",silentLoginAsync_end:"silentLoginAsync_end",silentLoginAsync_error:"silentLoginAsync_error",syncTokensAsync_begin:"syncTokensAsync_begin",syncTokensAsync_lock_not_available:"syncTokensAsync_lock_not_available",syncTokensAsync_end:"syncTokensAsync_end",syncTokensAsync_error:"syncTokensAsync_error",tokensInvalidButWaitingActionsToRefresh:"tokensInvalidButWaitingActionsToRefresh"},P=(e,n=sessionStorage)=>{const t=y=>(n[`oidc.${e}`]=JSON.stringify({tokens:null,status:y}),Promise.resolve()),s=async()=>{if(!n[`oidc.${e}`])return n[`oidc.${e}`]=JSON.stringify({tokens:null,status:null}),{tokens:null,status:null};const y=JSON.parse(n[`oidc.${e}`]);return Promise.resolve({tokens:y.tokens,status:y.status})},o=y=>{n[`oidc.${e}`]=JSON.stringify({tokens:y})},r=async y=>{n[`oidc.session_state.${e}`]=y},i=async()=>n[`oidc.session_state.${e}`],l=y=>{n[`oidc.nonce.${e}`]=y.nonce},a=y=>{n[`oidc.jwk.${e}`]=JSON.stringify(y)},d=()=>JSON.parse(n[`oidc.jwk.${e}`]),f=async()=>({nonce:n[`oidc.nonce.${e}`]}),c=async y=>{n[`oidc.dpop_nonce.${e}`]=y},u=()=>n[`oidc.dpop_nonce.${e}`],h=()=>n[`oidc.${e}`]?JSON.stringify({tokens:JSON.parse(n[`oidc.${e}`]).tokens}):null;let g={};return{clearAsync:t,initAsync:s,setTokens:o,getTokens:h,setSessionStateAsync:r,getSessionStateAsync:i,setNonceAsync:l,getNonceAsync:f,setLoginParams:y=>{g[e]=y,n[`oidc.login.${e}`]=JSON.stringify(y)},getLoginParams:()=>{const y=n[`oidc.login.${e}`];return y?(g[e]||(g[e]=JSON.parse(y)),g[e]):(console.warn(`storage[oidc.login.${e}] is empty, you should have an bad OIDC or code configuration somewhere.`),null)},getStateAsync:async()=>n[`oidc.state.${e}`],setStateAsync:async y=>{n[`oidc.state.${e}`]=y},getCodeVerifierAsync:async()=>n[`oidc.code_verifier.${e}`],setCodeVerifierAsync:async y=>{n[`oidc.code_verifier.${e}`]=y},setDemonstratingProofOfPossessionNonce:c,getDemonstratingProofOfPossessionNonce:u,setDemonstratingProofOfPossessionJwkAsync:a,getDemonstratingProofOfPossessionJwkAsync:d}};var F=(e=>(e.AutomaticBeforeTokenExpiration="AutomaticBeforeTokensExpiration",e.AutomaticOnlyWhenFetchExecuted="AutomaticOnlyWhenFetchExecuted",e))(F||{});const Ne=e=>decodeURIComponent(Array.prototype.map.call(atob(e),n=>"%"+("00"+n.charCodeAt(0).toString(16)).slice(-2)).join("")),xe=e=>JSON.parse(Ne(e.replaceAll(/-/g,"+").replaceAll(/_/g,"/"))),fe=e=>{try{return e&&We(e,".")===2?xe(e.split(".")[1]):null}catch(n){console.warn(n)}return null},We=(e,n)=>e.split(n).length-1,X={access_token_or_id_token_invalid:"access_token_or_id_token_invalid",access_token_invalid:"access_token_invalid",id_token_invalid:"id_token_invalid"};function Le(e,n,t){if(e.issuedAt){if(typeof e.issuedAt=="string")return parseInt(e.issuedAt,10)}else return n&&n.iat?n.iat:t&&t.iat?t.iat:new Date().getTime()/1e3;return e.issuedAt}const z=(e,n=null,t)=>{if(!e)return null;let s;const o=typeof e.expiresIn=="string"?parseInt(e.expiresIn,10):e.expiresIn;e.accessTokenPayload!==void 0?s=e.accessTokenPayload:s=fe(e.accessToken);let r;n!=null&&"idToken"in n&&!("idToken"in e)?r=n.idToken:r=e.idToken;const i=e.idTokenPayload?e.idTokenPayload:fe(r),l=i&&i.exp?i.exp:Number.MAX_VALUE,a=s&&s.exp?s.exp:e.issuedAt+o;e.issuedAt=Le(e,s,i);let d;e.expiresAt?d=e.expiresAt:t===X.access_token_invalid?d=a:t===X.id_token_invalid?d=l:d=l<a?l:a;const f={...e,idTokenPayload:i,accessTokenPayload:s,expiresAt:d,idToken:r};if(n!=null&&"refreshToken"in n&&!("refreshToken"in e)){const c=n.refreshToken;return{...f,refreshToken:c}}return f},ne=(e,n,t)=>{if(!e)return null;if(!e.issued_at){const o=new Date().getTime()/1e3;e.issued_at=o}const s={accessToken:e.access_token,expiresIn:e.expires_in,idToken:e.id_token,scope:e.scope,tokenType:e.token_type,issuedAt:e.issued_at};return"refresh_token"in e&&(s.refreshToken=e.refresh_token),e.accessTokenPayload!==void 0&&(s.accessTokenPayload=e.accessTokenPayload),e.idTokenPayload!==void 0&&(s.idTokenPayload=e.idTokenPayload),z(s,n,t)},V=(e,n)=>{const t=new Date().getTime()/1e3,s=n-t;return Math.round(s-e)},_e=e=>e?V(0,e.expiresAt)>0:!1,te=async(e,n=200,t=50)=>{let s=t;if(!e.tokens)return null;for(;!_e(e.tokens)&&s>0;)e.configuration.token_automatic_renew_mode==F.AutomaticOnlyWhenFetchExecuted?await e.renewTokensAsync({}):await B({milliseconds:n}),s=s-1;return{isTokensValid:_e(e.tokens),tokens:e.tokens,numberWaited:s-t}},de=(e,n,t)=>{if(e.idTokenPayload){const s=e.idTokenPayload;if(t.issuer!==s.iss)return{isValid:!1,reason:`Issuer does not match (oidcServerConfiguration issuer) ${t.issuer} !== (idTokenPayload issuer) ${s.iss}`};const o=new Date().getTime()/1e3;if(s.exp&&s.exp<o)return{isValid:!1,reason:`Token expired (idTokenPayload exp) ${s.exp} < (currentTimeUnixSecond) ${o}`};const r=60*60*24*7;if(s.iat&&s.iat+r<o)return{isValid:!1,reason:`Token is used from too long time (idTokenPayload iat + timeInSevenDays) ${s.iat+r} < (currentTimeUnixSecond) ${o}`};if(s.nonce&&s.nonce!==n)return{isValid:!1,reason:`Nonce does not match (idTokenPayload nonce) ${s.nonce} !== (nonce) ${n}`}}return{isValid:!0,reason:""}},M=function(){const e=function(){let a,d;const f=(function(){const u={},h={setTimeout:function(m,_,w){u[_]=setTimeout(function(){m.postMessage(_),u[_]=null},w)},setInterval:function(m,_,w){u[_]=setInterval(function(){m.postMessage(_)},w)},clearTimeout:function(m,_){clearTimeout(u[_]),u[_]=null},clearInterval:function(m,_){clearInterval(u[_]),u[_]=null}};function g(m,_){const w=_.data[0],A=_.data[1],v=_.data[2];h[w]&&h[w](m,A,v)}this.onmessage=function(m){g(self,m)},this.onconnect=function(m){const _=m.ports[0];_.onmessage=function(w){g(_,w)}}}).toString();try{const u=new Blob(["(",f,")()"],{type:"application/javascript"});d=URL.createObjectURL(u)}catch{return null}const c=typeof process>"u";try{if(SharedWorker)return a=new SharedWorker(d),a.port}catch{c&&console.warn("SharedWorker not available")}try{if(Worker)return a=new Worker(d),a}catch{c&&console.warn("Worker not available")}return null}();if(!e){const a=typeof window>"u"?global:window;return{setTimeout:setTimeout.bind(a),clearTimeout:clearTimeout.bind(a),setInterval:setInterval.bind(a),clearInterval:clearInterval.bind(a)}}const n=function(){let a=0;return function(){return a++,a}}(),t={},s={};e.onmessage=function(a){const d=a.data,f=t[d];if(f){f(),t[d]=null;return}const c=s[d];c&&c()};function o(a,d){const f=n();return e.postMessage(["setTimeout",f,d]),t[f]=a,f}function r(a){e.postMessage(["clearTimeout",a]),t[a]=null}function i(a,d){const f=n();return e.postMessage(["setInterval",f,d]),s[f]=a,f}function l(a){e.postMessage(["clearInterval",a]),s[a]=null}return{setTimeout:o,clearTimeout:r,setInterval:i,clearInterval:l}}(),he="7.20.1-beta.1399";let ye=null,Q;const B=({milliseconds:e})=>new Promise(n=>M.setTimeout(n,e)),ge=(e="/")=>{try{Q=new AbortController,fetch(`${e}OidcKeepAliveServiceWorker.json?minSleepSeconds=150`,{signal:Q.signal}).catch(s=>{console.log(s)}),B({milliseconds:150*1e3}).then(ge)}catch(n){console.log(n)}},De=()=>{Q&&Q.abort()},Re=(e="/")=>fetch(`${e}OidcKeepAliveServiceWorker.json`,{headers:{"oidc-vanilla":"true"}}).then(n=>n.statusText==="oidc-service-worker").catch(n=>{console.log(n)}),$e=e=>async(n,t)=>{t(),await n.update();const s=await n.unregister();console.log(`Service worker unregistering ${s}`),await B({milliseconds:2e3}),e.reload()},O=e=>n=>new Promise(function(t,s){const o=new MessageChannel;o.port1.onmessage=function(r){r.data&&r.data.error?s(r.data.error):t(r.data)},e.active.postMessage(n,[o.port2])}),I=async(e,n)=>{const t=e.service_worker_relative_url;if(typeof window>"u"||typeof navigator>"u"||!navigator.serviceWorker||!t||e.service_worker_activate()===!1)return null;let s=null;e.register?s=await e.service_worker_register(t):s=await navigator.serviceWorker.register(t);try{await navigator.serviceWorker.ready,navigator.serviceWorker.controller||await O(s)({type:"claim"})}catch{return null}const o=async k=>O(s)({type:"clear",data:{status:k},configurationName:n}),r=async(k,S,C)=>{const b=await O(s)({type:"init",data:{oidcServerConfiguration:k,where:S,oidcConfiguration:{token_renew_mode:C.token_renew_mode,service_worker_convert_all_requests_to_cors:C.service_worker_convert_all_requests_to_cors}},configurationName:n}),U=b.version;return U!==he&&(console.warn(`Service worker ${U} version mismatch with js client version ${he}, unregistering and reloading`),await C.service_worker_update_require_callback(s,De)),{tokens:ne(b.tokens,null,C.token_renew_mode),status:b.status}},i=(k="/")=>{ye==null&&(ye="not_null",ge(k))},l=k=>O(s)({type:"setSessionState",data:{sessionState:k},configurationName:n}),a=async()=>(await O(s)({type:"getSessionState",data:null,configurationName:n})).sessionState,d=k=>(sessionStorage[`oidc.nonce.${n}`]=k.nonce,O(s)({type:"setNonce",data:{nonce:k},configurationName:n})),f=async()=>{let S=(await O(s)({type:"getNonce",data:null,configurationName:n})).nonce;return S||(S=sessionStorage[`oidc.nonce.${n}`],console.warn("nonce not found in service worker, using sessionStorage")),{nonce:S}};let c={};return{clearAsync:o,initAsync:r,startKeepAliveServiceWorker:()=>i(e.service_worker_keep_alive_path),isServiceWorkerProxyActiveAsync:()=>Re(e.service_worker_keep_alive_path),setSessionStateAsync:l,getSessionStateAsync:a,setNonceAsync:d,getNonceAsync:f,setLoginParams:k=>{c[n]=k,localStorage[`oidc.login.${n}`]=JSON.stringify(k)},getLoginParams:()=>{const k=localStorage[`oidc.login.${n}`];return c[n]||(c[n]=JSON.parse(k)),c[n]},getStateAsync:async()=>{let S=(await O(s)({type:"getState",data:null,configurationName:n})).state;return S||(S=sessionStorage[`oidc.state.${n}`],console.warn("state not found in service worker, using sessionStorage")),S},setStateAsync:async k=>(sessionStorage[`oidc.state.${n}`]=k,O(s)({type:"setState",data:{state:k},configurationName:n})),getCodeVerifierAsync:async()=>{let S=(await O(s)({type:"getCodeVerifier",data:null,configurationName:n})).codeVerifier;return S||(S=sessionStorage[`oidc.code_verifier.${n}`],console.warn("codeVerifier not found in service worker, using sessionStorage")),S},setCodeVerifierAsync:async k=>(sessionStorage[`oidc.code_verifier.${n}`]=k,O(s)({type:"setCodeVerifier",data:{codeVerifier:k},configurationName:n})),setDemonstratingProofOfPossessionNonce:async k=>{await O(s)({type:"setDemonstratingProofOfPossessionNonce",data:{demonstratingProofOfPossessionNonce:k},configurationName:n})},getDemonstratingProofOfPossessionNonce:async()=>(await O(s)({type:"getDemonstratingProofOfPossessionNonce",data:null,configurationName:n})).demonstratingProofOfPossessionNonce,setDemonstratingProofOfPossessionJwkAsync:async k=>{const S=JSON.stringify(k);await O(s)({type:"setDemonstratingProofOfPossessionJwk",data:{demonstratingProofOfPossessionJwkJson:S},configurationName:n})},getDemonstratingProofOfPossessionJwkAsync:async()=>{const k=await O(s)({type:"getDemonstratingProofOfPossessionJwk",data:null,configurationName:n});return k.demonstratingProofOfPossessionJwkJson?JSON.parse(k.demonstratingProofOfPossessionJwkJson):null}}},$={},Ke=(e,n=window.sessionStorage,t)=>{if(!$[e]&&n){const o=n.getItem(e);o&&($[e]=JSON.parse(o))}const s=1e3*t;return $[e]&&$[e].timestamp+s>Date.now()?$[e].result:null},Ue=(e,n,t=window.sessionStorage)=>{const s=Date.now();$[e]={result:n,timestamp:s},t&&t.setItem(e,JSON.stringify({result:n,timestamp:s}))};function ke(e){return new TextEncoder().encode(e)}function me(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function Fe(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(t,s){return String.fromCharCode(parseInt(s,16))})}const se=e=>{let n="";return e.forEach(function(t){n+=String.fromCharCode(t)}),me(n)};function pe(e){return me(Fe(e))}const Ve={importKeyAlgorithm:{name:"ECDSA",namedCurve:"P-256",hash:{name:"ES256"}},signAlgorithm:{name:"ECDSA",hash:{name:"SHA-256"}},generateKeyAlgorithm:{name:"ECDSA",namedCurve:"P-256"},digestAlgorithm:{name:"SHA-256"},jwtHeaderAlgorithm:"ES256"};var Me={sign:e=>async(n,t,s,o,r="dpop+jwt")=>{switch(n=Object.assign({},n),t.typ=r,t.alg=o.jwtHeaderAlgorithm,t.alg){case"ES256":t.jwk={kty:n.kty,crv:n.crv,x:n.x,y:n.y};break;case"RS256":t.jwk={kty:n.kty,n:n.n,e:n.e,kid:t.kid};break;default:throw new Error("Unknown or not implemented JWS algorithm")}const i={protected:pe(JSON.stringify(t)),payload:pe(JSON.stringify(s))},l=o.importKeyAlgorithm,a=!0,d=["sign"],f=await e.crypto.subtle.importKey("jwk",n,l,a,d),c=ke(`${i.protected}.${i.payload}`),u=o.signAlgorithm,h=await e.crypto.subtle.sign(u,f,c);return i.signature=se(new Uint8Array(h)),`${i.protected}.${i.payload}.${i.signature}`}};const Be={generate:e=>async n=>{const t=n,s=!0,o=["sign","verify"],r=await e.crypto.subtle.generateKey(t,s,o);return await e.crypto.subtle.exportKey("jwk",r.privateKey)},neuter:e=>{const n=Object.assign({},e);return delete n.d,n.key_ops=["verify"],n}};var Je={thumbprint:e=>async(n,t)=>{let s;switch(n.kty){case"EC":s='{"crv":"CRV","kty":"EC","x":"X","y":"Y"}'.replace("CRV",n.crv).replace("X",n.x).replace("Y",n.y);break;case"RSA":s='{"e":"E","kty":"RSA","n":"N"}'.replace("E",n.e).replace("N",n.n);break;default:throw new Error("Unknown or not implemented JWK type")}const o=await e.crypto.subtle.digest(t,ke(s));return se(new Uint8Array(o))}};const He=e=>async n=>await Be.generate(e)(n),we=e=>n=>async(t,s="POST",o,r={})=>{const i={jti:btoa(je()),htm:s,htu:o,iat:Math.round(Date.now()/1e3),...r},l=await Je.thumbprint(e)(t,n.digestAlgorithm);return await Me.sign(e)(t,{kid:l},i,n)},je=()=>{const e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",n="0123456789abcdef";let t=0,s="";for(let o=0;o<36;o++)e[o]!=="-"&&e[o]!=="4"&&(t=Math.random()*16|0),e[o]==="x"?s+=n[t]:e[o]==="y"?(t&=3,t|=8,s+=n[t]):s+=e[o];return s},Ae=()=>{const e=typeof window<"u"&&!!window.crypto,n=e&&!!window.crypto.subtle;return{hasCrypto:e,hasSubtleCrypto:n}},oe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",qe=e=>{const n=[];for(let t=0;t<e.byteLength;t+=1){const s=e[t]%oe.length;n.push(oe[s])}return n.join("")},re=e=>{const n=new Uint8Array(e),{hasCrypto:t}=Ae();if(t)window.crypto.getRandomValues(n);else for(let s=0;s<e;s+=1)n[s]=Math.random()*oe.length|0;return qe(n)};function Ge(e){const n=new ArrayBuffer(e.length),t=new Uint8Array(n);for(let s=0;s<e.length;s++)t[s]=e.charCodeAt(s);return t}function Se(e){return new Promise((n,t)=>{crypto.subtle.digest("SHA-256",Ge(e)).then(s=>n(se(new Uint8Array(s))),s=>t(s))})}const Ye=e=>{if(e.length<43||e.length>128)return Promise.reject(new Error("Invalid code length."));const{hasSubtleCrypto:n}=Ae();return n?Se(e):Promise.reject(new Error("window.crypto.subtle is unavailable."))},Xe=60*60,ze=e=>async(n,t=Xe,s=window.sessionStorage,o=1e4)=>{const r=`${n}/.well-known/openid-configuration`,i=`oidc.server:${n}`,l=Ke(i,s,t);if(l)return new le(l);const a=await J(e)(r,{},o);if(a.status!==200)return null;const d=await a.json();return Ue(i,d,s),new le(d)},J=e=>async(n,t={},s=1e4,o=0)=>{let r;try{const i=new AbortController;setTimeout(()=>i.abort(),s),r=await e(n,{...t,signal:i.signal})}catch(i){if(i.name==="AbortError"||i.message==="Network request failed"){if(o<=1)return await J(e)(n,t,s,o+1);throw i}else throw console.error(i.message),i}return r},ie={refresh_token:"refresh_token",access_token:"access_token"},ve=e=>async(n,t,s=ie.refresh_token,o,r={},i=1e4)=>{const l={token:t,token_type_hint:s,client_id:o};for(const[c,u]of Object.entries(r))l[c]===void 0&&(l[c]=u);const a=[];for(const c in l){const u=encodeURIComponent(c),h=encodeURIComponent(l[c]);a.push(`${u}=${h}`)}const d=a.join("&");return(await J(e)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},body:d},i)).status!==200?{success:!1}:{success:!0}},Qe=e=>async(n,t,s,o,r={},i,l=1e4)=>{for(const[h,g]of Object.entries(s))t[h]===void 0&&(t[h]=g);const a=[];for(const h in t){const g=encodeURIComponent(h),m=encodeURIComponent(t[h]);a.push(`${g}=${m}`)}const d=a.join("&"),f=await J(e)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8",...r},body:d},l);if(f.status!==200)return{success:!1,status:f.status,demonstratingProofOfPossessionNonce:null};const c=await f.json();let u=null;return f.headers.has(Z)&&(u=f.headers.get(Z)),{success:!0,status:f.status,data:ne(c,o,i),demonstratingProofOfPossessionNonce:u}},Ze=(e,n)=>async(t,s)=>{s=s?{...s}:{};const o=re(128),r=await Ye(o);await e.setCodeVerifierAsync(o),await e.setStateAsync(s.state),s.code_challenge=r,s.code_challenge_method="S256";let i="";if(s)for(const[l,a]of Object.entries(s))i===""?i+="?":i+="&",i+=`${l}=${encodeURIComponent(a)}`;n.open(`${t}${i}`)},Z="DPoP-Nonce",en=e=>async(n,t,s,o,r=1e4)=>{t=t?{...t}:{},t.code_verifier=await e.getCodeVerifierAsync();const i=[];for(const c in t){const u=encodeURIComponent(c),h=encodeURIComponent(t[c]);i.push(`${u}=${h}`)}const l=i.join("&"),a=await J(fetch)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8",...s},body:l},r);if(await Promise.all([e.setCodeVerifierAsync(null),e.setStateAsync(null)]),a.status!==200)return{success:!1,status:a.status};let d=null;a.headers.has(Z)&&(d=a.headers.get(Z));const f=await a.json();return{success:!0,data:{state:t.state,tokens:ne(f,null,o),demonstratingProofOfPossessionNonce:d}}};async function Te(e,n,t){const s=l=>{e.tokens=l},{tokens:o,status:r}=await ee(e)(0,n,t,s);return await I(e.configuration,e.configurationName)||await P(e.configurationName,e.configuration.storage).setTokens(e.tokens),e.tokens?o:(await e.destroyAsync(r),null)}const nn=async(e,n)=>{const t=await I(n,e.configurationName);if(t){const s=await e.initAsync(n.authority,n.authority_configuration),{tokens:o}=await t.initAsync(s,"tryKeepExistingSessionAsync",n);return o}else{const s=P(e.configurationName,n.storage??sessionStorage);let{tokens:o}=await s.initAsync();return o=z(o,e.tokens,n.token_renew_mode),o}};async function be(e,n=!1,t=null){const s=e.configuration,o=`${s.client_id}_${e.configurationName}_${s.authority}`;let r;const i=await I(e.configuration,e.configurationName);return(s==null?void 0:s.storage)===(window==null?void 0:window.sessionStorage)&&!i?r=await Te(e,n,t):r=await navigator.locks.request(o,{ifAvailable:!0},async l=>l?await Te(e,n,t):(e.publishEvent(x.eventNames.syncTokensAsync_lock_not_available,{lock:"lock not available"}),await nn(e,s))),r?(e.timeoutId&&(e.timeoutId=H(e,e.tokens.expiresAt,t)),e.tokens):null}const H=(e,n,t=null)=>{const s=e.configuration.refresh_time_before_tokens_expiration_in_second;return M.setTimeout(async()=>{const r={timeLeft:V(s,n)};e.publishEvent(x.eventNames.token_timer,r),await be(e,!1,t)},1e3)},W={FORCE_REFRESH:"FORCE_REFRESH",SESSION_LOST:"SESSION_LOST",NOT_CONNECTED:"NOT_CONNECTED",TOKENS_VALID:"TOKENS_VALID",TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID:"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID",LOGOUT_FROM_ANOTHER_TAB:"LOGOUT_FROM_ANOTHER_TAB",REQUIRE_SYNC_TOKENS:"REQUIRE_SYNC_TOKENS"},tn=e=>async(n,t,s,o=!1)=>{const r={nonce:null};if(!s)return{tokens:null,status:"NOT_CONNECTED",nonce:r};let i=r;const l=await e.initAsync(n.authority,n.authority_configuration),a=await I(n,t);if(a){const{status:c,tokens:u}=await a.initAsync(l,"syncTokensAsync",n);if(c==="LOGGED_OUT")return{tokens:null,status:"LOGOUT_FROM_ANOTHER_TAB",nonce:r};if(c==="SESSIONS_LOST")return{tokens:null,status:"SESSIONS_LOST",nonce:r};if(!c||!u)return{tokens:null,status:"REQUIRE_SYNC_TOKENS",nonce:r};if(u.issuedAt!==s.issuedAt){const g=V(n.refresh_time_before_tokens_expiration_in_second,u.expiresAt)>0?"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID":"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID",m=await a.getNonceAsync();return{tokens:u,status:g,nonce:m}}i=await a.getNonceAsync()}else{const c=P(t,n.storage??sessionStorage);let{tokens:u,status:h}=await c.initAsync();if(u&&(u=z(u,e.tokens,n.token_renew_mode)),u){if(h==="SESSIONS_LOST")return{tokens:null,status:"SESSIONS_LOST",nonce:r};if(u.issuedAt!==s.issuedAt){const m=V(n.refresh_time_before_tokens_expiration_in_second,u.expiresAt)>0?"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID":"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID",_=await c.getNonceAsync();return{tokens:u,status:m,nonce:_}}}else return{tokens:null,status:"LOGOUT_FROM_ANOTHER_TAB",nonce:r};i=await c.getNonceAsync()}const f=V(n.refresh_time_before_tokens_expiration_in_second,s.expiresAt)>0?"TOKENS_VALID":"TOKENS_INVALID";return o?{tokens:s,status:"FORCE_REFRESH",nonce:i}:{tokens:s,status:f,nonce:i}},ee=e=>async(n=0,t=!1,s=null,o)=>{for(;!navigator.onLine&&document.hidden;)await B({milliseconds:1e3}),e.publishEvent(p.refreshTokensAsync,{message:"wait because navigator is offline and hidden"});let r=6;for(;!navigator.onLine&&r>0;)await B({milliseconds:1e3}),r--,e.publishEvent(p.refreshTokensAsync,{message:`wait because navigator is offline try ${r}`});const i=document.hidden,l=n+1;s||(s={});const a=e.configuration,d=(c,u=null,h=null)=>ae(e.configurationName,e.configuration,e.publishEvent.bind(e))(c,u,h),f=async()=>{try{let c;const u=await I(a,e.configurationName);u?c=u.getLoginParams():c=P(e.configurationName,a.storage).getLoginParams();const h=await d({...c.extras,...s,prompt:"none"});return h?h.error?(o(null),e.publishEvent(p.refreshTokensAsync_error,{message:"refresh token silent"}),{tokens:null,status:"SESSION_LOST"}):(o(h.tokens),e.publishEvent(x.eventNames.token_renewed,{}),{tokens:h.tokens,status:"LOGGED"}):(o(null),e.publishEvent(p.refreshTokensAsync_error,{message:"refresh token silent not active"}),{tokens:null,status:"SESSION_LOST"})}catch(c){return console.error(c),e.publishEvent(p.refreshTokensAsync_silent_error,{message:"exceptionSilent",exception:c.message}),await ee(e)(l,t,s,o)}};if(n>4)return i?{tokens:e.tokens,status:"GIVE_UP"}:(o(null),e.publishEvent(p.refreshTokensAsync_error,{message:"refresh token"}),{tokens:null,status:"SESSION_LOST"});try{const{status:c,tokens:u,nonce:h}=await tn(e)(a,e.configurationName,e.tokens,t);switch(c){case W.SESSION_LOST:return o(null),e.publishEvent(p.refreshTokensAsync_error,{message:"refresh token session lost"}),{tokens:null,status:"SESSION_LOST"};case W.NOT_CONNECTED:return o(null),{tokens:null,status:null};case W.TOKENS_VALID:return o(u),{tokens:u,status:"LOGGED_IN"};case W.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID:return o(u),e.publishEvent(x.eventNames.token_renewed,{reason:"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID"}),{tokens:u,status:"LOGGED_IN"};case W.LOGOUT_FROM_ANOTHER_TAB:return o(null),e.publishEvent(p.logout_from_another_tab,{status:"session syncTokensAsync"}),{tokens:null,status:"LOGGED_OUT"};case W.REQUIRE_SYNC_TOKENS:return a.token_automatic_renew_mode==F.AutomaticOnlyWhenFetchExecuted&&W.FORCE_REFRESH!==c?(e.publishEvent(p.tokensInvalidButWaitingActionsToRefresh,{}),{tokens:e.tokens,status:"GIVE_UP"}):(e.publishEvent(p.refreshTokensAsync_begin,{tryNumber:n}),await f());default:{if(a.token_automatic_renew_mode==F.AutomaticOnlyWhenFetchExecuted&&W.FORCE_REFRESH!==c)return e.publishEvent(p.tokensInvalidButWaitingActionsToRefresh,{}),{tokens:e.tokens,status:"GIVE_UP"};if(e.publishEvent(p.refreshTokensAsync_begin,{refreshToken:u.refreshToken,status:c,tryNumber:n}),!u.refreshToken)return await f();const g=a.client_id,m=a.redirect_uri,_=a.authority,A={...a.token_request_extras?a.token_request_extras:{}};for(const[T,y]of Object.entries(s))T.endsWith(":token_request")&&(A[T.replace(":token_request","")]=y);return await(async()=>{const T={client_id:g,redirect_uri:m,grant_type:"refresh_token",refresh_token:u.refreshToken},y=await e.initAsync(_,a.authority_configuration),k=document.hidden?1e4:3e4*10,S=y.tokenEndpoint,C={};a.demonstrating_proof_of_possession&&(C.DPoP=await e.generateDemonstrationOfProofOfPossessionAsync(u.accessToken,S,"POST"));const b=await Qe(e.getFetch())(S,T,A,u,C,a.token_renew_mode,k);if(b.success){const{isValid:U,reason:E}=de(b.data,h.nonce,y);if(!U)return o(null),e.publishEvent(p.refreshTokensAsync_error,{message:`refresh token return not valid tokens, reason: ${E}`}),{tokens:null,status:"SESSION_LOST"};if(o(b.data),b.demonstratingProofOfPossessionNonce){const D=await I(a,e.configurationName);D?await D.setDemonstratingProofOfPossessionNonce(b.demonstratingProofOfPossessionNonce):await P(e.configurationName,a.storage).setDemonstratingProofOfPossessionNonce(b.demonstratingProofOfPossessionNonce)}return e.publishEvent(p.refreshTokensAsync_end,{success:b.success}),e.publishEvent(x.eventNames.token_renewed,{reason:"REFRESH_TOKEN"}),{tokens:b.data,status:"LOGGED_IN"}}else return e.publishEvent(p.refreshTokensAsync_silent_error,{message:"bad request",tokenResponse:b}),b.status>=400&&b.status<500?(o(null),e.publishEvent(p.refreshTokensAsync_error,{message:`session lost: ${b.status}`}),{tokens:null,status:"SESSION_LOST"}):await ee(e)(l,t,s,o)})()}}}catch(c){return console.error(c),e.publishEvent(p.refreshTokensAsync_silent_error,{message:"exception",exception:c.message}),ee(e)(l,t,s,o)}},ae=(e,n,t)=>(s=null,o=null,r=null)=>{if(!n.silent_redirect_uri||!n.silent_login_uri)return Promise.resolve(null);try{t(p.silentLoginAsync_begin,{});let i="";if(o&&(s==null&&(s={}),s.state=o),r&&(s==null&&(s={}),s.scope=r),s!=null)for(const[c,u]of Object.entries(s))i===""?i=`?${encodeURIComponent(c)}=${encodeURIComponent(u)}`:i+=`&${encodeURIComponent(c)}=${encodeURIComponent(u)}`;const l=n.silent_login_uri+i,a=l.indexOf("/",l.indexOf("//")+2),d=l.substring(0,a),f=document.createElement("iframe");return f.width="0px",f.height="0px",f.id=`${e}_oidc_iframe`,f.setAttribute("src",l),document.body.appendChild(f),new Promise((c,u)=>{let h=!1;const g=()=>{window.removeEventListener("message",m),f.remove(),h=!0},m=_=>{if(_.origin===d&&_.source===f.contentWindow){const w=`${e}_oidc_tokens:`,A=`${e}_oidc_error:`,v=`${e}_oidc_exception:`,T=_.data;if(T&&typeof T=="string"&&!h){if(T.startsWith(w)){const y=JSON.parse(_.data.replace(w,""));t(p.silentLoginAsync_end,{}),c(y),g()}else if(T.startsWith(A)){const y=JSON.parse(_.data.replace(A,""));t(p.silentLoginAsync_error,y),c({error:"oidc_"+y.error,tokens:null,sessionState:null}),g()}else if(T.startsWith(v)){const y=JSON.parse(_.data.replace(v,""));t(p.silentLoginAsync_error,y),u(new Error(y.error)),g()}}}};try{window.addEventListener("message",m);const _=n.silent_login_timeout;setTimeout(()=>{h||(g(),t(p.silentLoginAsync_error,{reason:"timeout"}),u(new Error("timeout")))},_)}catch(_){g(),t(p.silentLoginAsync_error,_),u(_)}})}catch(i){throw t(p.silentLoginAsync_error,i),i}},sn=(e,n,t,s,o)=>(r=null,i=void 0)=>{r={...r};const l=(d,f,c)=>ae(n,t,s.bind(o))(d,f,c);return(async()=>{o.timeoutId&&M.clearTimeout(o.timeoutId);let d;r&&"state"in r&&(d=r.state,delete r.state);try{const f=t.extras?{...t.extras,...r}:r,c=await l({...f,prompt:"none"},d,i);if(c)return o.tokens=c.tokens,s(p.token_aquired,{}),o.timeoutId=H(o,o.tokens.expiresAt,r),{}}catch(f){return f}})()},on=(e,n,t)=>(s,o,r,i=!1)=>{const l=(a,d=void 0,f=void 0)=>ae(e.configurationName,t,e.publishEvent.bind(e))(a,d,f);return new Promise((a,d)=>{if(t.silent_login_uri&&t.silent_redirect_uri&&t.monitor_session&&s&&r&&!i){const f=()=>{e.checkSessionIFrame.stop();const c=e.tokens;if(c===null)return;const u=c.idToken,h=c.idTokenPayload;return l({prompt:"none",id_token_hint:u,scope:t.scope||"openid"}).then(g=>{if(g.error)throw new Error(g.error);const m=g.tokens.idTokenPayload;if(h.sub===m.sub){const _=g.sessionState;e.checkSessionIFrame.start(g.sessionState),h.sid===m.sid?console.debug("SessionMonitor._callback: Same sub still logged in at OP, restarting check session iframe; session_state:",_):console.debug("SessionMonitor._callback: Same sub still logged in at OP, session state has changed, restarting check session iframe; session_state:",_)}else console.debug("SessionMonitor._callback: Different subject signed into OP:",m.sub)}).catch(async g=>{console.warn("SessionMonitor._callback: Silent login failed, logging out other tabs:",g);for(const[m,_]of Object.entries(n))await _.logoutOtherTabAsync(t.client_id,h.sub)})};e.checkSessionIFrame=new Ce(f,o,s),e.checkSessionIFrame.load().then(()=>{e.checkSessionIFrame.start(r),a(e.checkSessionIFrame)}).catch(c=>{d(c)})}else a(null)})},Ee=e=>{const n=e.match(/^([a-z][\w-]+\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);if(!n)throw new Error("Invalid URL");let t=n[6],s=n[7];if(s){const o=s.split("?");o.length===2&&(s=o[0],t=o[1])}return t.startsWith("?")&&(t=t.slice(1)),n&&{href:e,protocol:n[1],host:n[2],hostname:n[3],port:n[4],path:n[5],search:t,hash:s}},rn=e=>{const n=Ee(e);let{path:t}=n;t.endsWith("/")&&(t=t.slice(0,-1));let{hash:s}=n;return s==="#_=_"&&(s=""),s&&(t+=s),t},j=e=>{const n=Ee(e),{search:t}=n;return an(t)},an=e=>{const n={};let t,s,o;const r=e.split("&");for(s=0,o=r.length;s<o;s++)t=r[s].split("="),n[decodeURIComponent(t[0])]=decodeURIComponent(t[1]);return n},cn=(e,n,t,s,o)=>(r=void 0,i=null,l=!1,a=void 0)=>{const d=i;return i={...i},(async()=>{const c=r||o.getPath();if("state"in i||(i.state=re(16)),t(p.loginAsync_begin,{}),i)for(const u of Object.keys(i))u.endsWith(":token_request")&&delete i[u];try{const u=l?n.silent_redirect_uri:n.redirect_uri;a||(a=n.scope);const h=n.extras?{...n.extras,...i}:i;h.nonce||(h.nonce=re(12));const g={nonce:h.nonce},m=await I(n,e),_=await s(n.authority,n.authority_configuration);let w;if(m)m.setLoginParams({callbackPath:c,extras:d}),await m.initAsync(_,"loginAsync",n),await m.setNonceAsync(g),m.startKeepAliveServiceWorker(),w=m;else{const v=P(e,n.storage??sessionStorage);v.setLoginParams({callbackPath:c,extras:d}),await v.setNonceAsync(g),w=v}const A={client_id:n.client_id,redirect_uri:u,scope:a,response_type:"code",...h};await Ze(w,o)(_.authorizationEndpoint,A)}catch(u){throw t(p.loginAsync_error,u),u}})()},ln=e=>async(n=!1)=>{try{e.publishEvent(p.loginCallbackAsync_begin,{});const t=e.configuration,s=t.client_id,o=n?t.silent_redirect_uri:t.redirect_uri,r=t.authority,i=t.token_request_timeout,l=await e.initAsync(r,t.authority_configuration),a=e.location.getCurrentHref(),f=j(a).session_state,c=await I(t,e.configurationName);let u,h,g,m;if(c)await c.initAsync(l,"loginCallbackAsync",t),await c.setSessionStateAsync(f),h=await c.getNonceAsync(),g=c.getLoginParams(),m=await c.getStateAsync(),c.startKeepAliveServiceWorker(),u=c;else{const E=P(e.configurationName,t.storage??sessionStorage);await E.setSessionStateAsync(f),h=await E.getNonceAsync(),g=E.getLoginParams(),m=await E.getStateAsync(),u=E}const _=j(a);if(_.error||_.error_description)throw new Error(`Error from OIDC server: ${_.error} - ${_.error_description}`);if(_.iss&&_.iss!==l.issuer)throw console.error(),new Error(`Issuer not valid (expected: ${l.issuer}, received: ${_.iss})`);if(_.state&&_.state!==m)throw new Error(`State not valid (expected: ${m}, received: ${_.state})`);const w={code:_.code,grant_type:"authorization_code",client_id:t.client_id,redirect_uri:o},A={};if(t.token_request_extras)for(const[E,D]of Object.entries(t.token_request_extras))A[E]=D;if(g&&g.extras)for(const[E,D]of Object.entries(g.extras))E.endsWith(":token_request")&&(A[E.replace(":token_request","")]=D);const v=l.tokenEndpoint,T={};if(t.demonstrating_proof_of_possession)if(c)T.DPoP=`DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${e.configurationName}`;else{const E=await He(window)(t.demonstrating_proof_of_possession_configuration.generateKeyAlgorithm);await P(e.configurationName,t.storage).setDemonstratingProofOfPossessionJwkAsync(E),T.DPoP=await we(window)(t.demonstrating_proof_of_possession_configuration)(E,"POST",v)}const y=await en(u)(v,{...w,...A},T,e.configuration.token_renew_mode,i);if(!y.success)throw new Error("Token request failed");let k;const S=y.data.tokens,C=y.data.demonstratingProofOfPossessionNonce;if(y.data.state!==A.state)throw new Error("state is not valid");const{isValid:b,reason:U}=de(S,h.nonce,l);if(!b)throw new Error(`Tokens are not OpenID valid, reason: ${U}`);if(c){if(S.refreshToken&&!S.refreshToken.includes("SECURED_BY_OIDC_SERVICE_WORKER"))throw new Error("Refresh token should be hidden by service worker");if(C&&S.accessToken&&S.accessToken.includes("SECURED_BY_OIDC_SERVICE_WORKER"))throw new Error("Demonstration of proof of possession require Access token not hidden by service worker")}if(c)await c.initAsync(l,"syncTokensAsync",t),k=c.getLoginParams(),C&&await c.setDemonstratingProofOfPossessionNonce(C);else{const E=P(e.configurationName,t.storage);k=E.getLoginParams(),C&&await E.setDemonstratingProofOfPossessionNonce(C)}return await e.startCheckSessionAsync(l.checkSessionIframe,s,f,n),e.publishEvent(p.loginCallbackAsync_end,{}),{tokens:S,state:"request.state",callbackPath:k.callbackPath}}catch(t){throw console.error(t),e.publishEvent(p.loginCallbackAsync_error,t),t}},Oe={access_token:"access_token",refresh_token:"refresh_token"},ce=(e,n)=>{const t={};if(e){for(const[s,o]of Object.entries(e))if(s.endsWith(n)){const r=s.replace(n,"");t[r]=o}return t}return t},un=e=>{const n={};if(e){for(const[t,s]of Object.entries(e))t.includes(":")||(n[t]=s);return n}return n},fn=e=>async n=>{M.clearTimeout(e.timeoutId),e.timeoutId=null,e.checkSessionIFrame&&e.checkSessionIFrame.stop();const t=await I(e.configuration,e.configurationName);t?await t.clearAsync(n):await P(e.configurationName,e.configuration.storage).clearAsync(n),e.tokens=null,e.userInfo=null},_n=(e,n,t,s,o)=>async(r=void 0,i=null)=>{const l=e.configuration,a=await e.initAsync(l.authority,l.authority_configuration);r&&typeof r!="string"&&(r=void 0,s.warn("callbackPathOrUrl path is not a string"));const d=r??o.getPath();let f=!1;r&&(f=r.includes("https://")||r.includes("http://"));const c=f?r:o.getOrigin()+d,u=e.tokens?e.tokens.idToken:"";try{const w=a.revocationEndpoint;if(w){const A=[],v=e.tokens?e.tokens.accessToken:null;if(v&&l.logout_tokens_to_invalidate.includes(Oe.access_token)){const y=ce(i,":revoke_access_token"),k=ve(t)(w,v,ie.access_token,l.client_id,y);A.push(k)}const T=e.tokens?e.tokens.refreshToken:null;if(T&&l.logout_tokens_to_invalidate.includes(Oe.refresh_token)){const y=ce(i,":revoke_refresh_token"),k=ve(t)(w,T,ie.refresh_token,l.client_id,y);A.push(k)}A.length>0&&await Promise.all(A)}}catch(w){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(w)}const h=e.tokens&&e.tokens.idTokenPayload?e.tokens.idTokenPayload.sub:null;await e.destroyAsync("LOGGED_OUT");for(const[w,A]of Object.entries(n))A!==e?await e.logoutSameTabAsync(e.configuration.client_id,h):e.publishEvent(p.logout_from_same_tab,{});const g=ce(i,":oidc");if(g&&g.no_reload==="true")return;const _=un(i);if(a.endSessionEndpoint){"id_token_hint"in _||(_.id_token_hint=u),!("post_logout_redirect_uri"in _)&&r!==null&&(_.post_logout_redirect_uri=c);let w="";for(const[A,v]of Object.entries(_))v!=null&&(w===""?w+="?":w+="&",w+=`${A}=${encodeURIComponent(v)}`);o.open(`${a.endSessionEndpoint}${w}`)}else o.reload()},Pe=(e,n)=>async(...t)=>{var u;const[s,o,...r]=t,i=o?{...o}:{method:"GET"};let l=new Headers;i.headers&&(l=i.headers instanceof Headers?i.headers:new Headers(i.headers));const a=n;console.log("before",te);const d=await te(a);console.log("getValidToken",d);const f=(u=d==null?void 0:d.tokens)==null?void 0:u.accessToken;if(l.has("Accept")||l.set("Accept","application/json"),f){if(a.configuration.demonstrating_proof_of_possession){const h=await a.generateDemonstrationOfProofOfPossessionAsync(f,s.toString(),i.method);l.set("Authorization",`PoP ${f}`),l.set("DPoP",h)}else l.set("Authorization",`Bearer ${f}`);i.credentials||(i.credentials="same-origin")}const c={...i,headers:l};return await e(s,c,...r)},dn=e=>async(n=!1)=>{if(console.log("oidc.userInfo",e.userInfo),e.userInfo!=null&&!n)return e.userInfo;const t=e.configuration,o=(await e.initAsync(t.authority,t.authority_configuration)).userInfoEndpoint,i=await(async()=>{const a=await Pe(fetch,e)(o);return a.status!==200?null:a.json()})();return e.userInfo=i,i};class q{open(n){window.location.href=n}reload(){window.location.reload()}getCurrentHref(){return window.location.href}getPath(){const n=window.location;return n.pathname+(n.search||"")+(n.hash||"")}getOrigin(){return window.origin}}const hn=e=>!!(e.os==="iOS"&&e.osVersion.startsWith("12")||e.os==="Mac OS X"&&e.osVersion.startsWith("10_15_6")),yn=e=>{const n=e.appVersion,t=e.userAgent,s="-";let o=s;const r=[{s:"Windows 10",r:/(Windows 10.0|Windows NT 10.0)/},{s:"Windows 8.1",r:/(Windows 8.1|Windows NT 6.3)/},{s:"Windows 8",r:/(Windows 8|Windows NT 6.2)/},{s:"Windows 7",r:/(Windows 7|Windows NT 6.1)/},{s:"Windows Vista",r:/Windows NT 6.0/},{s:"Windows Server 2003",r:/Windows NT 5.2/},{s:"Windows XP",r:/(Windows NT 5.1|Windows XP)/},{s:"Windows 2000",r:/(Windows NT 5.0|Windows 2000)/},{s:"Windows ME",r:/(Win 9x 4.90|Windows ME)/},{s:"Windows 98",r:/(Windows 98|Win98)/},{s:"Windows 95",r:/(Windows 95|Win95|Windows_95)/},{s:"Windows NT 4.0",r:/(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/},{s:"Windows CE",r:/Windows CE/},{s:"Windows 3.11",r:/Win16/},{s:"Android",r:/Android/},{s:"Open BSD",r:/OpenBSD/},{s:"Sun OS",r:/SunOS/},{s:"Chrome OS",r:/CrOS/},{s:"Linux",r:/(Linux|X11(?!.*CrOS))/},{s:"iOS",r:/(iPhone|iPad|iPod)/},{s:"Mac OS X",r:/Mac OS X/},{s:"Mac OS",r:/(Mac OS|MacPPC|MacIntel|Mac_PowerPC|Macintosh)/},{s:"QNX",r:/QNX/},{s:"UNIX",r:/UNIX/},{s:"BeOS",r:/BeOS/},{s:"OS/2",r:/OS\/2/},{s:"Search Bot",r:/(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/}];for(const l in r){const a=r[l];if(a.r.test(t)){o=a.s;break}}let i=s;switch(/Windows/.test(o)&&(i=/Windows (.*)/.exec(o)[1],o="Windows"),o){case"Mac OS":case"Mac OS X":case"Android":i=/(?:Android|Mac OS|Mac OS X|MacPPC|MacIntel|Mac_PowerPC|Macintosh) ([._\d]+)/.exec(t)[1];break;case"iOS":{const l=/OS (\d+)_(\d+)_?(\d+)?/.exec(n);l!=null&&l.length>2&&(i=l[1]+"."+l[2]+"."+(parseInt(l[3])|0));break}}return{os:o,osVersion:i}};function gn(){const e=navigator.userAgent;let n,t=e.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];if(/trident/i.test(t[1]))return n=/\brv[ :]+(\d+)/g.exec(e)||[],{name:"ie",version:n[1]||""};if(t[1]==="Chrome"&&(n=e.match(/\bOPR|Edge\/(\d+)/),n!=null)){let s=n[1];if(!s){const o=e.split(n[0]+"/");o.length>1&&(s=o[1])}return{name:"opera",version:s}}return t=t[2]?[t[1],t[2]]:[navigator.appName,navigator.appVersion,"-?"],(n=e.match(/version\/(\d+)/i))!=null&&t.splice(1,1,n[1]),{name:t[0].toLowerCase(),version:t[1]}}const kn=()=>{const{name:e,version:n}=gn();if(e==="chrome"&&parseInt(n)<=70||e==="opera"&&(!n||parseInt(n.split(".")[0])<80)||e==="ie")return!1;const t=yn(navigator);return!hn(t)},mn=async e=>{let n;if(e.tokens!=null)return!1;e.publishEvent(p.tryKeepExistingSessionAsync_begin,{});try{const t=e.configuration,s=await e.initAsync(t.authority,t.authority_configuration);if(n=await I(t,e.configurationName),n){const{tokens:o}=await n.initAsync(s,"tryKeepExistingSessionAsync",t);if(o){n.startKeepAliveServiceWorker(),e.tokens=o;const r=n.getLoginParams(e.configurationName);e.timeoutId=H(e,e.tokens.expiresAt,r.extras);const i=await n.getSessionStateAsync();return await e.startCheckSessionAsync(s.check_session_iframe,t.client_id,i),e.publishEvent(p.tryKeepExistingSessionAsync_end,{success:!0,message:"tokens inside ServiceWorker are valid"}),!0}e.publishEvent(p.tryKeepExistingSessionAsync_end,{success:!1,message:"no exiting session found"})}else{t.service_worker_relative_url&&e.publishEvent(p.service_worker_not_supported_by_browser,{message:"service worker is not supported by this browser"});const o=P(e.configurationName,t.storage??sessionStorage),{tokens:r}=await o.initAsync();if(r){e.tokens=z(r,null,t.token_renew_mode);const i=o.getLoginParams();e.timeoutId=H(e,e.tokens.expiresAt,i.extras);const l=await o.getSessionStateAsync();return await e.startCheckSessionAsync(s.check_session_iframe,t.client_id,l),e.publishEvent(p.tryKeepExistingSessionAsync_end,{success:!0,message:"tokens inside storage are valid"}),!0}}return e.publishEvent(p.tryKeepExistingSessionAsync_end,{success:!1,message:n?"service worker sessions not retrieved":"session storage sessions not retrieved"}),!1}catch(t){return console.error(t),n&&await n.clearAsync(),e.publishEvent(p.tryKeepExistingSessionAsync_error,"tokens inside ServiceWorker are invalid"),!1}},Ie=()=>fetch;class le{constructor(n){this.authorizationEndpoint=n.authorization_endpoint,this.tokenEndpoint=n.token_endpoint,this.revocationEndpoint=n.revocation_endpoint,this.userInfoEndpoint=n.userinfo_endpoint,this.checkSessionIframe=n.check_session_iframe,this.issuer=n.issuer,this.endSessionEndpoint=n.end_session_endpoint}}const L={},pn=(e,n=new q)=>(t,s="default")=>(L[s]||(L[s]=new x(t,s,e,n)),L[s]),wn=async e=>{const{parsedTokens:n,callbackPath:t}=await e.loginCallbackAsync();return e.timeoutId=H(e,n.expiresAt),{callbackPath:t}},An=e=>Math.floor(Math.random()*e),G=class G{constructor(n,t="default",s,o=new q){this.initPromise=null,this.tryKeepExistingSessionPromise=null,this.loginPromise=null,this.loginCallbackPromise=null,this.loginCallbackWithAutoTokensRenewPromise=null,this.userInfoPromise=null,this.renewTokensPromise=null,this.logoutPromise=null;let r=n.silent_login_uri;n.silent_redirect_uri&&!n.silent_login_uri&&(r=`${n.silent_redirect_uri.replace("-callback","").replace("callback","")}-login`);let i=n.refresh_time_before_tokens_expiration_in_second??120;i>60&&(i=i-Math.floor(Math.random()*40)),this.location=o??new q;const l=n.service_worker_update_require_callback??$e(this.location);this.configuration={...n,silent_login_uri:r,token_automatic_renew_mode:n.token_automatic_renew_mode??F.AutomaticBeforeTokenExpiration,monitor_session:n.monitor_session??!1,refresh_time_before_tokens_expiration_in_second:i,silent_login_timeout:n.silent_login_timeout??12e3,token_renew_mode:n.token_renew_mode??X.access_token_or_id_token_invalid,demonstrating_proof_of_possession:n.demonstrating_proof_of_possession??!1,authority_timeout_wellknowurl_in_millisecond:n.authority_timeout_wellknowurl_in_millisecond??1e4,logout_tokens_to_invalidate:n.logout_tokens_to_invalidate??["access_token","refresh_token"],service_worker_update_require_callback:l,service_worker_activate:n.service_worker_activate??kn,demonstrating_proof_of_possession_configuration:n.demonstrating_proof_of_possession_configuration??Ve},this.getFetch=s??Ie,this.configurationName=t,this.tokens=null,this.userInfo=null,this.events=[],this.timeoutId=null,this.loginCallbackWithAutoTokensRenewAsync.bind(this),this.initAsync.bind(this),this.loginCallbackAsync.bind(this),this.subscribeEvents.bind(this),this.removeEventSubscription.bind(this),this.publishEvent.bind(this),this.destroyAsync.bind(this),this.logoutAsync.bind(this),this.renewTokensAsync.bind(this),this.initAsync(this.configuration.authority,this.configuration.authority_configuration)}subscribeEvents(n){const t=An(9999999999999).toString();return this.events.push({id:t,func:n}),t}removeEventSubscription(n){const t=this.events.filter(s=>s.id!==n);this.events=t}publishEvent(n,t){this.events.forEach(s=>{s.func(n,t)})}static get(n="default"){const t=typeof process>"u";if(!Object.prototype.hasOwnProperty.call(L,n)&&t)throw Error(`OIDC library does seem initialized.
|
|
2
|
-
Please checkout that you are using OIDC hook inside a <OidcProvider configurationName="${n}"></OidcProvider> component.`);return L[n]}_silentLoginCallbackFromIFrame(){if(this.configuration.silent_redirect_uri&&this.configuration.silent_login_uri){const n=this.location,t=j(n.getCurrentHref());window.parent.postMessage(`${this.configurationName}_oidc_tokens:${JSON.stringify({tokens:this.tokens,sessionState:t.session_state})}`,n.getOrigin())}}_silentLoginErrorCallbackFromIFrame(n=null){if(this.configuration.silent_redirect_uri&&this.configuration.silent_login_uri){const t=this.location,s=j(t.getCurrentHref());s.error?window.parent.postMessage(`${this.configurationName}_oidc_error:${JSON.stringify({error:s.error})}`,t.getOrigin()):window.parent.postMessage(`${this.configurationName}_oidc_exception:${JSON.stringify({error:n==null?"":n.toString()})}`,t.getOrigin())}}async silentLoginCallbackAsync(){try{await this.loginCallbackAsync(!0),this._silentLoginCallbackFromIFrame()}catch(n){console.error(n),this._silentLoginErrorCallbackFromIFrame(n)}}async initAsync(n,t){if(this.initPromise!==null)return this.initPromise;const s=async()=>{if(t!=null)return new
|
|
1
|
+
(function(N,Y){typeof exports=="object"&&typeof module<"u"?Y(exports):typeof define=="function"&&define.amd?define(["exports"],Y):(N=typeof globalThis<"u"?globalThis:N||self,Y(N["oidc-client"]={}))})(this,function(N){"use strict";const R=console;class Ce{constructor(n,t,s,o=2e3,r=!0){this._callback=n,this._client_id=t,this._url=s,this._interval=o||2e3,this._stopOnError=r;const i=s.indexOf("/",s.indexOf("//")+2);this._frame_origin=s.substr(0,i),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=s}load(){return new Promise(n=>{this._frame.onload=()=>{n()},window.document.body.appendChild(this._frame),this._boundMessageEvent=this._message.bind(this),window.addEventListener("message",this._boundMessageEvent,!1)})}_message(n){n.origin===this._frame_origin&&n.source===this._frame.contentWindow&&(n.data==="error"?(R.error("CheckSessionIFrame: error message from check session op iframe"),this._stopOnError&&this.stop()):n.data==="changed"?(R.debug(n),R.debug("CheckSessionIFrame: changed message from check session op iframe"),this.stop(),this._callback()):R.debug("CheckSessionIFrame: "+n.data+" message from check session op iframe"))}start(n){R.debug("CheckSessionIFrame.start :"+n),this.stop();const t=()=>{this._frame.contentWindow.postMessage(this._client_id+" "+n,this._frame_origin)};t(),this._timer=window.setInterval(t,this._interval)}stop(){this._timer&&(R.debug("CheckSessionIFrame.stop"),window.clearInterval(this._timer),this._timer=null)}}const p={service_worker_not_supported_by_browser:"service_worker_not_supported_by_browser",token_aquired:"token_aquired",logout_from_another_tab:"logout_from_another_tab",logout_from_same_tab:"logout_from_same_tab",token_renewed:"token_renewed",token_timer:"token_timer",loginAsync_begin:"loginAsync_begin",loginAsync_error:"loginAsync_error",loginCallbackAsync_begin:"loginCallbackAsync_begin",loginCallbackAsync_end:"loginCallbackAsync_end",loginCallbackAsync_error:"loginCallbackAsync_error",refreshTokensAsync_begin:"refreshTokensAsync_begin",refreshTokensAsync:"refreshTokensAsync",refreshTokensAsync_end:"refreshTokensAsync_end",refreshTokensAsync_error:"refreshTokensAsync_error",refreshTokensAsync_silent_error:"refreshTokensAsync_silent_error",tryKeepExistingSessionAsync_begin:"tryKeepExistingSessionAsync_begin",tryKeepExistingSessionAsync_end:"tryKeepExistingSessionAsync_end",tryKeepExistingSessionAsync_error:"tryKeepExistingSessionAsync_error",silentLoginAsync_begin:"silentLoginAsync_begin",silentLoginAsync:"silentLoginAsync",silentLoginAsync_end:"silentLoginAsync_end",silentLoginAsync_error:"silentLoginAsync_error",syncTokensAsync_begin:"syncTokensAsync_begin",syncTokensAsync_lock_not_available:"syncTokensAsync_lock_not_available",syncTokensAsync_end:"syncTokensAsync_end",syncTokensAsync_error:"syncTokensAsync_error",tokensInvalidAndWaitingActionsToRefresh:"tokensInvalidAndWaitingActionsToRefresh"},P=(e,n=sessionStorage)=>{const t=y=>(n[`oidc.${e}`]=JSON.stringify({tokens:null,status:y}),Promise.resolve()),s=async()=>{if(!n[`oidc.${e}`])return n[`oidc.${e}`]=JSON.stringify({tokens:null,status:null}),{tokens:null,status:null};const y=JSON.parse(n[`oidc.${e}`]);return Promise.resolve({tokens:y.tokens,status:y.status})},o=y=>{n[`oidc.${e}`]=JSON.stringify({tokens:y})},r=async y=>{n[`oidc.session_state.${e}`]=y},i=async()=>n[`oidc.session_state.${e}`],l=y=>{n[`oidc.nonce.${e}`]=y.nonce},a=y=>{n[`oidc.jwk.${e}`]=JSON.stringify(y)},d=()=>JSON.parse(n[`oidc.jwk.${e}`]),f=async()=>({nonce:n[`oidc.nonce.${e}`]}),c=async y=>{n[`oidc.dpop_nonce.${e}`]=y},u=()=>n[`oidc.dpop_nonce.${e}`],h=()=>n[`oidc.${e}`]?JSON.stringify({tokens:JSON.parse(n[`oidc.${e}`]).tokens}):null;let g={};return{clearAsync:t,initAsync:s,setTokens:o,getTokens:h,setSessionStateAsync:r,getSessionStateAsync:i,setNonceAsync:l,getNonceAsync:f,setLoginParams:y=>{g[e]=y,n[`oidc.login.${e}`]=JSON.stringify(y)},getLoginParams:()=>{const y=n[`oidc.login.${e}`];return y?(g[e]||(g[e]=JSON.parse(y)),g[e]):(console.warn(`storage[oidc.login.${e}] is empty, you should have an bad OIDC or code configuration somewhere.`),null)},getStateAsync:async()=>n[`oidc.state.${e}`],setStateAsync:async y=>{n[`oidc.state.${e}`]=y},getCodeVerifierAsync:async()=>n[`oidc.code_verifier.${e}`],setCodeVerifierAsync:async y=>{n[`oidc.code_verifier.${e}`]=y},setDemonstratingProofOfPossessionNonce:c,getDemonstratingProofOfPossessionNonce:u,setDemonstratingProofOfPossessionJwkAsync:a,getDemonstratingProofOfPossessionJwkAsync:d}};var $=(e=>(e.AutomaticBeforeTokenExpiration="AutomaticBeforeTokensExpiration",e.AutomaticOnlyWhenFetchExecuted="AutomaticOnlyWhenFetchExecuted",e))($||{});const Ne=e=>decodeURIComponent(Array.prototype.map.call(atob(e),n=>"%"+("00"+n.charCodeAt(0).toString(16)).slice(-2)).join("")),xe=e=>JSON.parse(Ne(e.replaceAll(/-/g,"+").replaceAll(/_/g,"/"))),ue=e=>{try{return e&&We(e,".")===2?xe(e.split(".")[1]):null}catch(n){console.warn(n)}return null},We=(e,n)=>e.split(n).length-1,X={access_token_or_id_token_invalid:"access_token_or_id_token_invalid",access_token_invalid:"access_token_invalid",id_token_invalid:"id_token_invalid"};function Le(e,n,t){if(e.issuedAt){if(typeof e.issuedAt=="string")return parseInt(e.issuedAt,10)}else return n&&n.iat?n.iat:t&&t.iat?t.iat:new Date().getTime()/1e3;return e.issuedAt}const z=(e,n=null,t)=>{if(!e)return null;let s;const o=typeof e.expiresIn=="string"?parseInt(e.expiresIn,10):e.expiresIn;e.accessTokenPayload!==void 0?s=e.accessTokenPayload:s=ue(e.accessToken);let r;n!=null&&"idToken"in n&&!("idToken"in e)?r=n.idToken:r=e.idToken;const i=e.idTokenPayload?e.idTokenPayload:ue(r),l=i&&i.exp?i.exp:Number.MAX_VALUE,a=s&&s.exp?s.exp:e.issuedAt+o;e.issuedAt=Le(e,s,i);let d;e.expiresAt?d=e.expiresAt:t===X.access_token_invalid?d=a:t===X.id_token_invalid?d=l:d=l<a?l:a;const f={...e,idTokenPayload:i,accessTokenPayload:s,expiresAt:d,idToken:r};if(n!=null&&"refreshToken"in n&&!("refreshToken"in e)){const c=n.refreshToken;return{...f,refreshToken:c}}return f},ne=(e,n,t)=>{if(!e)return null;if(!e.issued_at){const o=new Date().getTime()/1e3;e.issued_at=o}const s={accessToken:e.access_token,expiresIn:e.expires_in,idToken:e.id_token,scope:e.scope,tokenType:e.token_type,issuedAt:e.issued_at};return"refresh_token"in e&&(s.refreshToken=e.refresh_token),e.accessTokenPayload!==void 0&&(s.accessTokenPayload=e.accessTokenPayload),e.idTokenPayload!==void 0&&(s.idTokenPayload=e.idTokenPayload),z(s,n,t)},V=(e,n)=>{const t=new Date().getTime()/1e3,s=n-t;return Math.round(s-e)},fe=e=>e?V(0,e.expiresAt)>0:!1,_e=async(e,n=200,t=50)=>{let s=t;if(!e.tokens)return null;for(;!fe(e.tokens)&&s>0;){if(e.configuration.token_automatic_renew_mode==$.AutomaticOnlyWhenFetchExecuted){await e.renewTokensAsync({});break}else await J({milliseconds:n});s=s-1}return{isTokensValid:fe(e.tokens),tokens:e.tokens,numberWaited:s-t}},de=(e,n,t)=>{if(e.idTokenPayload){const s=e.idTokenPayload;if(t.issuer!==s.iss)return{isValid:!1,reason:`Issuer does not match (oidcServerConfiguration issuer) ${t.issuer} !== (idTokenPayload issuer) ${s.iss}`};const o=new Date().getTime()/1e3;if(s.exp&&s.exp<o)return{isValid:!1,reason:`Token expired (idTokenPayload exp) ${s.exp} < (currentTimeUnixSecond) ${o}`};const r=60*60*24*7;if(s.iat&&s.iat+r<o)return{isValid:!1,reason:`Token is used from too long time (idTokenPayload iat + timeInSevenDays) ${s.iat+r} < (currentTimeUnixSecond) ${o}`};if(s.nonce&&s.nonce!==n)return{isValid:!1,reason:`Nonce does not match (idTokenPayload nonce) ${s.nonce} !== (nonce) ${n}`}}return{isValid:!0,reason:""}},M=function(){const e=function(){let a,d;const f=(function(){const u={},h={setTimeout:function(m,_,w){u[_]=setTimeout(function(){m.postMessage(_),u[_]=null},w)},setInterval:function(m,_,w){u[_]=setInterval(function(){m.postMessage(_)},w)},clearTimeout:function(m,_){clearTimeout(u[_]),u[_]=null},clearInterval:function(m,_){clearInterval(u[_]),u[_]=null}};function g(m,_){const w=_.data[0],A=_.data[1],v=_.data[2];h[w]&&h[w](m,A,v)}this.onmessage=function(m){g(self,m)},this.onconnect=function(m){const _=m.ports[0];_.onmessage=function(w){g(_,w)}}}).toString();try{const u=new Blob(["(",f,")()"],{type:"application/javascript"});d=URL.createObjectURL(u)}catch{return null}const c=typeof process>"u";try{if(SharedWorker)return a=new SharedWorker(d),a.port}catch{c&&console.warn("SharedWorker not available")}try{if(Worker)return a=new Worker(d),a}catch{c&&console.warn("Worker not available")}return null}();if(!e){const a=typeof window>"u"?global:window;return{setTimeout:setTimeout.bind(a),clearTimeout:clearTimeout.bind(a),setInterval:setInterval.bind(a),clearInterval:clearInterval.bind(a)}}const n=function(){let a=0;return function(){return a++,a}}(),t={},s={};e.onmessage=function(a){const d=a.data,f=t[d];if(f){f(),t[d]=null;return}const c=s[d];c&&c()};function o(a,d){const f=n();return e.postMessage(["setTimeout",f,d]),t[f]=a,f}function r(a){e.postMessage(["clearTimeout",a]),t[a]=null}function i(a,d){const f=n();return e.postMessage(["setInterval",f,d]),s[f]=a,f}function l(a){e.postMessage(["clearInterval",a]),s[a]=null}return{setTimeout:o,clearTimeout:r,setInterval:i,clearInterval:l}}(),he="7.20.1";let ye=null,Q;const J=({milliseconds:e})=>new Promise(n=>M.setTimeout(n,e)),ge=(e="/")=>{try{Q=new AbortController,fetch(`${e}OidcKeepAliveServiceWorker.json?minSleepSeconds=150`,{signal:Q.signal}).catch(s=>{console.log(s)}),J({milliseconds:150*1e3}).then(ge)}catch(n){console.log(n)}},De=()=>{Q&&Q.abort()},Re=(e="/")=>fetch(`${e}OidcKeepAliveServiceWorker.json`,{headers:{"oidc-vanilla":"true"}}).then(n=>n.statusText==="oidc-service-worker").catch(n=>{console.log(n)}),$e=e=>async(n,t)=>{t(),await n.update();const s=await n.unregister();console.log(`Service worker unregistering ${s}`),await J({milliseconds:2e3}),e.reload()},O=e=>n=>new Promise(function(t,s){const o=new MessageChannel;o.port1.onmessage=function(r){r.data&&r.data.error?s(r.data.error):t(r.data)},e.active.postMessage(n,[o.port2])}),I=async(e,n)=>{const t=e.service_worker_relative_url;if(typeof window>"u"||typeof navigator>"u"||!navigator.serviceWorker||!t||e.service_worker_activate()===!1)return null;let s=null;e.register?s=await e.service_worker_register(t):s=await navigator.serviceWorker.register(t);try{await navigator.serviceWorker.ready,navigator.serviceWorker.controller||await O(s)({type:"claim"})}catch{return null}const o=async k=>O(s)({type:"clear",data:{status:k},configurationName:n}),r=async(k,S,C)=>{const b=await O(s)({type:"init",data:{oidcServerConfiguration:k,where:S,oidcConfiguration:{token_renew_mode:C.token_renew_mode,service_worker_convert_all_requests_to_cors:C.service_worker_convert_all_requests_to_cors}},configurationName:n}),F=b.version;return F!==he&&(console.warn(`Service worker ${F} version mismatch with js client version ${he}, unregistering and reloading`),await C.service_worker_update_require_callback(s,De)),{tokens:ne(b.tokens,null,C.token_renew_mode),status:b.status}},i=(k="/")=>{ye==null&&(ye="not_null",ge(k))},l=k=>O(s)({type:"setSessionState",data:{sessionState:k},configurationName:n}),a=async()=>(await O(s)({type:"getSessionState",data:null,configurationName:n})).sessionState,d=k=>(sessionStorage[`oidc.nonce.${n}`]=k.nonce,O(s)({type:"setNonce",data:{nonce:k},configurationName:n})),f=async()=>{let S=(await O(s)({type:"getNonce",data:null,configurationName:n})).nonce;return S||(S=sessionStorage[`oidc.nonce.${n}`],console.warn("nonce not found in service worker, using sessionStorage")),{nonce:S}};let c={};return{clearAsync:o,initAsync:r,startKeepAliveServiceWorker:()=>i(e.service_worker_keep_alive_path),isServiceWorkerProxyActiveAsync:()=>Re(e.service_worker_keep_alive_path),setSessionStateAsync:l,getSessionStateAsync:a,setNonceAsync:d,getNonceAsync:f,setLoginParams:k=>{c[n]=k,localStorage[`oidc.login.${n}`]=JSON.stringify(k)},getLoginParams:()=>{const k=localStorage[`oidc.login.${n}`];return c[n]||(c[n]=JSON.parse(k)),c[n]},getStateAsync:async()=>{let S=(await O(s)({type:"getState",data:null,configurationName:n})).state;return S||(S=sessionStorage[`oidc.state.${n}`],console.warn("state not found in service worker, using sessionStorage")),S},setStateAsync:async k=>(sessionStorage[`oidc.state.${n}`]=k,O(s)({type:"setState",data:{state:k},configurationName:n})),getCodeVerifierAsync:async()=>{let S=(await O(s)({type:"getCodeVerifier",data:null,configurationName:n})).codeVerifier;return S||(S=sessionStorage[`oidc.code_verifier.${n}`],console.warn("codeVerifier not found in service worker, using sessionStorage")),S},setCodeVerifierAsync:async k=>(sessionStorage[`oidc.code_verifier.${n}`]=k,O(s)({type:"setCodeVerifier",data:{codeVerifier:k},configurationName:n})),setDemonstratingProofOfPossessionNonce:async k=>{await O(s)({type:"setDemonstratingProofOfPossessionNonce",data:{demonstratingProofOfPossessionNonce:k},configurationName:n})},getDemonstratingProofOfPossessionNonce:async()=>(await O(s)({type:"getDemonstratingProofOfPossessionNonce",data:null,configurationName:n})).demonstratingProofOfPossessionNonce,setDemonstratingProofOfPossessionJwkAsync:async k=>{const S=JSON.stringify(k);await O(s)({type:"setDemonstratingProofOfPossessionJwk",data:{demonstratingProofOfPossessionJwkJson:S},configurationName:n})},getDemonstratingProofOfPossessionJwkAsync:async()=>{const k=await O(s)({type:"getDemonstratingProofOfPossessionJwk",data:null,configurationName:n});return k.demonstratingProofOfPossessionJwkJson?JSON.parse(k.demonstratingProofOfPossessionJwkJson):null}}},K={},Ke=(e,n=window.sessionStorage,t)=>{if(!K[e]&&n){const o=n.getItem(e);o&&(K[e]=JSON.parse(o))}const s=1e3*t;return K[e]&&K[e].timestamp+s>Date.now()?K[e].result:null},Ue=(e,n,t=window.sessionStorage)=>{const s=Date.now();K[e]={result:n,timestamp:s},t&&t.setItem(e,JSON.stringify({result:n,timestamp:s}))};function ke(e){return new TextEncoder().encode(e)}function me(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function Fe(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(t,s){return String.fromCharCode(parseInt(s,16))})}const te=e=>{let n="";return e.forEach(function(t){n+=String.fromCharCode(t)}),me(n)};function pe(e){return me(Fe(e))}const Ve={importKeyAlgorithm:{name:"ECDSA",namedCurve:"P-256",hash:{name:"ES256"}},signAlgorithm:{name:"ECDSA",hash:{name:"SHA-256"}},generateKeyAlgorithm:{name:"ECDSA",namedCurve:"P-256"},digestAlgorithm:{name:"SHA-256"},jwtHeaderAlgorithm:"ES256"};var Me={sign:e=>async(n,t,s,o,r="dpop+jwt")=>{switch(n=Object.assign({},n),t.typ=r,t.alg=o.jwtHeaderAlgorithm,t.alg){case"ES256":t.jwk={kty:n.kty,crv:n.crv,x:n.x,y:n.y};break;case"RS256":t.jwk={kty:n.kty,n:n.n,e:n.e,kid:t.kid};break;default:throw new Error("Unknown or not implemented JWS algorithm")}const i={protected:pe(JSON.stringify(t)),payload:pe(JSON.stringify(s))},l=o.importKeyAlgorithm,a=!0,d=["sign"],f=await e.crypto.subtle.importKey("jwk",n,l,a,d),c=ke(`${i.protected}.${i.payload}`),u=o.signAlgorithm,h=await e.crypto.subtle.sign(u,f,c);return i.signature=te(new Uint8Array(h)),`${i.protected}.${i.payload}.${i.signature}`}};const Je={generate:e=>async n=>{const t=n,s=!0,o=["sign","verify"],r=await e.crypto.subtle.generateKey(t,s,o);return await e.crypto.subtle.exportKey("jwk",r.privateKey)},neuter:e=>{const n=Object.assign({},e);return delete n.d,n.key_ops=["verify"],n}};var Be={thumbprint:e=>async(n,t)=>{let s;switch(n.kty){case"EC":s='{"crv":"CRV","kty":"EC","x":"X","y":"Y"}'.replace("CRV",n.crv).replace("X",n.x).replace("Y",n.y);break;case"RSA":s='{"e":"E","kty":"RSA","n":"N"}'.replace("E",n.e).replace("N",n.n);break;default:throw new Error("Unknown or not implemented JWK type")}const o=await e.crypto.subtle.digest(t,ke(s));return te(new Uint8Array(o))}};const He=e=>async n=>await Je.generate(e)(n),we=e=>n=>async(t,s="POST",o,r={})=>{const i={jti:btoa(je()),htm:s,htu:o,iat:Math.round(Date.now()/1e3),...r},l=await Be.thumbprint(e)(t,n.digestAlgorithm);return await Me.sign(e)(t,{kid:l},i,n)},je=()=>{const e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",n="0123456789abcdef";let t=0,s="";for(let o=0;o<36;o++)e[o]!=="-"&&e[o]!=="4"&&(t=Math.random()*16|0),e[o]==="x"?s+=n[t]:e[o]==="y"?(t&=3,t|=8,s+=n[t]):s+=e[o];return s},Ae=()=>{const e=typeof window<"u"&&!!window.crypto,n=e&&!!window.crypto.subtle;return{hasCrypto:e,hasSubtleCrypto:n}},se="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",qe=e=>{const n=[];for(let t=0;t<e.byteLength;t+=1){const s=e[t]%se.length;n.push(se[s])}return n.join("")},oe=e=>{const n=new Uint8Array(e),{hasCrypto:t}=Ae();if(t)window.crypto.getRandomValues(n);else for(let s=0;s<e;s+=1)n[s]=Math.random()*se.length|0;return qe(n)};function Ge(e){const n=new ArrayBuffer(e.length),t=new Uint8Array(n);for(let s=0;s<e.length;s++)t[s]=e.charCodeAt(s);return t}function Se(e){return new Promise((n,t)=>{crypto.subtle.digest("SHA-256",Ge(e)).then(s=>n(te(new Uint8Array(s))),s=>t(s))})}const Ye=e=>{if(e.length<43||e.length>128)return Promise.reject(new Error("Invalid code length."));const{hasSubtleCrypto:n}=Ae();return n?Se(e):Promise.reject(new Error("window.crypto.subtle is unavailable."))},Xe=60*60,ze=e=>async(n,t=Xe,s=window.sessionStorage,o=1e4)=>{const r=`${n}/.well-known/openid-configuration`,i=`oidc.server:${n}`,l=Ke(i,s,t);if(l)return new ce(l);const a=await B(e)(r,{},o);if(a.status!==200)return null;const d=await a.json();return Ue(i,d,s),new ce(d)},B=e=>async(n,t={},s=1e4,o=0)=>{let r;try{const i=new AbortController;setTimeout(()=>i.abort(),s),r=await e(n,{...t,signal:i.signal})}catch(i){if(i.name==="AbortError"||i.message==="Network request failed"){if(o<=1)return await B(e)(n,t,s,o+1);throw i}else throw console.error(i.message),i}return r},re={refresh_token:"refresh_token",access_token:"access_token"},ve=e=>async(n,t,s=re.refresh_token,o,r={},i=1e4)=>{const l={token:t,token_type_hint:s,client_id:o};for(const[c,u]of Object.entries(r))l[c]===void 0&&(l[c]=u);const a=[];for(const c in l){const u=encodeURIComponent(c),h=encodeURIComponent(l[c]);a.push(`${u}=${h}`)}const d=a.join("&");return(await B(e)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},body:d},i)).status!==200?{success:!1}:{success:!0}},Qe=e=>async(n,t,s,o,r={},i,l=1e4)=>{for(const[h,g]of Object.entries(s))t[h]===void 0&&(t[h]=g);const a=[];for(const h in t){const g=encodeURIComponent(h),m=encodeURIComponent(t[h]);a.push(`${g}=${m}`)}const d=a.join("&"),f=await B(e)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8",...r},body:d},l);if(f.status!==200)return{success:!1,status:f.status,demonstratingProofOfPossessionNonce:null};const c=await f.json();let u=null;return f.headers.has(Z)&&(u=f.headers.get(Z)),{success:!0,status:f.status,data:ne(c,o,i),demonstratingProofOfPossessionNonce:u}},Ze=(e,n)=>async(t,s)=>{s=s?{...s}:{};const o=oe(128),r=await Ye(o);await e.setCodeVerifierAsync(o),await e.setStateAsync(s.state),s.code_challenge=r,s.code_challenge_method="S256";let i="";if(s)for(const[l,a]of Object.entries(s))i===""?i+="?":i+="&",i+=`${l}=${encodeURIComponent(a)}`;n.open(`${t}${i}`)},Z="DPoP-Nonce",en=e=>async(n,t,s,o,r=1e4)=>{t=t?{...t}:{},t.code_verifier=await e.getCodeVerifierAsync();const i=[];for(const c in t){const u=encodeURIComponent(c),h=encodeURIComponent(t[c]);i.push(`${u}=${h}`)}const l=i.join("&"),a=await B(fetch)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8",...s},body:l},r);if(await Promise.all([e.setCodeVerifierAsync(null),e.setStateAsync(null)]),a.status!==200)return{success:!1,status:a.status};let d=null;a.headers.has(Z)&&(d=a.headers.get(Z));const f=await a.json();return{success:!0,data:{state:t.state,tokens:ne(f,null,o),demonstratingProofOfPossessionNonce:d}}};async function Te(e,n,t){const s=l=>{e.tokens=l},{tokens:o,status:r}=await ee(e)(0,n,t,s);return await I(e.configuration,e.configurationName)||await P(e.configurationName,e.configuration.storage).setTokens(e.tokens),e.tokens?o:(await e.destroyAsync(r),null)}const nn=async(e,n)=>{const t=await I(n,e.configurationName);if(t){const s=await e.initAsync(n.authority,n.authority_configuration),{tokens:o}=await t.initAsync(s,"tryKeepExistingSessionAsync",n);return o}else{const s=P(e.configurationName,n.storage??sessionStorage);let{tokens:o}=await s.initAsync();return o=z(o,e.tokens,n.token_renew_mode),o}};async function be(e,n=!1,t=null){const s=e.configuration,o=`${s.client_id}_${e.configurationName}_${s.authority}`;let r;const i=await I(e.configuration,e.configurationName);return(s==null?void 0:s.storage)===(window==null?void 0:window.sessionStorage)&&!i?r=await Te(e,n,t):r=await navigator.locks.request(o,{ifAvailable:!0},async l=>l?await Te(e,n,t):(e.publishEvent(x.eventNames.syncTokensAsync_lock_not_available,{lock:"lock not available"}),await nn(e,s))),r?(e.timeoutId&&(e.timeoutId=H(e,e.tokens.expiresAt,t)),e.tokens):null}const H=(e,n,t=null)=>{const s=e.configuration.refresh_time_before_tokens_expiration_in_second;return M.setTimeout(async()=>{const r={timeLeft:V(s,n)};e.publishEvent(x.eventNames.token_timer,r),await be(e,!1,t)},1e3)},W={FORCE_REFRESH:"FORCE_REFRESH",SESSION_LOST:"SESSION_LOST",NOT_CONNECTED:"NOT_CONNECTED",TOKENS_VALID:"TOKENS_VALID",TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID:"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID",LOGOUT_FROM_ANOTHER_TAB:"LOGOUT_FROM_ANOTHER_TAB",REQUIRE_SYNC_TOKENS:"REQUIRE_SYNC_TOKENS"},tn=e=>async(n,t,s,o=!1)=>{const r={nonce:null};if(!s)return{tokens:null,status:"NOT_CONNECTED",nonce:r};let i=r;const l=await e.initAsync(n.authority,n.authority_configuration),a=await I(n,t);if(a){const{status:c,tokens:u}=await a.initAsync(l,"syncTokensAsync",n);if(c==="LOGGED_OUT")return{tokens:null,status:"LOGOUT_FROM_ANOTHER_TAB",nonce:r};if(c==="SESSIONS_LOST")return{tokens:null,status:"SESSIONS_LOST",nonce:r};if(!c||!u)return{tokens:null,status:"REQUIRE_SYNC_TOKENS",nonce:r};if(u.issuedAt!==s.issuedAt){const g=V(n.refresh_time_before_tokens_expiration_in_second,u.expiresAt)>0?"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID":"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID",m=await a.getNonceAsync();return{tokens:u,status:g,nonce:m}}i=await a.getNonceAsync()}else{const c=P(t,n.storage??sessionStorage);let{tokens:u,status:h}=await c.initAsync();if(u&&(u=z(u,e.tokens,n.token_renew_mode)),u){if(h==="SESSIONS_LOST")return{tokens:null,status:"SESSIONS_LOST",nonce:r};if(u.issuedAt!==s.issuedAt){const m=V(n.refresh_time_before_tokens_expiration_in_second,u.expiresAt)>0?"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID":"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID",_=await c.getNonceAsync();return{tokens:u,status:m,nonce:_}}}else return{tokens:null,status:"LOGOUT_FROM_ANOTHER_TAB",nonce:r};i=await c.getNonceAsync()}const f=V(n.refresh_time_before_tokens_expiration_in_second,s.expiresAt)>0?"TOKENS_VALID":"TOKENS_INVALID";return o?{tokens:s,status:"FORCE_REFRESH",nonce:i}:{tokens:s,status:f,nonce:i}},ee=e=>async(n=0,t=!1,s=null,o)=>{for(;!navigator.onLine&&document.hidden;)await J({milliseconds:1e3}),e.publishEvent(p.refreshTokensAsync,{message:"wait because navigator is offline and hidden"});let r=6;for(;!navigator.onLine&&r>0;)await J({milliseconds:1e3}),r--,e.publishEvent(p.refreshTokensAsync,{message:`wait because navigator is offline try ${r}`});const i=document.hidden,l=n+1;s||(s={});const a=e.configuration,d=(c,u=null,h=null)=>ie(e.configurationName,e.configuration,e.publishEvent.bind(e))(c,u,h),f=async()=>{try{let c;const u=await I(a,e.configurationName);u?c=u.getLoginParams():c=P(e.configurationName,a.storage).getLoginParams();const h=await d({...c.extras,...s,prompt:"none"});return h?h.error?(o(null),e.publishEvent(p.refreshTokensAsync_error,{message:"refresh token silent"}),{tokens:null,status:"SESSION_LOST"}):(o(h.tokens),e.publishEvent(x.eventNames.token_renewed,{}),{tokens:h.tokens,status:"LOGGED"}):(o(null),e.publishEvent(p.refreshTokensAsync_error,{message:"refresh token silent not active"}),{tokens:null,status:"SESSION_LOST"})}catch(c){return console.error(c),e.publishEvent(p.refreshTokensAsync_silent_error,{message:"exceptionSilent",exception:c.message}),await ee(e)(l,t,s,o)}};if(n>4)return i?{tokens:e.tokens,status:"GIVE_UP"}:(o(null),e.publishEvent(p.refreshTokensAsync_error,{message:"refresh token"}),{tokens:null,status:"SESSION_LOST"});try{const{status:c,tokens:u,nonce:h}=await tn(e)(a,e.configurationName,e.tokens,t);switch(c){case W.SESSION_LOST:return o(null),e.publishEvent(p.refreshTokensAsync_error,{message:"refresh token session lost"}),{tokens:null,status:"SESSION_LOST"};case W.NOT_CONNECTED:return o(null),{tokens:null,status:null};case W.TOKENS_VALID:return o(u),{tokens:u,status:"LOGGED_IN"};case W.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID:return o(u),e.publishEvent(x.eventNames.token_renewed,{reason:"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID"}),{tokens:u,status:"LOGGED_IN"};case W.LOGOUT_FROM_ANOTHER_TAB:return o(null),e.publishEvent(p.logout_from_another_tab,{status:"session syncTokensAsync"}),{tokens:null,status:"LOGGED_OUT"};case W.REQUIRE_SYNC_TOKENS:return a.token_automatic_renew_mode==$.AutomaticOnlyWhenFetchExecuted&&W.FORCE_REFRESH!==c?(e.publishEvent(p.tokensInvalidAndWaitingActionsToRefresh,{}),{tokens:e.tokens,status:"GIVE_UP"}):(e.publishEvent(p.refreshTokensAsync_begin,{tryNumber:n}),await f());default:{if(a.token_automatic_renew_mode==$.AutomaticOnlyWhenFetchExecuted&&W.FORCE_REFRESH!==c)return e.publishEvent(p.tokensInvalidAndWaitingActionsToRefresh,{}),{tokens:e.tokens,status:"GIVE_UP"};if(e.publishEvent(p.refreshTokensAsync_begin,{refreshToken:u.refreshToken,status:c,tryNumber:n}),!u.refreshToken)return await f();const g=a.client_id,m=a.redirect_uri,_=a.authority,A={...a.token_request_extras?a.token_request_extras:{}};for(const[T,y]of Object.entries(s))T.endsWith(":token_request")&&(A[T.replace(":token_request","")]=y);return await(async()=>{const T={client_id:g,redirect_uri:m,grant_type:"refresh_token",refresh_token:u.refreshToken},y=await e.initAsync(_,a.authority_configuration),k=document.hidden?1e4:3e4*10,S=y.tokenEndpoint,C={};a.demonstrating_proof_of_possession&&(C.DPoP=await e.generateDemonstrationOfProofOfPossessionAsync(u.accessToken,S,"POST"));const b=await Qe(e.getFetch())(S,T,A,u,C,a.token_renew_mode,k);if(b.success){const{isValid:F,reason:E}=de(b.data,h.nonce,y);if(!F)return o(null),e.publishEvent(p.refreshTokensAsync_error,{message:`refresh token return not valid tokens, reason: ${E}`}),{tokens:null,status:"SESSION_LOST"};if(o(b.data),b.demonstratingProofOfPossessionNonce){const D=await I(a,e.configurationName);D?await D.setDemonstratingProofOfPossessionNonce(b.demonstratingProofOfPossessionNonce):await P(e.configurationName,a.storage).setDemonstratingProofOfPossessionNonce(b.demonstratingProofOfPossessionNonce)}return e.publishEvent(p.refreshTokensAsync_end,{success:b.success}),e.publishEvent(x.eventNames.token_renewed,{reason:"REFRESH_TOKEN"}),{tokens:b.data,status:"LOGGED_IN"}}else return e.publishEvent(p.refreshTokensAsync_silent_error,{message:"bad request",tokenResponse:b}),b.status>=400&&b.status<500?(o(null),e.publishEvent(p.refreshTokensAsync_error,{message:`session lost: ${b.status}`}),{tokens:null,status:"SESSION_LOST"}):await ee(e)(l,t,s,o)})()}}}catch(c){return console.error(c),e.publishEvent(p.refreshTokensAsync_silent_error,{message:"exception",exception:c.message}),ee(e)(l,t,s,o)}},ie=(e,n,t)=>(s=null,o=null,r=null)=>{if(!n.silent_redirect_uri||!n.silent_login_uri)return Promise.resolve(null);try{t(p.silentLoginAsync_begin,{});let i="";if(o&&(s==null&&(s={}),s.state=o),r&&(s==null&&(s={}),s.scope=r),s!=null)for(const[c,u]of Object.entries(s))i===""?i=`?${encodeURIComponent(c)}=${encodeURIComponent(u)}`:i+=`&${encodeURIComponent(c)}=${encodeURIComponent(u)}`;const l=n.silent_login_uri+i,a=l.indexOf("/",l.indexOf("//")+2),d=l.substring(0,a),f=document.createElement("iframe");return f.width="0px",f.height="0px",f.id=`${e}_oidc_iframe`,f.setAttribute("src",l),document.body.appendChild(f),new Promise((c,u)=>{let h=!1;const g=()=>{window.removeEventListener("message",m),f.remove(),h=!0},m=_=>{if(_.origin===d&&_.source===f.contentWindow){const w=`${e}_oidc_tokens:`,A=`${e}_oidc_error:`,v=`${e}_oidc_exception:`,T=_.data;if(T&&typeof T=="string"&&!h){if(T.startsWith(w)){const y=JSON.parse(_.data.replace(w,""));t(p.silentLoginAsync_end,{}),c(y),g()}else if(T.startsWith(A)){const y=JSON.parse(_.data.replace(A,""));t(p.silentLoginAsync_error,y),c({error:"oidc_"+y.error,tokens:null,sessionState:null}),g()}else if(T.startsWith(v)){const y=JSON.parse(_.data.replace(v,""));t(p.silentLoginAsync_error,y),u(new Error(y.error)),g()}}}};try{window.addEventListener("message",m);const _=n.silent_login_timeout;setTimeout(()=>{h||(g(),t(p.silentLoginAsync_error,{reason:"timeout"}),u(new Error("timeout")))},_)}catch(_){g(),t(p.silentLoginAsync_error,_),u(_)}})}catch(i){throw t(p.silentLoginAsync_error,i),i}},sn=(e,n,t,s,o)=>(r=null,i=void 0)=>{r={...r};const l=(d,f,c)=>ie(n,t,s.bind(o))(d,f,c);return(async()=>{o.timeoutId&&M.clearTimeout(o.timeoutId);let d;r&&"state"in r&&(d=r.state,delete r.state);try{const f=t.extras?{...t.extras,...r}:r,c=await l({...f,prompt:"none"},d,i);if(c)return o.tokens=c.tokens,s(p.token_aquired,{}),o.timeoutId=H(o,o.tokens.expiresAt,r),{}}catch(f){return f}})()},on=(e,n,t)=>(s,o,r,i=!1)=>{const l=(a,d=void 0,f=void 0)=>ie(e.configurationName,t,e.publishEvent.bind(e))(a,d,f);return new Promise((a,d)=>{if(t.silent_login_uri&&t.silent_redirect_uri&&t.monitor_session&&s&&r&&!i){const f=()=>{e.checkSessionIFrame.stop();const c=e.tokens;if(c===null)return;const u=c.idToken,h=c.idTokenPayload;return l({prompt:"none",id_token_hint:u,scope:t.scope||"openid"}).then(g=>{if(g.error)throw new Error(g.error);const m=g.tokens.idTokenPayload;if(h.sub===m.sub){const _=g.sessionState;e.checkSessionIFrame.start(g.sessionState),h.sid===m.sid?console.debug("SessionMonitor._callback: Same sub still logged in at OP, restarting check session iframe; session_state:",_):console.debug("SessionMonitor._callback: Same sub still logged in at OP, session state has changed, restarting check session iframe; session_state:",_)}else console.debug("SessionMonitor._callback: Different subject signed into OP:",m.sub)}).catch(async g=>{console.warn("SessionMonitor._callback: Silent login failed, logging out other tabs:",g);for(const[m,_]of Object.entries(n))await _.logoutOtherTabAsync(t.client_id,h.sub)})};e.checkSessionIFrame=new Ce(f,o,s),e.checkSessionIFrame.load().then(()=>{e.checkSessionIFrame.start(r),a(e.checkSessionIFrame)}).catch(c=>{d(c)})}else a(null)})},Ee=e=>{const n=e.match(/^([a-z][\w-]+\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);if(!n)throw new Error("Invalid URL");let t=n[6],s=n[7];if(s){const o=s.split("?");o.length===2&&(s=o[0],t=o[1])}return t.startsWith("?")&&(t=t.slice(1)),n&&{href:e,protocol:n[1],host:n[2],hostname:n[3],port:n[4],path:n[5],search:t,hash:s}},rn=e=>{const n=Ee(e);let{path:t}=n;t.endsWith("/")&&(t=t.slice(0,-1));let{hash:s}=n;return s==="#_=_"&&(s=""),s&&(t+=s),t},j=e=>{const n=Ee(e),{search:t}=n;return an(t)},an=e=>{const n={};let t,s,o;const r=e.split("&");for(s=0,o=r.length;s<o;s++)t=r[s].split("="),n[decodeURIComponent(t[0])]=decodeURIComponent(t[1]);return n},cn=(e,n,t,s,o)=>(r=void 0,i=null,l=!1,a=void 0)=>{const d=i;return i={...i},(async()=>{const c=r||o.getPath();if("state"in i||(i.state=oe(16)),t(p.loginAsync_begin,{}),i)for(const u of Object.keys(i))u.endsWith(":token_request")&&delete i[u];try{const u=l?n.silent_redirect_uri:n.redirect_uri;a||(a=n.scope);const h=n.extras?{...n.extras,...i}:i;h.nonce||(h.nonce=oe(12));const g={nonce:h.nonce},m=await I(n,e),_=await s(n.authority,n.authority_configuration);let w;if(m)m.setLoginParams({callbackPath:c,extras:d}),await m.initAsync(_,"loginAsync",n),await m.setNonceAsync(g),m.startKeepAliveServiceWorker(),w=m;else{const v=P(e,n.storage??sessionStorage);v.setLoginParams({callbackPath:c,extras:d}),await v.setNonceAsync(g),w=v}const A={client_id:n.client_id,redirect_uri:u,scope:a,response_type:"code",...h};await Ze(w,o)(_.authorizationEndpoint,A)}catch(u){throw t(p.loginAsync_error,u),u}})()},ln=e=>async(n=!1)=>{try{e.publishEvent(p.loginCallbackAsync_begin,{});const t=e.configuration,s=t.client_id,o=n?t.silent_redirect_uri:t.redirect_uri,r=t.authority,i=t.token_request_timeout,l=await e.initAsync(r,t.authority_configuration),a=e.location.getCurrentHref(),f=j(a).session_state,c=await I(t,e.configurationName);let u,h,g,m;if(c)await c.initAsync(l,"loginCallbackAsync",t),await c.setSessionStateAsync(f),h=await c.getNonceAsync(),g=c.getLoginParams(),m=await c.getStateAsync(),c.startKeepAliveServiceWorker(),u=c;else{const E=P(e.configurationName,t.storage??sessionStorage);await E.setSessionStateAsync(f),h=await E.getNonceAsync(),g=E.getLoginParams(),m=await E.getStateAsync(),u=E}const _=j(a);if(_.error||_.error_description)throw new Error(`Error from OIDC server: ${_.error} - ${_.error_description}`);if(_.iss&&_.iss!==l.issuer)throw console.error(),new Error(`Issuer not valid (expected: ${l.issuer}, received: ${_.iss})`);if(_.state&&_.state!==m)throw new Error(`State not valid (expected: ${m}, received: ${_.state})`);const w={code:_.code,grant_type:"authorization_code",client_id:t.client_id,redirect_uri:o},A={};if(t.token_request_extras)for(const[E,D]of Object.entries(t.token_request_extras))A[E]=D;if(g&&g.extras)for(const[E,D]of Object.entries(g.extras))E.endsWith(":token_request")&&(A[E.replace(":token_request","")]=D);const v=l.tokenEndpoint,T={};if(t.demonstrating_proof_of_possession)if(c)T.DPoP=`DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${e.configurationName}`;else{const E=await He(window)(t.demonstrating_proof_of_possession_configuration.generateKeyAlgorithm);await P(e.configurationName,t.storage).setDemonstratingProofOfPossessionJwkAsync(E),T.DPoP=await we(window)(t.demonstrating_proof_of_possession_configuration)(E,"POST",v)}const y=await en(u)(v,{...w,...A},T,e.configuration.token_renew_mode,i);if(!y.success)throw new Error("Token request failed");let k;const S=y.data.tokens,C=y.data.demonstratingProofOfPossessionNonce;if(y.data.state!==A.state)throw new Error("state is not valid");const{isValid:b,reason:F}=de(S,h.nonce,l);if(!b)throw new Error(`Tokens are not OpenID valid, reason: ${F}`);if(c){if(S.refreshToken&&!S.refreshToken.includes("SECURED_BY_OIDC_SERVICE_WORKER"))throw new Error("Refresh token should be hidden by service worker");if(C&&S.accessToken&&S.accessToken.includes("SECURED_BY_OIDC_SERVICE_WORKER"))throw new Error("Demonstration of proof of possession require Access token not hidden by service worker")}if(c)await c.initAsync(l,"syncTokensAsync",t),k=c.getLoginParams(),C&&await c.setDemonstratingProofOfPossessionNonce(C);else{const E=P(e.configurationName,t.storage);k=E.getLoginParams(),C&&await E.setDemonstratingProofOfPossessionNonce(C)}return await e.startCheckSessionAsync(l.checkSessionIframe,s,f,n),e.publishEvent(p.loginCallbackAsync_end,{}),{tokens:S,state:"request.state",callbackPath:k.callbackPath}}catch(t){throw console.error(t),e.publishEvent(p.loginCallbackAsync_error,t),t}},Oe={access_token:"access_token",refresh_token:"refresh_token"},ae=(e,n)=>{const t={};if(e){for(const[s,o]of Object.entries(e))if(s.endsWith(n)){const r=s.replace(n,"");t[r]=o}return t}return t},un=e=>{const n={};if(e){for(const[t,s]of Object.entries(e))t.includes(":")||(n[t]=s);return n}return n},fn=e=>async n=>{M.clearTimeout(e.timeoutId),e.timeoutId=null,e.checkSessionIFrame&&e.checkSessionIFrame.stop();const t=await I(e.configuration,e.configurationName);t?await t.clearAsync(n):await P(e.configurationName,e.configuration.storage).clearAsync(n),e.tokens=null,e.userInfo=null},_n=(e,n,t,s,o)=>async(r=void 0,i=null)=>{const l=e.configuration,a=await e.initAsync(l.authority,l.authority_configuration);r&&typeof r!="string"&&(r=void 0,s.warn("callbackPathOrUrl path is not a string"));const d=r??o.getPath();let f=!1;r&&(f=r.includes("https://")||r.includes("http://"));const c=f?r:o.getOrigin()+d,u=e.tokens?e.tokens.idToken:"";try{const w=a.revocationEndpoint;if(w){const A=[],v=e.tokens?e.tokens.accessToken:null;if(v&&l.logout_tokens_to_invalidate.includes(Oe.access_token)){const y=ae(i,":revoke_access_token"),k=ve(t)(w,v,re.access_token,l.client_id,y);A.push(k)}const T=e.tokens?e.tokens.refreshToken:null;if(T&&l.logout_tokens_to_invalidate.includes(Oe.refresh_token)){const y=ae(i,":revoke_refresh_token"),k=ve(t)(w,T,re.refresh_token,l.client_id,y);A.push(k)}A.length>0&&await Promise.all(A)}}catch(w){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(w)}const h=e.tokens&&e.tokens.idTokenPayload?e.tokens.idTokenPayload.sub:null;await e.destroyAsync("LOGGED_OUT");for(const[w,A]of Object.entries(n))A!==e?await e.logoutSameTabAsync(e.configuration.client_id,h):e.publishEvent(p.logout_from_same_tab,{});const g=ae(i,":oidc");if(g&&g.no_reload==="true")return;const _=un(i);if(a.endSessionEndpoint){"id_token_hint"in _||(_.id_token_hint=u),!("post_logout_redirect_uri"in _)&&r!==null&&(_.post_logout_redirect_uri=c);let w="";for(const[A,v]of Object.entries(_))v!=null&&(w===""?w+="?":w+="&",w+=`${A}=${encodeURIComponent(v)}`);o.open(`${a.endSessionEndpoint}${w}`)}else o.reload()},Pe=(e,n)=>async(...t)=>{var u;const[s,o,...r]=t,i=o?{...o}:{method:"GET"};let l=new Headers;i.headers&&(l=i.headers instanceof Headers?i.headers:new Headers(i.headers));const a=n,d=await _e(a),f=(u=d==null?void 0:d.tokens)==null?void 0:u.accessToken;if(l.has("Accept")||l.set("Accept","application/json"),f){if(a.configuration.demonstrating_proof_of_possession){const h=await a.generateDemonstrationOfProofOfPossessionAsync(f,s.toString(),i.method);l.set("Authorization",`PoP ${f}`),l.set("DPoP",h)}else l.set("Authorization",`Bearer ${f}`);i.credentials||(i.credentials="same-origin")}const c={...i,headers:l};return await e(s,c,...r)},dn=e=>async(n=!1)=>{if(e.userInfo!=null&&!n)return e.userInfo;const t=e.configuration,o=(await e.initAsync(t.authority,t.authority_configuration)).userInfoEndpoint,i=await(async()=>{const a=await Pe(fetch,e)(o);return a.status!==200?null:a.json()})();return e.userInfo=i,i};class q{open(n){window.location.href=n}reload(){window.location.reload()}getCurrentHref(){return window.location.href}getPath(){const n=window.location;return n.pathname+(n.search||"")+(n.hash||"")}getOrigin(){return window.origin}}const hn=e=>!!(e.os==="iOS"&&e.osVersion.startsWith("12")||e.os==="Mac OS X"&&e.osVersion.startsWith("10_15_6")),yn=e=>{const n=e.appVersion,t=e.userAgent,s="-";let o=s;const r=[{s:"Windows 10",r:/(Windows 10.0|Windows NT 10.0)/},{s:"Windows 8.1",r:/(Windows 8.1|Windows NT 6.3)/},{s:"Windows 8",r:/(Windows 8|Windows NT 6.2)/},{s:"Windows 7",r:/(Windows 7|Windows NT 6.1)/},{s:"Windows Vista",r:/Windows NT 6.0/},{s:"Windows Server 2003",r:/Windows NT 5.2/},{s:"Windows XP",r:/(Windows NT 5.1|Windows XP)/},{s:"Windows 2000",r:/(Windows NT 5.0|Windows 2000)/},{s:"Windows ME",r:/(Win 9x 4.90|Windows ME)/},{s:"Windows 98",r:/(Windows 98|Win98)/},{s:"Windows 95",r:/(Windows 95|Win95|Windows_95)/},{s:"Windows NT 4.0",r:/(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/},{s:"Windows CE",r:/Windows CE/},{s:"Windows 3.11",r:/Win16/},{s:"Android",r:/Android/},{s:"Open BSD",r:/OpenBSD/},{s:"Sun OS",r:/SunOS/},{s:"Chrome OS",r:/CrOS/},{s:"Linux",r:/(Linux|X11(?!.*CrOS))/},{s:"iOS",r:/(iPhone|iPad|iPod)/},{s:"Mac OS X",r:/Mac OS X/},{s:"Mac OS",r:/(Mac OS|MacPPC|MacIntel|Mac_PowerPC|Macintosh)/},{s:"QNX",r:/QNX/},{s:"UNIX",r:/UNIX/},{s:"BeOS",r:/BeOS/},{s:"OS/2",r:/OS\/2/},{s:"Search Bot",r:/(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/}];for(const l in r){const a=r[l];if(a.r.test(t)){o=a.s;break}}let i=s;switch(/Windows/.test(o)&&(i=/Windows (.*)/.exec(o)[1],o="Windows"),o){case"Mac OS":case"Mac OS X":case"Android":i=/(?:Android|Mac OS|Mac OS X|MacPPC|MacIntel|Mac_PowerPC|Macintosh) ([._\d]+)/.exec(t)[1];break;case"iOS":{const l=/OS (\d+)_(\d+)_?(\d+)?/.exec(n);l!=null&&l.length>2&&(i=l[1]+"."+l[2]+"."+(parseInt(l[3])|0));break}}return{os:o,osVersion:i}};function gn(){const e=navigator.userAgent;let n,t=e.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];if(/trident/i.test(t[1]))return n=/\brv[ :]+(\d+)/g.exec(e)||[],{name:"ie",version:n[1]||""};if(t[1]==="Chrome"&&(n=e.match(/\bOPR|Edge\/(\d+)/),n!=null)){let s=n[1];if(!s){const o=e.split(n[0]+"/");o.length>1&&(s=o[1])}return{name:"opera",version:s}}return t=t[2]?[t[1],t[2]]:[navigator.appName,navigator.appVersion,"-?"],(n=e.match(/version\/(\d+)/i))!=null&&t.splice(1,1,n[1]),{name:t[0].toLowerCase(),version:t[1]}}const kn=()=>{const{name:e,version:n}=gn();if(e==="chrome"&&parseInt(n)<=70||e==="opera"&&(!n||parseInt(n.split(".")[0])<80)||e==="ie")return!1;const t=yn(navigator);return!hn(t)},mn=async e=>{let n;if(e.tokens!=null)return!1;e.publishEvent(p.tryKeepExistingSessionAsync_begin,{});try{const t=e.configuration,s=await e.initAsync(t.authority,t.authority_configuration);if(n=await I(t,e.configurationName),n){const{tokens:o}=await n.initAsync(s,"tryKeepExistingSessionAsync",t);if(o){n.startKeepAliveServiceWorker(),e.tokens=o;const r=n.getLoginParams(e.configurationName);e.timeoutId=H(e,e.tokens.expiresAt,r.extras);const i=await n.getSessionStateAsync();return await e.startCheckSessionAsync(s.check_session_iframe,t.client_id,i),e.publishEvent(p.tryKeepExistingSessionAsync_end,{success:!0,message:"tokens inside ServiceWorker are valid"}),!0}e.publishEvent(p.tryKeepExistingSessionAsync_end,{success:!1,message:"no exiting session found"})}else{t.service_worker_relative_url&&e.publishEvent(p.service_worker_not_supported_by_browser,{message:"service worker is not supported by this browser"});const o=P(e.configurationName,t.storage??sessionStorage),{tokens:r}=await o.initAsync();if(r){e.tokens=z(r,null,t.token_renew_mode);const i=o.getLoginParams();e.timeoutId=H(e,e.tokens.expiresAt,i.extras);const l=await o.getSessionStateAsync();return await e.startCheckSessionAsync(s.check_session_iframe,t.client_id,l),e.publishEvent(p.tryKeepExistingSessionAsync_end,{success:!0,message:"tokens inside storage are valid"}),!0}}return e.publishEvent(p.tryKeepExistingSessionAsync_end,{success:!1,message:n?"service worker sessions not retrieved":"session storage sessions not retrieved"}),!1}catch(t){return console.error(t),n&&await n.clearAsync(),e.publishEvent(p.tryKeepExistingSessionAsync_error,"tokens inside ServiceWorker are invalid"),!1}},Ie=()=>fetch;class ce{constructor(n){this.authorizationEndpoint=n.authorization_endpoint,this.tokenEndpoint=n.token_endpoint,this.revocationEndpoint=n.revocation_endpoint,this.userInfoEndpoint=n.userinfo_endpoint,this.checkSessionIframe=n.check_session_iframe,this.issuer=n.issuer,this.endSessionEndpoint=n.end_session_endpoint}}const L={},pn=(e,n=new q)=>(t,s="default")=>(L[s]||(L[s]=new x(t,s,e,n)),L[s]),wn=async e=>{const{parsedTokens:n,callbackPath:t}=await e.loginCallbackAsync();return e.timeoutId=H(e,n.expiresAt),{callbackPath:t}},An=e=>Math.floor(Math.random()*e),G=class G{constructor(n,t="default",s,o=new q){this.initPromise=null,this.tryKeepExistingSessionPromise=null,this.loginPromise=null,this.loginCallbackPromise=null,this.loginCallbackWithAutoTokensRenewPromise=null,this.userInfoPromise=null,this.renewTokensPromise=null,this.logoutPromise=null;let r=n.silent_login_uri;n.silent_redirect_uri&&!n.silent_login_uri&&(r=`${n.silent_redirect_uri.replace("-callback","").replace("callback","")}-login`);let i=n.refresh_time_before_tokens_expiration_in_second??120;i>60&&(i=i-Math.floor(Math.random()*40)),this.location=o??new q;const l=n.service_worker_update_require_callback??$e(this.location);this.configuration={...n,silent_login_uri:r,token_automatic_renew_mode:n.token_automatic_renew_mode??$.AutomaticBeforeTokenExpiration,monitor_session:n.monitor_session??!1,refresh_time_before_tokens_expiration_in_second:i,silent_login_timeout:n.silent_login_timeout??12e3,token_renew_mode:n.token_renew_mode??X.access_token_or_id_token_invalid,demonstrating_proof_of_possession:n.demonstrating_proof_of_possession??!1,authority_timeout_wellknowurl_in_millisecond:n.authority_timeout_wellknowurl_in_millisecond??1e4,logout_tokens_to_invalidate:n.logout_tokens_to_invalidate??["access_token","refresh_token"],service_worker_update_require_callback:l,service_worker_activate:n.service_worker_activate??kn,demonstrating_proof_of_possession_configuration:n.demonstrating_proof_of_possession_configuration??Ve},this.getFetch=s??Ie,this.configurationName=t,this.tokens=null,this.userInfo=null,this.events=[],this.timeoutId=null,this.loginCallbackWithAutoTokensRenewAsync.bind(this),this.initAsync.bind(this),this.loginCallbackAsync.bind(this),this.subscribeEvents.bind(this),this.removeEventSubscription.bind(this),this.publishEvent.bind(this),this.destroyAsync.bind(this),this.logoutAsync.bind(this),this.renewTokensAsync.bind(this),this.initAsync(this.configuration.authority,this.configuration.authority_configuration)}subscribeEvents(n){const t=An(9999999999999).toString();return this.events.push({id:t,func:n}),t}removeEventSubscription(n){const t=this.events.filter(s=>s.id!==n);this.events=t}publishEvent(n,t){this.events.forEach(s=>{s.func(n,t)})}static get(n="default"){const t=typeof process>"u";if(!Object.prototype.hasOwnProperty.call(L,n)&&t)throw Error(`OIDC library does seem initialized.
|
|
2
|
+
Please checkout that you are using OIDC hook inside a <OidcProvider configurationName="${n}"></OidcProvider> component.`);return L[n]}_silentLoginCallbackFromIFrame(){if(this.configuration.silent_redirect_uri&&this.configuration.silent_login_uri){const n=this.location,t=j(n.getCurrentHref());window.parent.postMessage(`${this.configurationName}_oidc_tokens:${JSON.stringify({tokens:this.tokens,sessionState:t.session_state})}`,n.getOrigin())}}_silentLoginErrorCallbackFromIFrame(n=null){if(this.configuration.silent_redirect_uri&&this.configuration.silent_login_uri){const t=this.location,s=j(t.getCurrentHref());s.error?window.parent.postMessage(`${this.configurationName}_oidc_error:${JSON.stringify({error:s.error})}`,t.getOrigin()):window.parent.postMessage(`${this.configurationName}_oidc_exception:${JSON.stringify({error:n==null?"":n.toString()})}`,t.getOrigin())}}async silentLoginCallbackAsync(){try{await this.loginCallbackAsync(!0),this._silentLoginCallbackFromIFrame()}catch(n){console.error(n),this._silentLoginErrorCallbackFromIFrame(n)}}async initAsync(n,t){if(this.initPromise!==null)return this.initPromise;const s=async()=>{if(t!=null)return new ce({authorization_endpoint:t.authorization_endpoint,end_session_endpoint:t.end_session_endpoint,revocation_endpoint:t.revocation_endpoint,token_endpoint:t.token_endpoint,userinfo_endpoint:t.userinfo_endpoint,check_session_iframe:t.check_session_iframe,issuer:t.issuer});const r=await I(this.configuration,this.configurationName)?window.localStorage:null;return await ze(this.getFetch())(n,this.configuration.authority_time_cache_wellknowurl_in_second??60*60,r,this.configuration.authority_timeout_wellknowurl_in_millisecond)};return this.initPromise=s(),this.initPromise.then(o=>(this.initPromise=null,o))}async tryKeepExistingSessionAsync(){return this.tryKeepExistingSessionPromise!==null?this.tryKeepExistingSessionPromise:(this.tryKeepExistingSessionPromise=mn(this),this.tryKeepExistingSessionPromise.then(n=>(this.tryKeepExistingSessionPromise=null,n)))}async startCheckSessionAsync(n,t,s,o=!1){await on(this,L,this.configuration)(n,t,s,o)}async loginAsync(n=void 0,t=null,s=!1,o=void 0,r=!1){return this.loginPromise!==null?this.loginPromise:r?sn(window,this.configurationName,this.configuration,this.publishEvent.bind(this),this)(t,o):(this.loginPromise=cn(this.configurationName,this.configuration,this.publishEvent.bind(this),this.initAsync.bind(this),this.location)(n,t,s,o),this.loginPromise.then(i=>(this.loginPromise=null,i)))}async loginCallbackAsync(n=!1){if(this.loginCallbackPromise!==null)return this.loginCallbackPromise;const t=async()=>{const s=await ln(this)(n),o=s.tokens;return this.tokens=o,await I(this.configuration,this.configurationName)||P(this.configurationName,this.configuration.storage).setTokens(o),this.publishEvent(G.eventNames.token_aquired,o),{parsedTokens:o,state:s.state,callbackPath:s.callbackPath}};return this.loginCallbackPromise=t(),this.loginCallbackPromise.then(s=>(this.loginCallbackPromise=null,s))}async generateDemonstrationOfProofOfPossessionAsync(n,t,s,o={}){const r=this.configuration,i={ath:await Se(n),...o},l=await I(r,this.configurationName);let a;if(l)return`DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${this.configurationName}`;const d=P(this.configurationName,r.storage);let f=await d.getDemonstratingProofOfPossessionJwkAsync();return a=await d.getDemonstratingProofOfPossessionNonce(),a&&(i.nonce=a),await we(window)(r.demonstrating_proof_of_possession_configuration)(f,s,t,i)}loginCallbackWithAutoTokensRenewAsync(){return this.loginCallbackWithAutoTokensRenewPromise!==null?this.loginCallbackWithAutoTokensRenewPromise:(this.loginCallbackWithAutoTokensRenewPromise=wn(this),this.loginCallbackWithAutoTokensRenewPromise.then(n=>(this.loginCallbackWithAutoTokensRenewPromise=null,n)))}userInfoAsync(n=!1){return this.userInfoPromise!==null?this.userInfoPromise:(this.userInfoPromise=dn(this)(n),this.userInfoPromise.then(t=>(this.userInfoPromise=null,t)))}async renewTokensAsync(n=null){if(this.renewTokensPromise!==null)return this.renewTokensPromise;if(this.timeoutId)return M.clearTimeout(this.timeoutId),this.renewTokensPromise=be(this,!0,n),this.renewTokensPromise.then(t=>(this.renewTokensPromise=null,t))}async destroyAsync(n){return await fn(this)(n)}async logoutSameTabAsync(n,t){this.configuration.monitor_session&&this.configuration.client_id===n&&t&&this.tokens&&this.tokens.idTokenPayload&&this.tokens.idTokenPayload.sub===t&&(await this.destroyAsync("LOGGED_OUT"),this.publishEvent(p.logout_from_same_tab,{mmessage:"SessionMonitor",sub:t}))}async logoutOtherTabAsync(n,t){this.configuration.monitor_session&&this.configuration.client_id===n&&t&&this.tokens&&this.tokens.idTokenPayload&&this.tokens.idTokenPayload.sub===t&&(await this.destroyAsync("LOGGED_OUT"),this.publishEvent(p.logout_from_another_tab,{message:"SessionMonitor",sub:t}))}async logoutAsync(n=void 0,t=null){return this.logoutPromise?this.logoutPromise:(this.logoutPromise=_n(this,L,this.getFetch(),console,this.location)(n,t),this.logoutPromise.then(s=>(this.logoutPromise=null,s)))}};G.getOrCreate=(n,t)=>(s,o="default")=>pn(n,t)(s,o),G.eventNames=p;let x=G;const U=class U{constructor(n){this._oidc=n}subscribeEvents(n){return this._oidc.subscribeEvents(n)}removeEventSubscription(n){this._oidc.removeEventSubscription(n)}publishEvent(n,t){this._oidc.publishEvent(n,t)}static get(n="default"){return new U(x.get(n))}tryKeepExistingSessionAsync(){return this._oidc.tryKeepExistingSessionAsync()}loginAsync(n=void 0,t=null,s=!1,o=void 0,r=!1){return this._oidc.loginAsync(n,t,s,o,r)}logoutAsync(n=void 0,t=null){return this._oidc.logoutAsync(n,t)}silentLoginCallbackAsync(){return this._oidc.silentLoginCallbackAsync()}renewTokensAsync(n=null){return this._oidc.renewTokensAsync(n)}loginCallbackAsync(){return this._oidc.loginCallbackWithAutoTokensRenewAsync()}get tokens(){return this._oidc.tokens}get configuration(){return this._oidc.configuration}async generateDemonstrationOfProofOfPossessionAsync(n,t,s,o={}){return this._oidc.generateDemonstrationOfProofOfPossessionAsync(n,t,s,o)}async getValidTokenAsync(n=200,t=50){return _e(this._oidc,n,t)}fetchWithTokens(n){return Pe(n,this)}async userInfoAsync(n=!1){return this._oidc.userInfoAsync(n)}};U.getOrCreate=(n,t=new q)=>(s,o="default")=>new U(x.getOrCreate(n,t)(s,o)),U.eventNames=x.eventNames;let le=U;N.OidcClient=le,N.OidcLocation=q,N.TokenAutomaticRenewMode=$,N.TokenRenewMode=X,N.getFetchDefault=Ie,N.getParseQueryStringFromLocation=j,N.getPath=rn,Object.defineProperty(N,Symbol.toStringTag,{value:"Module"})});
|
package/dist/oidc.d.ts
CHANGED
|
@@ -69,7 +69,7 @@ export declare class Oidc {
|
|
|
69
69
|
syncTokensAsync_lock_not_available: string;
|
|
70
70
|
syncTokensAsync_end: string;
|
|
71
71
|
syncTokensAsync_error: string;
|
|
72
|
-
|
|
72
|
+
tokensInvalidAndWaitingActionsToRefresh: string;
|
|
73
73
|
};
|
|
74
74
|
_silentLoginCallbackFromIFrame(): void;
|
|
75
75
|
_silentLoginErrorCallbackFromIFrame(exception?: any): void;
|
package/dist/oidcClient.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ export declare class OidcClient {
|
|
|
41
41
|
syncTokensAsync_lock_not_available: string;
|
|
42
42
|
syncTokensAsync_end: string;
|
|
43
43
|
syncTokensAsync_error: string;
|
|
44
|
-
|
|
44
|
+
tokensInvalidAndWaitingActionsToRefresh: string;
|
|
45
45
|
};
|
|
46
46
|
tryKeepExistingSessionAsync(): Promise<boolean>;
|
|
47
47
|
loginAsync(callbackPath?: string, extras?: StringMap, isSilentSignin?: boolean, scope?: string, silentLoginOnly?: boolean): Promise<unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseTokens.d.ts","sourceRoot":"","sources":["../src/parseTokens.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,SAAS,EAAE,uBAAuB,EAAC,MAAM,SAAS,CAAC;AAI9E,eAAO,MAAM,QAAQ,YAAY,MAAM,QAAsF,CAAC;AAsB9H,MAAM,MAAM,MAAM,GAAG;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAC,GAAG,CAAC;IACnB,OAAO,EAAC,MAAM,CAAC;IACf,kBAAkB,EAAC,GAAG,CAAC;IACvB,WAAW,EAAC,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC7B,gCAAgC,EAAE,MAAM,CAAC;IACzC,oBAAoB,EAAC,MAAM,CAAC;IAC5B,gBAAgB,EAAE,MAAM,CAAC;CAC5B,CAAA;AAED,eAAO,MAAM,cAAc;;;;CAI1B,CAAC;AAkBF,eAAO,MAAM,SAAS,gDAA8C,MAAM,KAAE,MAmD3E,CAAC;AAEF,eAAO,MAAM,mBAAmB,gDAAuC,MAAM,WAkC5E,CAAC;AAEF,eAAO,MAAM,eAAe,4EAM3B,CAAC;AAEF,eAAO,MAAM,aAAa,0BAKzB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACrB,aAAa,EAAE,OAAO,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;CACxB,CAAA;AAED,MAAM,WAAW,SAAS;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE;QAAG,0BAA0B,CAAC,EAAE,uBAAuB,CAAC;KAAE,CAAC;IAC1E,gBAAgB,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1D;AAED,eAAO,MAAM,kBAAkB,SAAgB,SAAS,2CAAkC,QAAQ,UAAU,
|
|
1
|
+
{"version":3,"file":"parseTokens.d.ts","sourceRoot":"","sources":["../src/parseTokens.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,SAAS,EAAE,uBAAuB,EAAC,MAAM,SAAS,CAAC;AAI9E,eAAO,MAAM,QAAQ,YAAY,MAAM,QAAsF,CAAC;AAsB9H,MAAM,MAAM,MAAM,GAAG;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAC,GAAG,CAAC;IACnB,OAAO,EAAC,MAAM,CAAC;IACf,kBAAkB,EAAC,GAAG,CAAC;IACvB,WAAW,EAAC,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC7B,gCAAgC,EAAE,MAAM,CAAC;IACzC,oBAAoB,EAAC,MAAM,CAAC;IAC5B,gBAAgB,EAAE,MAAM,CAAC;CAC5B,CAAA;AAED,eAAO,MAAM,cAAc;;;;CAI1B,CAAC;AAkBF,eAAO,MAAM,SAAS,gDAA8C,MAAM,KAAE,MAmD3E,CAAC;AAEF,eAAO,MAAM,mBAAmB,gDAAuC,MAAM,WAkC5E,CAAC;AAEF,eAAO,MAAM,eAAe,4EAM3B,CAAC;AAEF,eAAO,MAAM,aAAa,0BAKzB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACrB,aAAa,EAAE,OAAO,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;CACxB,CAAA;AAED,MAAM,WAAW,SAAS;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE;QAAG,0BAA0B,CAAC,EAAE,uBAAuB,CAAC;KAAE,CAAC;IAC1E,gBAAgB,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1D;AAED,eAAO,MAAM,kBAAkB,SAAgB,SAAS,2CAAkC,QAAQ,UAAU,CAoB3G,CAAC;AAIF,eAAO,MAAM,iBAAiB;;;CA2B7B,CAAC"}
|
package/dist/user.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../src/user.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,QAAQ,CAAC;AAG1B,eAAO,MAAM,aAAa,SAAS,IAAI,
|
|
1
|
+
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../src/user.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,QAAQ,CAAC;AAG1B,eAAO,MAAM,aAAa,SAAS,IAAI,wCAkBtC,CAAC"}
|
package/dist/version.d.ts
CHANGED
package/dist/version.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";AAAA,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";AAAA,wBAAwB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axa-fr/oidc-client",
|
|
3
|
-
"version": "7.20.1
|
|
3
|
+
"version": "7.20.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.umd.cjs",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"url": "https://github.com/AxaFrance/oidc-client.git"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@axa-fr/oidc-client-service-worker": "7.20.1
|
|
23
|
+
"@axa-fr/oidc-client-service-worker": "7.20.1"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@testing-library/dom": "9.3.4",
|
package/src/events.ts
CHANGED
|
@@ -26,5 +26,5 @@ export const eventNames = {
|
|
|
26
26
|
syncTokensAsync_lock_not_available: 'syncTokensAsync_lock_not_available',
|
|
27
27
|
syncTokensAsync_end: 'syncTokensAsync_end',
|
|
28
28
|
syncTokensAsync_error: 'syncTokensAsync_error',
|
|
29
|
-
|
|
29
|
+
tokensInvalidAndWaitingActionsToRefresh: 'tokensInvalidAndWaitingActionsToRefresh',
|
|
30
30
|
};
|
package/src/fetch.ts
CHANGED
|
@@ -15,11 +15,8 @@ export const fetchWithTokens = (fetch: Fetch, oidcClient: Oidc | null) : Fetch =
|
|
|
15
15
|
const oidc = oidcClient;
|
|
16
16
|
|
|
17
17
|
// @ts-ignore
|
|
18
|
-
console.log('before', getValidTokenAsync);
|
|
19
18
|
const getValidToken = await getValidTokenAsync(oidc);
|
|
20
|
-
console.log('getValidToken', getValidToken);
|
|
21
19
|
const accessToken = getValidToken?.tokens?.accessToken;
|
|
22
|
-
|
|
23
20
|
if (!headers.has('Accept')) {
|
|
24
21
|
headers.set('Accept', 'application/json');
|
|
25
22
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import {ILOidcLocation} from "./location";
|
|
2
|
+
|
|
1
3
|
export { getFetchDefault } from './oidc.js';
|
|
2
4
|
export { TokenRenewMode } from './parseTokens.js';
|
|
3
5
|
export { getParseQueryStringFromLocation, getPath } from './route-utils';
|
|
@@ -5,8 +7,10 @@ export type {
|
|
|
5
7
|
AuthorityConfiguration,
|
|
6
8
|
Fetch,
|
|
7
9
|
OidcConfiguration,
|
|
8
|
-
StringMap
|
|
9
|
-
TokenAutomaticRenewMode
|
|
10
|
+
StringMap
|
|
10
11
|
} from './types.js';
|
|
11
|
-
|
|
12
|
+
|
|
13
|
+
export { OidcLocation } from './location.js';
|
|
14
|
+
export type { ILOidcLocation } from './location.js';
|
|
15
|
+
export { TokenAutomaticRenewMode } from './types.js';
|
|
12
16
|
export { type OidcUserInfo, OidcClient } from './oidcClient.js';
|
package/src/parseTokens.ts
CHANGED
|
@@ -185,8 +185,9 @@ export const getValidTokenAsync = async (oidc: OidcToken, waitMs = 200, numberWa
|
|
|
185
185
|
return null;
|
|
186
186
|
}
|
|
187
187
|
while (!isTokensValid(oidc.tokens) && numberWaitTemp > 0) {
|
|
188
|
-
if(oidc.configuration.token_automatic_renew_mode == TokenAutomaticRenewMode.AutomaticOnlyWhenFetchExecuted
|
|
188
|
+
if(oidc.configuration.token_automatic_renew_mode == TokenAutomaticRenewMode.AutomaticOnlyWhenFetchExecuted){
|
|
189
189
|
await oidc.renewTokensAsync({});
|
|
190
|
+
break;
|
|
190
191
|
} else {
|
|
191
192
|
await sleepAsync({milliseconds: waitMs});
|
|
192
193
|
}
|
package/src/renewTokens.ts
CHANGED
|
@@ -241,7 +241,7 @@ const synchroniseTokensAsync = (oidc:Oidc) => async (index = 0, forceRefresh = f
|
|
|
241
241
|
case synchroniseTokensStatus.REQUIRE_SYNC_TOKENS:
|
|
242
242
|
|
|
243
243
|
if(configuration.token_automatic_renew_mode == TokenAutomaticRenewMode.AutomaticOnlyWhenFetchExecuted && synchroniseTokensStatus.FORCE_REFRESH !== status ){
|
|
244
|
-
oidc.publishEvent(eventNames.
|
|
244
|
+
oidc.publishEvent(eventNames.tokensInvalidAndWaitingActionsToRefresh, {});
|
|
245
245
|
return { tokens: oidc.tokens, status: 'GIVE_UP' };
|
|
246
246
|
}
|
|
247
247
|
|
|
@@ -250,7 +250,7 @@ const synchroniseTokensAsync = (oidc:Oidc) => async (index = 0, forceRefresh = f
|
|
|
250
250
|
default: {
|
|
251
251
|
|
|
252
252
|
if(configuration.token_automatic_renew_mode == TokenAutomaticRenewMode.AutomaticOnlyWhenFetchExecuted && synchroniseTokensStatus.FORCE_REFRESH !== status ){
|
|
253
|
-
oidc.publishEvent(eventNames.
|
|
253
|
+
oidc.publishEvent(eventNames.tokensInvalidAndWaitingActionsToRefresh, {});
|
|
254
254
|
return { tokens: oidc.tokens, status: 'GIVE_UP' };
|
|
255
255
|
}
|
|
256
256
|
|
package/src/user.ts
CHANGED
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '7.20.1
|
|
1
|
+
export default '7.20.1';
|