From d2e7faa3bb12a80b4d94a9b847fbccac071961ea Mon Sep 17 00:00:00 2001 From: Mohamadzadeh <7796733@gmail.com> Date: Sat, 13 Jun 2026 09:50:57 +0330 Subject: [PATCH] update keycloak --- dist/index.js | 417 +++++++++++++++++++++--------------------- src/core/keycloak.jsx | 24 ++- src/index.js | 7 +- 3 files changed, 240 insertions(+), 208 deletions(-) diff --git a/dist/index.js b/dist/index.js index 5939c5f..7d624e5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4,34 +4,34 @@ var ve = (r) => { }; var je = (r, e, t) => e in r ? ze(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t; var f = (r, e, t) => je(r, typeof e != "symbol" ? e + "" : e, t), oe = (r, e, t) => e.has(r) || ve("Cannot " + t); -var u = (r, e, t) => (oe(r, e, "read from private field"), t ? t.call(r) : e.get(r)), A = (r, e, t) => e.has(r) ? ve("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(r) : e.set(r, t), B = (r, e, t, i) => (oe(r, e, "write to private field"), i ? i.call(r, t) : e.set(r, t), t), d = (r, e, t) => (oe(r, e, "access private method"), t); -import { jsxs as O, jsx as v } from "react/jsx-runtime"; +var h = (r, e, t) => (oe(r, e, "read from private field"), t ? t.call(r) : e.get(r)), A = (r, e, t) => e.has(r) ? ve("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(r) : e.set(r, t), B = (r, e, t, i) => (oe(r, e, "write to private field"), i ? i.call(r, t) : e.set(r, t), t), d = (r, e, t) => (oe(r, e, "access private method"), t); +import { jsxs as O, jsx as S } from "react/jsx-runtime"; import { useState as I, useRef as ie, useEffect as W, useCallback as H, createContext as Oe, useMemo as We, useContext as Fe } from "react"; -import { HStack as K, IconButton as G, Button as ge, Input as ke, Text as j } from "@chakra-ui/react"; +import { HStack as N, IconButton as G, Button as ge, Input as ke, Text as j } from "@chakra-ui/react"; import { IoChevronForwardOutline as be, IoChevronBackOutline as ye } from "react-icons/io5"; -const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), y = (r) => String(r).replace(/\d/g, (e) => "۰۱۲۳۴۵۶۷۸۹"[Number(e)]), F = (r) => String(r).replace(/[۰-۹]/g, (t) => String("۰۱۲۳۴۵۶۷۸۹".indexOf(t))), vt = ({ +const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => String(r).replace(/\d/g, (e) => "۰۱۲۳۴۵۶۷۸۹"[Number(e)]), F = (r) => String(r).replace(/[۰-۹]/g, (t) => String("۰۱۲۳۴۵۶۷۸۹".indexOf(t))), vt = ({ currentPage: r, totalPages: e, totalCount: t, onPageChange: i }) => { - const [n, o] = I(y(r)), [c, a] = I(!1), [l, h] = I(null), w = ie(null), m = [.../* @__PURE__ */ new Set([1, r, e])].filter( + const [n, o] = I(v(r)), [c, a] = I(!1), [l, u] = I(null), w = ie(null), m = [.../* @__PURE__ */ new Set([1, r, e])].filter( (p) => p >= 1 && p <= e ); W(() => { if (l !== null) { - r === l && (h(null), a(!1), o(y(r))); + r === l && (u(null), a(!1), o(v(r))); return; } - c || o(y(r)); + c || o(v(r)); }, [r, c, l]), W(() => { if (!c || !n || l !== null) return; const p = parseInt(F(n), 10); if (isNaN(p)) return; const k = setTimeout(() => { - var S; + var C; const g = Math.min(Math.max(p, 1), e); - g !== r ? (h(g), o(y(g)), i(g)) : (a(!1), o(y(r))), (S = w.current) == null || S.blur(); + g !== r ? (u(g), o(v(g)), i(g)) : (a(!1), o(v(r))), (C = w.current) == null || C.blur(); }, 1e3); return () => clearTimeout(k); }, [ @@ -42,18 +42,18 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), y = (r) => S r, i ]); - const C = () => { - var g, S; + const T = () => { + var g, C; const p = parseInt(F(n), 10); if (isNaN(p)) { - o(y(r)), a(!1), h(null), (g = w.current) == null || g.blur(); + o(v(r)), a(!1), u(null), (g = w.current) == null || g.blur(); return; } const k = Math.min(Math.max(p, 1), e); - k !== r ? (h(k), o(y(k)), i(k)) : (o(y(r)), a(!1), h(null)), (S = w.current) == null || S.blur(); + k !== r ? (u(k), o(v(k)), i(k)) : (o(v(r)), a(!1), u(null)), (C = w.current) == null || C.blur(); }; return e === 0 || !t ? null : /* @__PURE__ */ O( - K, + N, { justifyContent: "space-around", backgroundColor: "white", @@ -64,8 +64,8 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), y = (r) => S borderColor: "blue.200", w: "100%", children: [ - /* @__PURE__ */ O(K, { spacing: 2, alignItems: "center", justifyContent: "center", children: [ - /* @__PURE__ */ v( + /* @__PURE__ */ O(N, { spacing: 2, alignItems: "center", justifyContent: "center", children: [ + /* @__PURE__ */ S( G, { size: "md", @@ -74,11 +74,11 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), y = (r) => S _hover: { bg: "#cbcbe8" }, onClick: () => i(r - 1), isDisabled: r === 1, - icon: /* @__PURE__ */ v(be, {}), + icon: /* @__PURE__ */ S(be, {}), "aria-label": "صفحه قبلی" } ), - m.map((p) => /* @__PURE__ */ v( + m.map((p) => /* @__PURE__ */ S( ge, { size: "md", @@ -88,11 +88,11 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), y = (r) => S _hover: { bg: r === p ? "#4B49AC" : "#cbcbe8" }, onClick: () => i(p), variant: "soft", - children: y(p) + children: v(p) }, p )), - /* @__PURE__ */ v( + /* @__PURE__ */ S( G, { size: "md", @@ -101,11 +101,11 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), y = (r) => S _hover: { bg: "#cbcbe8" }, onClick: () => i(r + 1), isDisabled: r === e, - icon: /* @__PURE__ */ v(ye, {}), + icon: /* @__PURE__ */ S(ye, {}), "aria-label": "صفحه بعدی" } ), - /* @__PURE__ */ v( + /* @__PURE__ */ S( ke, { ref: w, @@ -115,17 +115,17 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), y = (r) => S w: "56px", value: n, onFocus: () => { - a(!0), h(null), o(""); + a(!0), u(null), o(""); }, onChange: (p) => { const k = p.target.value, g = F(k).replace(/\D/g, ""); - o(y(g)); + o(v(g)); }, onBlur: () => { - n || (o(y(r)), a(!1), h(null)); + n || (o(v(r)), a(!1), u(null)); }, onKeyDown: (p) => { - p.key === "Enter" && C(); + p.key === "Enter" && T(); }, textAlign: "center", color: "#1D2939", @@ -135,9 +135,9 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), y = (r) => S } ) ] }), - /* @__PURE__ */ O(K, { spacing: 2, children: [ - /* @__PURE__ */ v(j, { w: "auto", fontWeight: "bold", whiteSpace: "nowrap", children: "تعداد کل:" }), - /* @__PURE__ */ v(j, { children: y(t) }) + /* @__PURE__ */ O(N, { spacing: 2, children: [ + /* @__PURE__ */ S(j, { w: "auto", fontWeight: "bold", whiteSpace: "nowrap", children: "تعداد کل:" }), + /* @__PURE__ */ S(j, { children: v(t) }) ] }) ] } @@ -148,23 +148,23 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), y = (r) => S totalCount: t, onPageChange: i }) => { - const [n, o] = I(y(r)), [c, a] = I(!1), [l, h] = I(null), w = ie(null), m = Array.from( + const [n, o] = I(v(r)), [c, a] = I(!1), [l, u] = I(null), w = ie(null), m = Array.from( /* @__PURE__ */ new Set([1, r, r + 1, e]) ).filter((p) => p >= 1 && p <= e).sort((p, k) => p - k); W(() => { if (l !== null) { - r === l && (h(null), a(!1), o(y(r))); + r === l && (u(null), a(!1), o(v(r))); return; } - c || o(y(r)); + c || o(v(r)); }, [r, c, l]), W(() => { if (!c || !n || l !== null) return; const p = parseInt(F(n), 10); if (isNaN(p)) return; const k = setTimeout(() => { - var S; + var C; const g = Math.min(Math.max(p, 1), e); - g !== r ? (h(g), o(y(g)), i(g)) : (a(!1), o(y(r))), (S = w.current) == null || S.blur(); + g !== r ? (u(g), o(v(g)), i(g)) : (a(!1), o(v(r))), (C = w.current) == null || C.blur(); }, 1e3); return () => clearTimeout(k); }, [ @@ -175,18 +175,18 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), y = (r) => S r, i ]); - const C = () => { - var g, S; + const T = () => { + var g, C; const p = parseInt(F(n), 10); if (isNaN(p)) { - o(y(r)), a(!1), h(null), (g = w.current) == null || g.blur(); + o(v(r)), a(!1), u(null), (g = w.current) == null || g.blur(); return; } const k = Math.min(Math.max(p, 1), e); - k !== r ? (h(k), o(y(k)), i(k)) : (o(y(r)), a(!1), h(null)), (S = w.current) == null || S.blur(); + k !== r ? (u(k), o(v(k)), i(k)) : (o(v(r)), a(!1), u(null)), (C = w.current) == null || C.blur(); }; return e === 0 || !t ? null : /* @__PURE__ */ O( - K, + N, { justifyContent: "space-around", backgroundColor: "white", @@ -197,14 +197,14 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), y = (r) => S borderColor: "blue.200", w: "100%", children: [ - /* @__PURE__ */ O(K, { spacing: 2, whiteSpace: "nowrap", children: [ - /* @__PURE__ */ v(j, { fontWeight: "bold", children: "صفحه" }), - /* @__PURE__ */ v(j, { children: y(r) }), - /* @__PURE__ */ v(j, { fontWeight: "bold", children: "از" }), - /* @__PURE__ */ v(j, { children: y(e) }) + /* @__PURE__ */ O(N, { spacing: 2, whiteSpace: "nowrap", children: [ + /* @__PURE__ */ S(j, { fontWeight: "bold", children: "صفحه" }), + /* @__PURE__ */ S(j, { children: v(r) }), + /* @__PURE__ */ S(j, { fontWeight: "bold", children: "از" }), + /* @__PURE__ */ S(j, { children: v(e) }) ] }), - /* @__PURE__ */ O(K, { spacing: 2, alignItems: "center", justifyContent: "center", children: [ - /* @__PURE__ */ v( + /* @__PURE__ */ O(N, { spacing: 2, alignItems: "center", justifyContent: "center", children: [ + /* @__PURE__ */ S( G, { size: "md", @@ -213,11 +213,11 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), y = (r) => S _hover: { bg: "#cbcbe8" }, onClick: () => i(r - 1), isDisabled: r === 1, - icon: /* @__PURE__ */ v(be, {}), + icon: /* @__PURE__ */ S(be, {}), "aria-label": "صفحه قبلی" } ), - m.map((p) => /* @__PURE__ */ v( + m.map((p) => /* @__PURE__ */ S( ge, { size: "md", @@ -226,11 +226,11 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), y = (r) => S _hover: { bg: r === p ? "#4B49AC" : "#cbcbe8" }, onClick: () => i(p), variant: "soft", - children: y(p) + children: v(p) }, p )), - /* @__PURE__ */ v( + /* @__PURE__ */ S( G, { size: "md", @@ -239,11 +239,11 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), y = (r) => S _hover: { bg: "#cbcbe8" }, onClick: () => i(r + 1), isDisabled: r === e, - icon: /* @__PURE__ */ v(ye, {}), + icon: /* @__PURE__ */ S(ye, {}), "aria-label": "صفحه بعدی" } ), - /* @__PURE__ */ v( + /* @__PURE__ */ S( ke, { ref: w, @@ -253,17 +253,17 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), y = (r) => S w: "100px", value: n, onFocus: () => { - a(!0), h(null), o(""); + a(!0), u(null), o(""); }, onChange: (p) => { const k = p.target.value, g = F(k).replace(/\D/g, ""); - o(y(g)); + o(v(g)); }, onBlur: () => { - n || (o(y(r)), a(!1), h(null)); + n || (o(v(r)), a(!1), u(null)); }, onKeyDown: (p) => { - p.key === "Enter" && C(); + p.key === "Enter" && T(); }, textAlign: "center", color: "#1D2939", @@ -273,9 +273,9 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), y = (r) => S } ) ] }), - /* @__PURE__ */ O(K, { spacing: 2, whiteSpace: "nowrap", children: [ - /* @__PURE__ */ v(j, { fontWeight: "bold", children: "تعداد کل:" }), - /* @__PURE__ */ v(j, { children: y(t) }) + /* @__PURE__ */ O(N, { spacing: 2, whiteSpace: "nowrap", children: [ + /* @__PURE__ */ S(j, { fontWeight: "bold", children: "تعداد کل:" }), + /* @__PURE__ */ S(j, { children: v(t) }) ] }) ] } @@ -286,30 +286,30 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), y = (r) => S totalCount: t, onPageChange: i }) => { - const [n, o] = I(""), [c, a] = I(!1), [l, h] = I(null), w = ie(null), m = l ?? r, C = H( + const [n, o] = I(""), [c, a] = I(!1), [l, u] = I(null), w = ie(null), m = l ?? r, T = H( (U) => { const E = Math.min(Math.max(U, 1), e); - a(!1), o(""), h(null), E !== r && i(E); + a(!1), o(""), u(null), E !== r && i(E); }, [r, e, i] ), p = H(() => { if (!n) { - a(!1), o(""), h(null); + a(!1), o(""), u(null); return; } const U = parseInt(F(n), 10); if (isNaN(U)) { - a(!1), o(""), h(null); + a(!1), o(""), u(null); return; } const E = Math.min(Math.max(U, 1), e); - a(!1), o(""), E !== r ? (h(E), i(E)) : h(null); + a(!1), o(""), E !== r ? (u(E), i(E)) : u(null); }, [n, r, e, i]); W(() => { var U; c && ((U = w.current) == null || U.focus()); }, [c]), W(() => { - l !== null && r === l && h(null); + l !== null && r === l && u(null); }, [r, l]), W(() => { if (!c || !n) return; const U = setTimeout(() => { @@ -318,24 +318,24 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), y = (r) => S return () => clearTimeout(U); }, [n, c, p]); const k = () => { - h(null), o(""), a(!0); - }, g = (U, E = !1) => /* @__PURE__ */ v( + u(null), o(""), a(!0); + }, g = (U, E = !1) => /* @__PURE__ */ S( ge, { size: "md", bg: E ? "#4B49AC" : "#e6e6f1", color: E ? "#e6e6f1" : "#4B49AC", _hover: { bg: E ? "#4B49AC" : "#cbcbe8" }, - onClick: E ? k : () => C(U), + onClick: E ? k : () => T(U), variant: "soft", - children: y(U) + children: v(U) }, U ); if (e === 0 || !t) return null; - const S = e > 1 && m !== 1, V = e > 1 && m !== e; - return /* @__PURE__ */ v( - K, + const C = e > 1 && m !== 1, V = e > 1 && m !== e; + return /* @__PURE__ */ S( + N, { justifyContent: "center", backgroundColor: "white", @@ -345,22 +345,22 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), y = (r) => S border: "1px", borderColor: "blue.200", w: "100%", - children: /* @__PURE__ */ O(K, { spacing: 2, alignItems: "center", justifyContent: "center", children: [ - /* @__PURE__ */ v( + children: /* @__PURE__ */ O(N, { spacing: 2, alignItems: "center", justifyContent: "center", children: [ + /* @__PURE__ */ S( G, { size: "md", bg: "#e6e6f1", color: "#4B49AC", _hover: { bg: "#cbcbe8" }, - onClick: () => C(m - 1), + onClick: () => T(m - 1), isDisabled: m === 1, - icon: /* @__PURE__ */ v(be, {}), + icon: /* @__PURE__ */ S(be, {}), "aria-label": "صفحه قبلی" } ), - S && g(1), - c ? /* @__PURE__ */ v( + C && g(1), + c ? /* @__PURE__ */ S( ke, { ref: w, @@ -371,13 +371,13 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), y = (r) => S value: n, onChange: (U) => { const E = U.target.value, Pe = F(E).replace(/\D/g, ""); - o(y(Pe)); + o(v(Pe)); }, onBlur: () => { - n ? p() : (o(""), a(!1), h(null)); + n ? p() : (o(""), a(!1), u(null)); }, onKeyDown: (U) => { - U.key === "Enter" && p(), U.key === "Escape" && (o(""), a(!1), h(null)); + U.key === "Enter" && p(), U.key === "Escape" && (o(""), a(!1), u(null)); }, textAlign: "center", color: "#1D2939", @@ -387,16 +387,16 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), y = (r) => S } ) : g(m, !0), V && g(e), - /* @__PURE__ */ v( + /* @__PURE__ */ S( G, { size: "md", bg: "#e6e6f1", color: "#4B49AC", _hover: { bg: "#cbcbe8" }, - onClick: () => C(m + 1), + onClick: () => T(m + 1), isDisabled: m === e, - icon: /* @__PURE__ */ v(ye, {}), + icon: /* @__PURE__ */ S(ye, {}), "aria-label": "صفحه بعدی" } ) @@ -404,7 +404,7 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), y = (r) => S } ); }, Ve = "application/json"; -var N, T, $, J, M, q, b, L, s, ee, _e, Te, Ee, Ae, ae, Ie, ce, xe, Le, te, X, le, P, Re, de, z, re, Z, R, he; +var K, _, $, J, M, q, y, L, s, ee, Ue, _e, Ee, Ae, ae, Ie, ce, xe, Le, te, X, le, P, Re, de, z, re, Z, R, ue; class He { /** * @param {KeycloakConfig} config @@ -412,17 +412,17 @@ class He { constructor(e) { A(this, s); /** @type {Pick, 'resolve' | 'reject'>[]} */ - A(this, N, []); + A(this, K, []); /** @type {KeycloakAdapter} */ - A(this, T); + A(this, _); /** @type {boolean} */ A(this, $, !0); /** @type {CallbackStorage} */ A(this, J); - A(this, M, d(this, s, he).call(this, console.info)); - A(this, q, d(this, s, he).call(this, console.warn)); + A(this, M, d(this, s, ue).call(this, console.info)); + A(this, q, d(this, s, ue).call(this, console.warn)); /** @type {LoginIframe} */ - A(this, b, { + A(this, y, { enable: !0, callbackList: [], interval: 5 @@ -514,7 +514,7 @@ class He { throw new Error("A 'Keycloak' instance can only be initialized once."); this.didInitialize = !0, B(this, J, Xe()); const t = ["default", "cordova", "cordova-native"]; - if (typeof e.adapter == "string" && t.includes(e.adapter) ? B(this, T, d(this, s, ee).call(this, e.adapter)) : typeof e.adapter == "object" ? B(this, T, e.adapter) : "Cordova" in window || "cordova" in window ? B(this, T, d(this, s, ee).call(this, "cordova")) : B(this, T, d(this, s, ee).call(this, "default")), typeof e.useNonce < "u" && B(this, $, e.useNonce), typeof e.checkLoginIframe < "u" && (u(this, b).enable = e.checkLoginIframe), e.checkLoginIframeInterval && (u(this, b).interval = e.checkLoginIframeInterval), e.onLoad === "login-required" && (this.loginRequired = !0), e.responseMode) + if (typeof e.adapter == "string" && t.includes(e.adapter) ? B(this, _, d(this, s, ee).call(this, e.adapter)) : typeof e.adapter == "object" ? B(this, _, e.adapter) : "Cordova" in window || "cordova" in window ? B(this, _, d(this, s, ee).call(this, "cordova")) : B(this, _, d(this, s, ee).call(this, "default")), typeof e.useNonce < "u" && B(this, $, e.useNonce), typeof e.checkLoginIframe < "u" && (h(this, y).enable = e.checkLoginIframe), e.checkLoginIframeInterval && (h(this, y).interval = e.checkLoginIframeInterval), e.onLoad === "login-required" && (this.loginRequired = !0), e.responseMode) if (e.responseMode === "query" || e.responseMode === "fragment") this.responseMode = e.responseMode; else @@ -546,13 +546,13 @@ class He { * @param {KeycloakLoginOptions} [options] * @returns {Promise} */ - f(this, "login", (e) => u(this, T).login(e)); + f(this, "login", (e) => h(this, _).login(e)); /** * @param {KeycloakLoginOptions} [options] * @returns {Promise} */ f(this, "createLoginUrl", async (e) => { - const t = Se(), i = Se(), n = u(this, T).redirectUri(e), o = { + const t = Se(), i = Se(), n = h(this, _).redirectUri(e), o = { state: t, nonce: i, redirectUri: n, @@ -563,7 +563,7 @@ class He { let a = (e == null ? void 0 : e.scope) || this.scope; const l = a ? a.split(" ") : []; l.includes("openid") || l.unshift("openid"), a = l.join(" "); - const h = new URLSearchParams([ + const u = new URLSearchParams([ [ "client_id", /** @type {string} */ @@ -575,20 +575,20 @@ class He { ["response_type", this.responseType], ["scope", a] ]); - if (u(this, $) && h.append("nonce", i), e != null && e.prompt && h.append("prompt", e.prompt), typeof (e == null ? void 0 : e.maxAge) == "number" && h.append("max_age", e.maxAge.toString()), e != null && e.loginHint && h.append("login_hint", e.loginHint), e != null && e.idpHint && h.append("kc_idp_hint", e.idpHint), e != null && e.action && e.action !== "register" && h.append("kc_action", e.action), e != null && e.locale && h.append("ui_locales", e.locale), e != null && e.acr && h.append("claims", Ye(e.acr)), e != null && e.acrValues && h.append("acr_values", e.acrValues), this.pkceMethod) + if (h(this, $) && u.append("nonce", i), e != null && e.prompt && u.append("prompt", e.prompt), typeof (e == null ? void 0 : e.maxAge) == "number" && u.append("max_age", e.maxAge.toString()), e != null && e.loginHint && u.append("login_hint", e.loginHint), e != null && e.idpHint && u.append("kc_idp_hint", e.idpHint), e != null && e.action && e.action !== "register" && u.append("kc_action", e.action), e != null && e.locale && u.append("ui_locales", e.locale), e != null && e.acr && u.append("claims", Ye(e.acr)), e != null && e.acrValues && u.append("acr_values", e.acrValues), this.pkceMethod) try { const w = $e(96), m = await Je(this.pkceMethod, w); - o.pkceCodeVerifier = w, h.append("code_challenge", m), h.append("code_challenge_method", this.pkceMethod); + o.pkceCodeVerifier = w, u.append("code_challenge", m), u.append("code_challenge_method", this.pkceMethod); } catch (w) { throw new Error("Failed to generate PKCE challenge.", { cause: w }); } - return u(this, J).add(o), `${c}?${h.toString()}`; + return h(this, J).add(o), `${c}?${u.toString()}`; }); /** * @param {KeycloakLogoutOptions} [options] * @returns {Promise} */ - f(this, "logout", (e) => u(this, T).logout(e)); + f(this, "logout", (e) => h(this, _).logout(e)); /** * @param {KeycloakLogoutOptions} [options] * @returns {string} @@ -603,7 +603,7 @@ class He { /** @type {string} */ this.clientId ], - ["post_logout_redirect_uri", u(this, T).redirectUri(e)] + ["post_logout_redirect_uri", h(this, _).redirectUri(e)] ]); return this.idToken && n.append("id_token_hint", this.idToken), `${i}?${n.toString()}`; }); @@ -611,7 +611,7 @@ class He { * @param {KeycloakRegisterOptions} [options] * @returns {Promise} */ - f(this, "register", (e) => u(this, T).register(e)); + f(this, "register", (e) => h(this, _).register(e)); /** * @param {KeycloakRegisterOptions} [options] * @returns {Promise} @@ -631,14 +631,14 @@ class He { /** @type {string} */ this.clientId ], - ["referrer_uri", u(this, T).redirectUri(e)] + ["referrer_uri", h(this, _).redirectUri(e)] ]); return `${t}/account?${i.toString()}`; }); /** * @returns {Promise} */ - f(this, "accountManagement", () => u(this, T).accountManagement()); + f(this, "accountManagement", () => h(this, _).accountManagement()); /** * @param {string} role * @returns {boolean} @@ -688,7 +688,7 @@ class He { if (!this.tokenParsed || !this.refreshToken && this.flow !== "implicit") throw new Error("Not authenticated"); if (this.timeSkew == null) - return u(this, M).call(this, "[KEYCLOAK] Unable to determine if token is expired as timeskew is not set"), !0; + return h(this, M).call(this, "[KEYCLOAK] Unable to determine if token is expired as timeskew is not set"), !0; if (typeof this.tokenParsed.exp != "number") return !1; let t = this.tokenParsed.exp - Math.ceil((/* @__PURE__ */ new Date()).getTime() / 1e3) + this.timeSkew; @@ -707,14 +707,14 @@ class He { var c, a; if (!this.refreshToken) throw new Error("Unable to update token, no refresh token available."); - e = e || 5, u(this, b).enable && await d(this, s, X).call(this); + e = e || 5, h(this, y).enable && await d(this, s, X).call(this); let t = !1; - if (e === -1 ? (t = !0, u(this, M).call(this, "[KEYCLOAK] Refreshing token: forced refresh")) : (!this.tokenParsed || this.isTokenExpired(e)) && (t = !0, u(this, M).call(this, "[KEYCLOAK] Refreshing token: token expired")), !t) + if (e === -1 ? (t = !0, h(this, M).call(this, "[KEYCLOAK] Refreshing token: forced refresh")) : (!this.tokenParsed || this.isTokenExpired(e)) && (t = !0, h(this, M).call(this, "[KEYCLOAK] Refreshing token: token expired")), !t) return !1; const { promise: i, resolve: n, reject: o } = Promise.withResolvers(); - if (u(this, N).push({ resolve: n, reject: o }), u(this, N).length === 1) { + if (h(this, K).push({ resolve: n, reject: o }), h(this, K).length === 1) { const l = this.endpoints.token(); - let h = (/* @__PURE__ */ new Date()).getTime(); + let u = (/* @__PURE__ */ new Date()).getTime(); try { const w = await ct( l, @@ -722,12 +722,12 @@ class He { /** @type {string} */ this.clientId ); - u(this, M).call(this, "[KEYCLOAK] Token refreshed"), h = (h + (/* @__PURE__ */ new Date()).getTime()) / 2, d(this, s, Z).call(this, w.access_token, w.refresh_token, w.id_token, h), (c = this.onAuthRefreshSuccess) == null || c.call(this); - for (let m = u(this, N).pop(); m != null; m = u(this, N).pop()) + h(this, M).call(this, "[KEYCLOAK] Token refreshed"), u = (u + (/* @__PURE__ */ new Date()).getTime()) / 2, d(this, s, Z).call(this, w.access_token, w.refresh_token, w.id_token, u), (c = this.onAuthRefreshSuccess) == null || c.call(this); + for (let m = h(this, K).pop(); m != null; m = h(this, K).pop()) m.resolve(!0); } catch (w) { - u(this, q).call(this, "[KEYCLOAK] Failed to refresh token"), w instanceof Ke && w.response.status === 400 && this.clearToken(), (a = this.onAuthRefreshError) == null || a.call(this); - for (let m = u(this, N).pop(); m != null; m = u(this, N).pop()) + h(this, q).call(this, "[KEYCLOAK] Failed to refresh token"), w instanceof Ne && w.response.status === 400 && this.clearToken(), (a = this.onAuthRefreshError) == null || a.call(this); + for (let m = h(this, K).pop(); m != null; m = h(this, K).pop()) m.reject(w); } } @@ -745,28 +745,28 @@ class He { if (!(i in e)) throw new Error(`The configuration object is missing the required '${i}' property.`); } - globalThis.isSecureContext || u(this, q).call(this, `[KEYCLOAK] Keycloak JS must be used in a 'secure context' to function properly as it relies on browser APIs that are otherwise not available. + globalThis.isSecureContext || h(this, q).call(this, `[KEYCLOAK] Keycloak JS must be used in a 'secure context' to function properly as it relies on browser APIs that are otherwise not available. Continuing to run your application insecurely will lead to unexpected behavior and breakage. For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts`), B(this, L, e); } } -N = new WeakMap(), T = new WeakMap(), $ = new WeakMap(), J = new WeakMap(), M = new WeakMap(), q = new WeakMap(), b = new WeakMap(), L = new WeakMap(), s = new WeakSet(), /** +K = new WeakMap(), _ = new WeakMap(), $ = new WeakMap(), J = new WeakMap(), M = new WeakMap(), q = new WeakMap(), y = new WeakMap(), L = new WeakMap(), s = new WeakSet(), /** * @param {"default" | "cordova" | "cordova-native"} type * @returns {KeycloakAdapter} */ ee = function(e) { if (e === "default") - return d(this, s, _e).call(this); + return d(this, s, Ue).call(this); if (e === "cordova") - return u(this, b).enable = !1, d(this, s, Te).call(this); + return h(this, y).enable = !1, d(this, s, _e).call(this); if (e === "cordova-native") - return u(this, b).enable = !1, d(this, s, Ee).call(this); + return h(this, y).enable = !1, d(this, s, Ee).call(this); throw new Error("invalid adapter type: " + e); }, /** * @returns {KeycloakAdapter} */ -_e = function() { +Ue = function() { const e = (t) => (t == null ? void 0 : t.redirectUri) || this.redirectUri || globalThis.location.href; return { login: async (t) => (window.location.assign(await this.createLoginUrl(t)), await new Promise(() => { @@ -809,70 +809,70 @@ _e = function() { }, /** * @returns {KeycloakAdapter} */ -Te = function() { +_e = function() { const e = (c, a, l) => window.cordova && window.cordova.InAppBrowser ? window.cordova.InAppBrowser.open(c, a, l) : window.open(c, a, l), t = (c) => c && c.cordovaOptions ? Object.keys(c.cordovaOptions).reduce((a, l) => (a[l] = c.cordovaOptions[l], a), {}) : {}, i = (c) => Object.keys(c).reduce((a, l) => (a.push(l + "=" + c[l]), a), []).join(","), n = (c) => { const a = t(c); return a.location = "no", c && c.prompt === "none" && (a.hidden = "yes"), i(a); }, o = () => this.redirectUri || "http://localhost"; return { login: async (c) => { - const a = n(c), l = await this.createLoginUrl(c), h = e(l, "_blank", a); + const a = n(c), l = await this.createLoginUrl(c), u = e(l, "_blank", a); let w = !1, m = !1; - function C() { - m = !0, h.close(); + function T() { + m = !0, u.close(); } return await new Promise((p, k) => { - h.addEventListener("loadstart", async (g) => { + u.addEventListener("loadstart", async (g) => { if (g.url.indexOf(o()) === 0) { - const S = d(this, s, P).call(this, g.url); - w = !0, C(); + const C = d(this, s, P).call(this, g.url); + w = !0, T(); try { - await d(this, s, z).call(this, S), p(); + await d(this, s, z).call(this, C), p(); } catch (V) { k(V); } } - }), h.addEventListener("loaderror", async (g) => { + }), u.addEventListener("loaderror", async (g) => { if (!w) if (g.url.indexOf(o()) === 0) { - const S = d(this, s, P).call(this, g.url); - w = !0, C(); + const C = d(this, s, P).call(this, g.url); + w = !0, T(); try { - await d(this, s, z).call(this, S), p(); + await d(this, s, z).call(this, C), p(); } catch (V) { k(V); } } else - k(new Error("Unable to process login.")), C(); - }), h.addEventListener("exit", function(g) { + k(new Error("Unable to process login.")), T(); + }), u.addEventListener("exit", function(g) { m || k(new Error("User closed the login window.")); }); }); }, logout: async (c) => { const a = this.createLogoutUrl(c), l = e(a, "_blank", "location=no,hidden=yes,clearcache=yes"); - let h = !1; + let u = !1; l.addEventListener("loadstart", (w) => { w.url.indexOf(o()) === 0 && l.close(); }), l.addEventListener("loaderror", (w) => { - w.url.indexOf(o()) === 0 || (h = !0), l.close(); + w.url.indexOf(o()) === 0 || (u = !0), l.close(); }), await new Promise((w, m) => { l.addEventListener("exit", () => { - h ? m(new Error("User closed the login window.")) : (this.clearToken(), w()); + u ? m(new Error("User closed the login window.")) : (this.clearToken(), w()); }); }); }, register: async (c) => { - const a = await this.createRegisterUrl(), l = n(c), h = e(a, "_blank", l); - await new Promise((m, C) => { - h.addEventListener("loadstart", async (p) => { + const a = await this.createRegisterUrl(), l = n(c), u = e(a, "_blank", l); + await new Promise((m, T) => { + u.addEventListener("loadstart", async (p) => { if (p.url.indexOf(o()) === 0) { - h.close(); + u.close(); const k = d(this, s, P).call(this, p.url); try { await d(this, s, z).call(this, k), m(); } catch (g) { - C(g); + T(g); } } }); @@ -941,11 +941,11 @@ Ee = function() { redirectUri: (e) => e && e.redirectUri ? e.redirectUri : this.redirectUri ? this.redirectUri : "http://localhost" }; }, Ae = async function() { - if (typeof u(this, L) == "string") { - const e = await nt(u(this, L)); + if (typeof h(this, L) == "string") { + const e = await nt(h(this, L)); this.authServerUrl = e["auth-server-url"], this.realm = e.realm, this.clientId = e.resource, d(this, s, ae).call(this); } else - this.clientId = u(this, L).clientId, "oidcProvider" in u(this, L) ? await d(this, s, Ie).call(this, u(this, L).oidcProvider) : (this.authServerUrl = u(this, L).url, this.realm = u(this, L).realm, d(this, s, ae).call(this)); + this.clientId = h(this, L).clientId, "oidcProvider" in h(this, L) ? await d(this, s, Ie).call(this, h(this, L).oidcProvider) : (this.authServerUrl = h(this, L).url, this.realm = h(this, L).realm, d(this, s, ae).call(this)); }, /** * @returns {void} */ @@ -961,7 +961,7 @@ ae = function() { }; }, Ie = async function(e) { if (typeof e == "string") { - const t = `${Ue(e)}/.well-known/openid-configuration`, i = await st(t); + const t = `${Te(e)}/.well-known/openid-configuration`, i = await st(t); d(this, s, ce).call(this, i); } else d(this, s, ce).call(this, e); @@ -997,18 +997,18 @@ ce = function(e) { } }; }, xe = async function() { - if (!u(this, b).enable && !this.silentCheckSsoRedirectUri || typeof this.endpoints.thirdPartyCookiesIframe != "function") + if (!h(this, y).enable && !this.silentCheckSsoRedirectUri || typeof this.endpoints.thirdPartyCookiesIframe != "function") return; const e = document.createElement("iframe"); e.setAttribute("src", this.endpoints.thirdPartyCookiesIframe()), e.setAttribute("sandbox", "allow-storage-access-by-user-activation allow-scripts allow-same-origin"), e.setAttribute("title", "keycloak-3p-check-iframe"), e.style.display = "none", document.body.appendChild(e); const t = new Promise((i) => { const n = (o) => { - e.contentWindow === o.source && (o.data !== "supported" && o.data !== "unsupported" || (o.data === "unsupported" && (u(this, q).call(this, `[KEYCLOAK] Your browser is blocking access to 3rd-party cookies, this means: + e.contentWindow === o.source && (o.data !== "supported" && o.data !== "unsupported" || (o.data === "unsupported" && (h(this, q).call(this, `[KEYCLOAK] Your browser is blocking access to 3rd-party cookies, this means: - It is not possible to retrieve tokens without redirecting to the Keycloak server (a.k.a. no support for silent authentication). - It is not possible to automatically detect changes to the session status (such as the user logging out in another tab). -For more information see: https://www.keycloak.org/securing-apps/javascript-adapter#_modern_browsers`), u(this, b).enable = !1, this.silentCheckSsoFallback && (this.silentCheckSsoRedirectUri = void 0)), document.body.removeChild(e), window.removeEventListener("message", n), i())); +For more information see: https://www.keycloak.org/securing-apps/javascript-adapter#_modern_browsers`), h(this, y).enable = !1, this.silentCheckSsoFallback && (this.silentCheckSsoRedirectUri = void 0)), document.body.removeChild(e), window.removeEventListener("message", n), i())); }; window.addEventListener("message", n, !1); }); @@ -1021,12 +1021,12 @@ For more information see: https://www.keycloak.org/securing-apps/javascript-adap return; } const i = async (l) => { - const h = {}; - l || (h.prompt = "none"), e.locale && (h.locale = e.locale), await this.login(h); + const u = {}; + l || (u.prompt = "none"), e.locale && (u.locale = e.locale), await this.login(u); }, n = async () => { switch (e.onLoad) { case "check-sso": - u(this, b).enable ? (await d(this, s, te).call(this), await d(this, s, X).call(this) || (this.silentCheckSsoRedirectUri ? await d(this, s, le).call(this) : await i(!1))) : this.silentCheckSsoRedirectUri ? await d(this, s, le).call(this) : await i(!1); + h(this, y).enable ? (await d(this, s, te).call(this), await d(this, s, X).call(this) || (this.silentCheckSsoRedirectUri ? await d(this, s, le).call(this) : await i(!1))) : this.silentCheckSsoRedirectUri ? await d(this, s, le).call(this) : await i(!1); break; case "login-required": await i(!0); @@ -1036,7 +1036,7 @@ For more information see: https://www.keycloak.org/securing-apps/javascript-adap } }; if (e.token && e.refreshToken) - if (d(this, s, Z).call(this, e.token, e.refreshToken, e.idToken), u(this, b).enable) + if (d(this, s, Z).call(this, e.token, e.refreshToken, e.idToken), h(this, y).enable) await d(this, s, te).call(this), await d(this, s, X).call(this) && ((o = this.onAuthSuccess) == null || o.call(this), d(this, s, re).call(this)); else try { @@ -1049,37 +1049,37 @@ For more information see: https://www.keycloak.org/securing-apps/javascript-adap } else e.onLoad && await n(); }, te = async function() { - if (!u(this, b).enable || u(this, b).iframe) + if (!h(this, y).enable || h(this, y).iframe) return; const e = document.createElement("iframe"); - u(this, b).iframe = e, e.setAttribute("src", this.endpoints.checkSessionIframe()), e.setAttribute("sandbox", "allow-storage-access-by-user-activation allow-scripts allow-same-origin"), e.setAttribute("title", "keycloak-session-iframe"), e.style.display = "none", document.body.appendChild(e); + h(this, y).iframe = e, e.setAttribute("src", this.endpoints.checkSessionIframe()), e.setAttribute("sandbox", "allow-storage-access-by-user-activation allow-scripts allow-same-origin"), e.setAttribute("title", "keycloak-session-iframe"), e.style.display = "none", document.body.appendChild(e); const t = (n) => { var c; - if (n.origin !== u(this, b).iframeOrigin || ((c = u(this, b).iframe) == null ? void 0 : c.contentWindow) !== n.source || !(n.data === "unchanged" || n.data === "changed" || n.data === "error")) + if (n.origin !== h(this, y).iframeOrigin || ((c = h(this, y).iframe) == null ? void 0 : c.contentWindow) !== n.source || !(n.data === "unchanged" || n.data === "changed" || n.data === "error")) return; n.data !== "unchanged" && this.clearToken(); - const o = u(this, b).callbackList; - u(this, b).callbackList = []; + const o = h(this, y).callbackList; + h(this, y).callbackList = []; for (const a of o.reverse()) n.data === "error" ? a(new Error("Error while checking login iframe")) : a(null, n.data === "unchanged"); }; window.addEventListener("message", t, !1), await new Promise((n) => { e.addEventListener("load", () => { const o = this.endpoints.authorize(); - o.startsWith("/") ? u(this, b).iframeOrigin = globalThis.location.origin : u(this, b).iframeOrigin = new URL(o).origin, n(); + o.startsWith("/") ? h(this, y).iframeOrigin = globalThis.location.origin : h(this, y).iframeOrigin = new URL(o).origin, n(); }); }); }, X = async function() { - if (!u(this, b).iframe || !u(this, b).iframeOrigin) + if (!h(this, y).iframe || !h(this, y).iframeOrigin) return; - const e = `${this.clientId} ${this.sessionId ? this.sessionId : ""}`, t = u(this, b).iframeOrigin; + const e = `${this.clientId} ${this.sessionId ? this.sessionId : ""}`, t = h(this, y).iframeOrigin; return await new Promise((n, o) => { var a, l; - const c = (h, w) => h ? o(h) : n( + const c = (u, w) => u ? o(u) : n( /** @type {boolean} */ w ); - u(this, b).callbackList.push(c), u(this, b).callbackList.length === 1 && ((l = (a = u(this, b).iframe) == null ? void 0 : a.contentWindow) == null || l.postMessage(e, t)); + h(this, y).callbackList.push(c), h(this, y).callbackList.length === 1 && ((l = (a = h(this, y).iframe) == null ? void 0 : a.contentWindow) == null || l.postMessage(e, t)); }); }, le = async function() { const e = document.createElement("iframe"), t = await this.createLoginUrl({ prompt: "none", redirectUri: this.silentCheckSsoRedirectUri }); @@ -1104,7 +1104,7 @@ P = function(e) { const t = d(this, s, Re).call(this, e); if (!t) return; - const i = u(this, J).get(t.state); + const i = h(this, J).get(t.state); return i && (t.valid = !0, t.redirectUri = i.redirectUri, t.storedNonce = i.nonce, t.prompt = i.prompt, t.pkceCodeVerifier = i.pkceCodeVerifier, t.loginOptions = i.loginOptions), t; }, /** * @param {string} urlString @@ -1151,20 +1151,20 @@ de = function(e, t) { o = "&" + o; continue; } - const [l, h] = a; - t.includes(l) && !(l in n) ? n[l] = h : o = o.length === 0 ? c : c + "&" + o; + const [l, u] = a; + t.includes(l) && !(l in n) ? n[l] = u : o = o.length === 0 ? c : c + "&" + o; } return { paramsString: o, oauthParams: n }; }, z = async function(e) { - var a, l, h, w; + var a, l, u, w; const { code: t, error: i, prompt: n } = e; let o = (/* @__PURE__ */ new Date()).getTime(); - const c = (m, C, p) => { - if (o = (o + (/* @__PURE__ */ new Date()).getTime()) / 2, d(this, s, Z).call(this, m, C, p, o), u(this, $) && this.idTokenParsed && this.idTokenParsed.nonce !== e.storedNonce) - throw u(this, M).call(this, "[KEYCLOAK] Invalid nonce, clearing token"), this.clearToken(), new Error("Invalid nonce."); + const c = (m, T, p) => { + if (o = (o + (/* @__PURE__ */ new Date()).getTime()) / 2, d(this, s, Z).call(this, m, T, p, o), h(this, $) && this.idTokenParsed && this.idTokenParsed.nonce !== e.storedNonce) + throw h(this, M).call(this, "[KEYCLOAK] Invalid nonce, clearing token"), this.clearToken(), new Error("Invalid nonce."); }; if (e.kc_action_status && this.onActionUpdate && this.onActionUpdate(e.kc_action_status, e.kc_action), i) { if (n !== "none") @@ -1186,12 +1186,12 @@ de = function(e, t) { e.redirectUri, e.pkceCodeVerifier ); - c(m.access_token, m.refresh_token, m.id_token), this.flow === "standard" && ((h = this.onAuthSuccess) == null || h.call(this)), d(this, s, re).call(this); + c(m.access_token, m.refresh_token, m.id_token), this.flow === "standard" && ((u = this.onAuthSuccess) == null || u.call(this)), d(this, s, re).call(this); } catch (m) { throw (w = this.onAuthError) == null || w.call(this), m; } }, re = async function() { - u(this, b).enable && this.token && (await dt(u(this, b).interval * 1e3), await d(this, s, X).call(this) && await d(this, s, re).call(this)); + h(this, y).enable && this.token && (await dt(h(this, y).interval * 1e3), await d(this, s, X).call(this) && await d(this, s, re).call(this)); }, /** * @param {string} [token] * @param {string} [refreshToken] @@ -1200,9 +1200,9 @@ de = function(e, t) { */ Z = function(e, t, i, n) { if (this.tokenTimeoutHandle && (clearTimeout(this.tokenTimeoutHandle), this.tokenTimeoutHandle = void 0), t ? (this.refreshToken = t, this.refreshTokenParsed = ne(t)) : (delete this.refreshToken, delete this.refreshTokenParsed), i ? (this.idToken = i, this.idTokenParsed = ne(i)) : (delete this.idToken, delete this.idTokenParsed), e) { - if (this.token = e, this.tokenParsed = ne(e), this.sessionId = this.tokenParsed.sid, this.authenticated = !0, this.subject = this.tokenParsed.sub, this.realmAccess = this.tokenParsed.realm_access, this.resourceAccess = this.tokenParsed.resource_access, n && (this.timeSkew = Math.floor(n / 1e3) - this.tokenParsed.iat), this.timeSkew !== null && (u(this, M).call(this, "[KEYCLOAK] Estimated time difference between browser and server is " + this.timeSkew + " seconds"), this.onTokenExpired)) { + if (this.token = e, this.tokenParsed = ne(e), this.sessionId = this.tokenParsed.sid, this.authenticated = !0, this.subject = this.tokenParsed.sub, this.realmAccess = this.tokenParsed.realm_access, this.resourceAccess = this.tokenParsed.resource_access, n && (this.timeSkew = Math.floor(n / 1e3) - this.tokenParsed.iat), this.timeSkew !== null && (h(this, M).call(this, "[KEYCLOAK] Estimated time difference between browser and server is " + this.timeSkew + " seconds"), this.onTokenExpired)) { const o = (this.tokenParsed.exp - (/* @__PURE__ */ new Date()).getTime() / 1e3 + this.timeSkew) * 1e3; - u(this, M).call(this, "[KEYCLOAK] Token expires in " + Math.round(o / 1e3) + " s"), o <= 0 ? this.onTokenExpired() : this.tokenTimeoutHandle = window.setTimeout(this.onTokenExpired, o); + h(this, M).call(this, "[KEYCLOAK] Token expires in " + Math.round(o / 1e3) + " s"), o <= 0 ? this.onTokenExpired() : this.tokenTimeoutHandle = window.setTimeout(this.onTokenExpired, o); } } else delete this.token, delete this.tokenParsed, delete this.subject, delete this.realmAccess, delete this.resourceAccess, this.authenticated = !1; @@ -1211,7 +1211,7 @@ Z = function(e, t, i, n) { */ R = function() { if (!(typeof this.authServerUrl > "u")) - return `${Ue(this.authServerUrl)}/realms/${encodeURIComponent( + return `${Te(this.authServerUrl)}/realms/${encodeURIComponent( /** @type {string} */ this.realm )}`; @@ -1219,7 +1219,7 @@ R = function() { * @param {Function} fn * @returns {(message: string) => void} */ -he = function(e) { +ue = function(e) { return (t) => { this.enableLogging && e.call(console, t); }; @@ -1275,7 +1275,7 @@ function Xe() { } } const Y = "kc-callback-"; -var x, ue, Me, fe, De; +var x, he, Me, fe, De; class Ze { constructor() { A(this, x); @@ -1288,7 +1288,7 @@ class Ze { get(e) { if (!e) return null; - d(this, x, ue).call(this); + d(this, x, he).call(this); const t = Y + e, i = globalThis.localStorage.getItem(t); return i ? (globalThis.localStorage.removeItem(t), JSON.parse(i)) : null; } @@ -1296,7 +1296,7 @@ class Ze { * @param {CallbackState} state */ add(e) { - d(this, x, ue).call(this); + d(this, x, he).call(this); const t = Y + e.state, i = JSON.stringify({ ...e, // Set the expiry time to 1 hour from now. @@ -1312,7 +1312,7 @@ class Ze { x = new WeakSet(), /** * Clears all values from local storage that are no longer valid. */ -ue = function() { +he = function() { const e = Date.now(); for (const [t, i] of d(this, x, fe).call(this)) { const n = d(this, x, De).call(this, i); @@ -1344,7 +1344,7 @@ De = function(e) { } return me(t) && "expires" in t && typeof t.expires == "number" ? t.expires : null; }; -var D, Ne, pe, we; +var D, Ke, pe, we; class et { constructor() { A(this, D); @@ -1356,7 +1356,7 @@ class et { get(e) { if (!e) return null; - const t = d(this, D, Ne).call(this, Y + e); + const t = d(this, D, Ke).call(this, Y + e); return d(this, D, pe).call(this, Y + e, "", d(this, D, we).call(this, -100)), t ? JSON.parse(t) : null; } /** @@ -1370,7 +1370,7 @@ D = new WeakSet(), /** * @param {string} key * @returns */ -Ne = function(e) { +Ke = function(e) { const t = e + "=", i = document.cookie.split(";"); for (let n = 0; n < i.length; n++) { let o = i[n]; @@ -1492,7 +1492,7 @@ async function Q(r, e = {}) { async function lt(r, e) { const t = await fetch(r, e); if (!t.ok) - throw new Ke("Server responded with an invalid status.", { response: t }); + throw new Ne("Server responded with an invalid status.", { response: t }); return t; } function Ce(r) { @@ -1500,10 +1500,10 @@ function Ce(r) { throw new Error("Unable to build authorization header, token is not set, make sure the user is authenticated."); return ["Authorization", `bearer ${r}`]; } -function Ue(r) { +function Te(r) { return r.endsWith("/") ? r.slice(0, -1) : r; } -class Ke extends Error { +class Ne extends Error { /** * @param {string} message * @param {NetworkErrorOptions} options @@ -1515,13 +1515,13 @@ class Ke extends Error { this.response = i.response; } } -const dt = (r) => new Promise((e) => setTimeout(e, r)), ht = "https://auth.ibagher.ir", ut = "bi"; -let _ = null, se = null; -const Be = Oe(null), ft = (r) => (_ || (_ = new He({ - url: ht, - realm: ut, +const dt = (r) => new Promise((e) => setTimeout(e, r)), ut = "https://auth.ibagher.ir", ht = "bi"; +let b = null, se = null; +const Be = Oe(null), ft = (r) => (b || (b = new He({ + url: ut, + realm: ht, clientId: r -})), _), pt = ({ clientId: r, initOptions: e = {} }) => { +})), b), pt = ({ clientId: r, initOptions: e = {} }) => { const t = ft(r); return se || (se = t.init({ onLoad: "login-required", @@ -1529,26 +1529,26 @@ const Be = Oe(null), ft = (r) => (_ || (_ = new He({ flow: "implicit", ...e })), se; -}, Ut = ({ +}, Tt = () => !!(b != null && b.authenticated), Ut = () => (b == null ? void 0 : b.token) ?? null, _t = async (r = 30) => b ? b.updateToken(r) : !1, Et = (r) => b == null ? void 0 : b.logout(r), At = (r) => b == null ? void 0 : b.login(r), It = ({ children: r, clientId: e, initOptions: t, loading: i = null }) => { - const [n, o] = I(!1), [c, a] = I(!1), [l, h] = I(null), w = ie(!1), m = H(() => { - _ && (a(!!_.authenticated), h(_.token ?? null)); + const [n, o] = I(!1), [c, a] = I(!1), [l, u] = I(null), w = ie(!1), m = H(() => { + b && (a(!!b.authenticated), u(b.token ?? null)); }, []); - W(() => (w.current = !0, pt({ clientId: e, initOptions: t }).then((S) => { - w.current && (a(!!S), h((_ == null ? void 0 : _.token) ?? null), o(!0)); + W(() => (w.current = !0, pt({ clientId: e, initOptions: t }).then((C) => { + w.current && (a(!!C), u((b == null ? void 0 : b.token) ?? null), o(!0)); }).catch(() => { - w.current && (a(!1), h(null), o(!0)); + w.current && (a(!1), u(null), o(!0)); }), () => { w.current = !1; }), [e, t]); - const C = H(() => _ == null ? void 0 : _.login(), []), p = H((S) => _ == null ? void 0 : _.logout(S), []), k = H( - async (S = 30) => { - if (!_) return !1; - const V = await _.updateToken(S); + const T = H(() => b == null ? void 0 : b.login(), []), p = H((C) => b == null ? void 0 : b.logout(C), []), k = H( + async (C = 30) => { + if (!b) return !1; + const V = await b.updateToken(C); return m(), V; }, [m] @@ -1557,27 +1557,32 @@ const Be = Oe(null), ft = (r) => (_ || (_ = new He({ initialized: n, authenticated: c, token: l, - login: C, + login: T, logout: p, updateToken: k }), - [n, c, l, C, p, k] + [n, c, l, T, p, k] ); - return n ? /* @__PURE__ */ v(Be.Provider, { value: g, children: r }) : i; -}, _t = () => { + return n ? /* @__PURE__ */ S(Be.Provider, { value: g, children: r }) : i; +}, xt = () => { const r = Fe(Be); if (!r) throw new Error("useKeycloak must be used inside KeycloakProvider"); return r; }; export { - Ut as KeycloakProvider, + It as KeycloakProvider, vt as LightPagination, St as Pagination, Ct as SimplePagination, + Ut as getKeycloakToken, pt as initKeycloak, + Tt as isKeycloakAuthenticated, + At as loginKeycloak, + Et as logoutKeycloak, F as toEnDigits, - y as toFaDigits, + v as toFaDigits, yt as toFaNumber, - _t as useKeycloak + _t as updateKeycloakToken, + xt as useKeycloak }; diff --git a/src/core/keycloak.jsx b/src/core/keycloak.jsx index 7169b47..650543c 100644 --- a/src/core/keycloak.jsx +++ b/src/core/keycloak.jsx @@ -44,6 +44,28 @@ export const initKeycloak = ({ clientId, initOptions = {} }) => { return initPromise; }; +export const isKeycloakAuthenticated = () => { + return Boolean(keycloakInstance?.authenticated); +}; + +export const getKeycloakToken = () => { + return keycloakInstance?.token ?? null; +}; + +export const updateKeycloakToken = async (minValidity = 30) => { + if (!keycloakInstance) return false; + + return keycloakInstance.updateToken(minValidity); +}; + +export const logoutKeycloak = (options) => { + return keycloakInstance?.logout(options); +}; + +export const loginKeycloak = (options) => { + return keycloakInstance?.login(options); +}; + export const KeycloakProvider = ({ children, clientId, @@ -136,4 +158,4 @@ export const useKeycloak = () => { } return context; -}; \ No newline at end of file +}; diff --git a/src/index.js b/src/index.js index a96a43b..d3fa8dc 100644 --- a/src/index.js +++ b/src/index.js @@ -8,4 +8,9 @@ export { KeycloakProvider, useKeycloak, initKeycloak, -} from "./core/keycloak.jsx"; \ No newline at end of file + isKeycloakAuthenticated, + getKeycloakToken, + updateKeycloakToken, + logoutKeycloak, + loginKeycloak, +} from "./core/keycloak.jsx";