update keycloak
This commit is contained in:
parent
7f947d5cd8
commit
0a65628ec3
158
dist/index.js
vendored
158
dist/index.js
vendored
@ -5,11 +5,11 @@ var Se = (r) => {
|
|||||||
var je = (r, e, t) => e in r ? Pe(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
var je = (r, e, t) => e in r ? Pe(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) || Se("Cannot " + t);
|
var f = (r, e, t) => je(r, typeof e != "symbol" ? e + "" : e, t), oe = (r, e, t) => e.has(r) || Se("Cannot " + t);
|
||||||
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) ? Se("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);
|
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) ? Se("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 { jsxs as W, 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 } from "react";
|
import { useState as I, useRef as ie, useEffect as O, useCallback as H, createContext as We, useMemo as Oe } from "react";
|
||||||
import { HStack as N, IconButton as G, Button as ke, Input as be, Text as j } from "@chakra-ui/react";
|
import { HStack as K, IconButton as G, Button as ke, Input as be, Text as j } from "@chakra-ui/react";
|
||||||
import { IoChevronForwardOutline as ye, IoChevronBackOutline as ve } from "react-icons/io5";
|
import { IoChevronForwardOutline as ye, IoChevronBackOutline as ve } from "react-icons/io5";
|
||||||
const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => String(r).replace(/\d/g, (e) => "۰۱۲۳۴۵۶۷۸۹"[Number(e)]), V = (r) => String(r).replace(/[۰-۹]/g, (t) => String("۰۱۲۳۴۵۶۷۸۹".indexOf(t))), vt = ({
|
const kt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => String(r).replace(/\d/g, (e) => "۰۱۲۳۴۵۶۷۸۹"[Number(e)]), V = (r) => String(r).replace(/[۰-۹]/g, (t) => String("۰۱۲۳۴۵۶۷۸۹".indexOf(t))), bt = ({
|
||||||
currentPage: r,
|
currentPage: r,
|
||||||
totalPages: e,
|
totalPages: e,
|
||||||
totalCount: t,
|
totalCount: t,
|
||||||
@ -18,13 +18,13 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => S
|
|||||||
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(
|
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
|
(p) => p >= 1 && p <= e
|
||||||
);
|
);
|
||||||
W(() => {
|
O(() => {
|
||||||
if (l !== null) {
|
if (l !== null) {
|
||||||
r === l && (u(null), a(!1), o(v(r)));
|
r === l && (u(null), a(!1), o(v(r)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
c || o(v(r));
|
c || o(v(r));
|
||||||
}, [r, c, l]), W(() => {
|
}, [r, c, l]), O(() => {
|
||||||
if (!c || !n || l !== null) return;
|
if (!c || !n || l !== null) return;
|
||||||
const p = parseInt(V(n), 10);
|
const p = parseInt(V(n), 10);
|
||||||
if (isNaN(p)) return;
|
if (isNaN(p)) return;
|
||||||
@ -52,8 +52,8 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => S
|
|||||||
const k = Math.min(Math.max(p, 1), e);
|
const k = Math.min(Math.max(p, 1), e);
|
||||||
k !== r ? (u(k), o(v(k)), i(k)) : (o(v(r)), a(!1), u(null)), (C = w.current) == null || C.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(
|
return e === 0 || !t ? null : /* @__PURE__ */ W(
|
||||||
N,
|
K,
|
||||||
{
|
{
|
||||||
justifyContent: "space-around",
|
justifyContent: "space-around",
|
||||||
backgroundColor: "white",
|
backgroundColor: "white",
|
||||||
@ -64,7 +64,7 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => S
|
|||||||
borderColor: "blue.200",
|
borderColor: "blue.200",
|
||||||
w: "100%",
|
w: "100%",
|
||||||
children: [
|
children: [
|
||||||
/* @__PURE__ */ O(N, { spacing: 2, alignItems: "center", justifyContent: "center", children: [
|
/* @__PURE__ */ W(K, { spacing: 2, alignItems: "center", justifyContent: "center", children: [
|
||||||
/* @__PURE__ */ S(
|
/* @__PURE__ */ S(
|
||||||
G,
|
G,
|
||||||
{
|
{
|
||||||
@ -135,14 +135,14 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => S
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
] }),
|
] }),
|
||||||
/* @__PURE__ */ O(N, { spacing: 2, children: [
|
/* @__PURE__ */ W(K, { spacing: 2, children: [
|
||||||
/* @__PURE__ */ S(j, { w: "auto", fontWeight: "bold", whiteSpace: "nowrap", children: "تعداد کل:" }),
|
/* @__PURE__ */ S(j, { w: "auto", fontWeight: "bold", whiteSpace: "nowrap", children: "تعداد کل:" }),
|
||||||
/* @__PURE__ */ S(j, { children: v(t) })
|
/* @__PURE__ */ S(j, { children: v(t) })
|
||||||
] })
|
] })
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}, St = ({
|
}, yt = ({
|
||||||
currentPage: r,
|
currentPage: r,
|
||||||
totalPages: e,
|
totalPages: e,
|
||||||
totalCount: t,
|
totalCount: t,
|
||||||
@ -151,13 +151,13 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => S
|
|||||||
const [n, o] = I(v(r)), [c, a] = I(!1), [l, u] = 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])
|
/* @__PURE__ */ new Set([1, r, r + 1, e])
|
||||||
).filter((p) => p >= 1 && p <= e).sort((p, k) => p - k);
|
).filter((p) => p >= 1 && p <= e).sort((p, k) => p - k);
|
||||||
W(() => {
|
O(() => {
|
||||||
if (l !== null) {
|
if (l !== null) {
|
||||||
r === l && (u(null), a(!1), o(v(r)));
|
r === l && (u(null), a(!1), o(v(r)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
c || o(v(r));
|
c || o(v(r));
|
||||||
}, [r, c, l]), W(() => {
|
}, [r, c, l]), O(() => {
|
||||||
if (!c || !n || l !== null) return;
|
if (!c || !n || l !== null) return;
|
||||||
const p = parseInt(V(n), 10);
|
const p = parseInt(V(n), 10);
|
||||||
if (isNaN(p)) return;
|
if (isNaN(p)) return;
|
||||||
@ -185,8 +185,8 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => S
|
|||||||
const k = Math.min(Math.max(p, 1), e);
|
const k = Math.min(Math.max(p, 1), e);
|
||||||
k !== r ? (u(k), o(v(k)), i(k)) : (o(v(r)), a(!1), u(null)), (C = w.current) == null || C.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(
|
return e === 0 || !t ? null : /* @__PURE__ */ W(
|
||||||
N,
|
K,
|
||||||
{
|
{
|
||||||
justifyContent: "space-around",
|
justifyContent: "space-around",
|
||||||
backgroundColor: "white",
|
backgroundColor: "white",
|
||||||
@ -197,13 +197,13 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => S
|
|||||||
borderColor: "blue.200",
|
borderColor: "blue.200",
|
||||||
w: "100%",
|
w: "100%",
|
||||||
children: [
|
children: [
|
||||||
/* @__PURE__ */ O(N, { spacing: 2, whiteSpace: "nowrap", children: [
|
/* @__PURE__ */ W(K, { spacing: 2, whiteSpace: "nowrap", children: [
|
||||||
/* @__PURE__ */ S(j, { fontWeight: "bold", children: "صفحه" }),
|
/* @__PURE__ */ S(j, { fontWeight: "bold", children: "صفحه" }),
|
||||||
/* @__PURE__ */ S(j, { children: v(r) }),
|
/* @__PURE__ */ S(j, { children: v(r) }),
|
||||||
/* @__PURE__ */ S(j, { fontWeight: "bold", children: "از" }),
|
/* @__PURE__ */ S(j, { fontWeight: "bold", children: "از" }),
|
||||||
/* @__PURE__ */ S(j, { children: v(e) })
|
/* @__PURE__ */ S(j, { children: v(e) })
|
||||||
] }),
|
] }),
|
||||||
/* @__PURE__ */ O(N, { spacing: 2, alignItems: "center", justifyContent: "center", children: [
|
/* @__PURE__ */ W(K, { spacing: 2, alignItems: "center", justifyContent: "center", children: [
|
||||||
/* @__PURE__ */ S(
|
/* @__PURE__ */ S(
|
||||||
G,
|
G,
|
||||||
{
|
{
|
||||||
@ -273,14 +273,14 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => S
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
] }),
|
] }),
|
||||||
/* @__PURE__ */ O(N, { spacing: 2, whiteSpace: "nowrap", children: [
|
/* @__PURE__ */ W(K, { spacing: 2, whiteSpace: "nowrap", children: [
|
||||||
/* @__PURE__ */ S(j, { fontWeight: "bold", children: "تعداد کل:" }),
|
/* @__PURE__ */ S(j, { fontWeight: "bold", children: "تعداد کل:" }),
|
||||||
/* @__PURE__ */ S(j, { children: v(t) })
|
/* @__PURE__ */ S(j, { children: v(t) })
|
||||||
] })
|
] })
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}, Ct = ({
|
}, vt = ({
|
||||||
currentPage: r,
|
currentPage: r,
|
||||||
totalPages: e,
|
totalPages: e,
|
||||||
totalCount: t,
|
totalCount: t,
|
||||||
@ -305,12 +305,12 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => S
|
|||||||
const E = Math.min(Math.max(U, 1), e);
|
const E = Math.min(Math.max(U, 1), e);
|
||||||
a(!1), o(""), E !== r ? (u(E), i(E)) : u(null);
|
a(!1), o(""), E !== r ? (u(E), i(E)) : u(null);
|
||||||
}, [n, r, e, i]);
|
}, [n, r, e, i]);
|
||||||
W(() => {
|
O(() => {
|
||||||
var U;
|
var U;
|
||||||
c && ((U = w.current) == null || U.focus());
|
c && ((U = w.current) == null || U.focus());
|
||||||
}, [c]), W(() => {
|
}, [c]), O(() => {
|
||||||
l !== null && r === l && u(null);
|
l !== null && r === l && u(null);
|
||||||
}, [r, l]), W(() => {
|
}, [r, l]), O(() => {
|
||||||
if (!c || !n) return;
|
if (!c || !n) return;
|
||||||
const U = setTimeout(() => {
|
const U = setTimeout(() => {
|
||||||
p();
|
p();
|
||||||
@ -335,7 +335,7 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => S
|
|||||||
if (e === 0 || !t) return null;
|
if (e === 0 || !t) return null;
|
||||||
const C = e > 1 && m !== 1, F = e > 1 && m !== e;
|
const C = e > 1 && m !== 1, F = e > 1 && m !== e;
|
||||||
return /* @__PURE__ */ S(
|
return /* @__PURE__ */ S(
|
||||||
N,
|
K,
|
||||||
{
|
{
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
backgroundColor: "white",
|
backgroundColor: "white",
|
||||||
@ -345,7 +345,7 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => S
|
|||||||
border: "1px",
|
border: "1px",
|
||||||
borderColor: "blue.200",
|
borderColor: "blue.200",
|
||||||
w: "100%",
|
w: "100%",
|
||||||
children: /* @__PURE__ */ O(N, { spacing: 2, alignItems: "center", justifyContent: "center", children: [
|
children: /* @__PURE__ */ W(K, { spacing: 2, alignItems: "center", justifyContent: "center", children: [
|
||||||
/* @__PURE__ */ S(
|
/* @__PURE__ */ S(
|
||||||
G,
|
G,
|
||||||
{
|
{
|
||||||
@ -404,7 +404,7 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => S
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}, Ve = "application/json";
|
}, Ve = "application/json";
|
||||||
var K, _, $, J, M, q, y, L, s, ee, _e, Ee, Ae, Ie, ae, xe, ce, Le, Re, te, X, le, z, Me, de, P, re, Z, R, ue;
|
var N, _, J, Y, M, q, y, L, s, ee, _e, Ee, Ae, Ie, ae, xe, ce, Le, Re, te, X, le, z, Me, de, P, re, Z, R, ue;
|
||||||
class Fe {
|
class Fe {
|
||||||
/**
|
/**
|
||||||
* @param {KeycloakConfig} config
|
* @param {KeycloakConfig} config
|
||||||
@ -412,13 +412,13 @@ class Fe {
|
|||||||
constructor(e) {
|
constructor(e) {
|
||||||
A(this, s);
|
A(this, s);
|
||||||
/** @type {Pick<PromiseWithResolvers<boolean>, 'resolve' | 'reject'>[]} */
|
/** @type {Pick<PromiseWithResolvers<boolean>, 'resolve' | 'reject'>[]} */
|
||||||
A(this, K, []);
|
A(this, N, []);
|
||||||
/** @type {KeycloakAdapter} */
|
/** @type {KeycloakAdapter} */
|
||||||
A(this, _);
|
A(this, _);
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
A(this, $, !0);
|
A(this, J, !0);
|
||||||
/** @type {CallbackStorage} */
|
/** @type {CallbackStorage} */
|
||||||
A(this, J);
|
A(this, Y);
|
||||||
A(this, M, d(this, s, ue).call(this, console.info));
|
A(this, M, d(this, s, ue).call(this, console.info));
|
||||||
A(this, q, d(this, s, ue).call(this, console.warn));
|
A(this, q, d(this, s, ue).call(this, console.warn));
|
||||||
/** @type {LoginIframe} */
|
/** @type {LoginIframe} */
|
||||||
@ -512,9 +512,9 @@ class Fe {
|
|||||||
var i;
|
var i;
|
||||||
if (this.didInitialize)
|
if (this.didInitialize)
|
||||||
throw new Error("A 'Keycloak' instance can only be initialized once.");
|
throw new Error("A 'Keycloak' instance can only be initialized once.");
|
||||||
this.didInitialize = !0, B(this, J, Qe());
|
this.didInitialize = !0, B(this, Y, Qe());
|
||||||
const t = ["default", "cordova", "cordova-native"];
|
const t = ["default", "cordova", "cordova-native"];
|
||||||
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 (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, J, 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")
|
if (e.responseMode === "query" || e.responseMode === "fragment")
|
||||||
this.responseMode = e.responseMode;
|
this.responseMode = e.responseMode;
|
||||||
else
|
else
|
||||||
@ -575,14 +575,14 @@ class Fe {
|
|||||||
["response_type", this.responseType],
|
["response_type", this.responseType],
|
||||||
["scope", a]
|
["scope", a]
|
||||||
]);
|
]);
|
||||||
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", He(e.acr)), e != null && e.acrValues && u.append("acr_values", e.acrValues), this.pkceMethod)
|
if (h(this, J) && 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", He(e.acr)), e != null && e.acrValues && u.append("acr_values", e.acrValues), this.pkceMethod)
|
||||||
try {
|
try {
|
||||||
const w = Ye(96), m = await $e(this.pkceMethod, w);
|
const w = $e(96), m = await Je(this.pkceMethod, w);
|
||||||
o.pkceCodeVerifier = w, u.append("code_challenge", m), u.append("code_challenge_method", this.pkceMethod);
|
o.pkceCodeVerifier = w, u.append("code_challenge", m), u.append("code_challenge_method", this.pkceMethod);
|
||||||
} catch (w) {
|
} catch (w) {
|
||||||
throw new Error("Failed to generate PKCE challenge.", { cause: w });
|
throw new Error("Failed to generate PKCE challenge.", { cause: w });
|
||||||
}
|
}
|
||||||
return h(this, J).add(o), `${c}?${u.toString()}`;
|
return h(this, Y).add(o), `${c}?${u.toString()}`;
|
||||||
});
|
});
|
||||||
/**
|
/**
|
||||||
* @param {KeycloakLogoutOptions} [options]
|
* @param {KeycloakLogoutOptions} [options]
|
||||||
@ -712,7 +712,7 @@ class Fe {
|
|||||||
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)
|
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;
|
return !1;
|
||||||
const { promise: i, resolve: n, reject: o } = Promise.withResolvers();
|
const { promise: i, resolve: n, reject: o } = Promise.withResolvers();
|
||||||
if (h(this, K).push({ resolve: n, reject: o }), h(this, K).length === 1) {
|
if (h(this, N).push({ resolve: n, reject: o }), h(this, N).length === 1) {
|
||||||
const l = this.endpoints.token();
|
const l = this.endpoints.token();
|
||||||
let u = (/* @__PURE__ */ new Date()).getTime();
|
let u = (/* @__PURE__ */ new Date()).getTime();
|
||||||
try {
|
try {
|
||||||
@ -723,11 +723,11 @@ class Fe {
|
|||||||
this.clientId
|
this.clientId
|
||||||
);
|
);
|
||||||
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);
|
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())
|
for (let m = h(this, N).pop(); m != null; m = h(this, N).pop())
|
||||||
m.resolve(!0);
|
m.resolve(!0);
|
||||||
} catch (w) {
|
} catch (w) {
|
||||||
h(this, q).call(this, "[KEYCLOAK] Failed to refresh token"), w instanceof Be && w.response.status === 400 && this.clearToken(), (a = this.onAuthRefreshError) == null || a.call(this);
|
h(this, q).call(this, "[KEYCLOAK] Failed to refresh token"), w instanceof Be && 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())
|
for (let m = h(this, N).pop(); m != null; m = h(this, N).pop())
|
||||||
m.reject(w);
|
m.reject(w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -751,7 +751,7 @@ Continuing to run your application insecurely will lead to unexpected behavior a
|
|||||||
For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts`), B(this, L, e);
|
For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts`), B(this, L, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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(), /**
|
N = new WeakMap(), _ = new WeakMap(), J = new WeakMap(), Y = new WeakMap(), M = new WeakMap(), q = new WeakMap(), y = new WeakMap(), L = new WeakMap(), s = new WeakSet(), /**
|
||||||
* @param {"default" | "cordova" | "cordova-native"} type
|
* @param {"default" | "cordova" | "cordova-native"} type
|
||||||
* @returns {KeycloakAdapter}
|
* @returns {KeycloakAdapter}
|
||||||
*/
|
*/
|
||||||
@ -1104,7 +1104,7 @@ z = function(e) {
|
|||||||
const t = d(this, s, Me).call(this, e);
|
const t = d(this, s, Me).call(this, e);
|
||||||
if (!t)
|
if (!t)
|
||||||
return;
|
return;
|
||||||
const i = h(this, J).get(t.state);
|
const i = h(this, Y).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;
|
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
|
* @param {string} urlString
|
||||||
@ -1163,7 +1163,7 @@ de = function(e, t) {
|
|||||||
const { code: t, error: i, prompt: n } = e;
|
const { code: t, error: i, prompt: n } = e;
|
||||||
let o = (/* @__PURE__ */ new Date()).getTime();
|
let o = (/* @__PURE__ */ new Date()).getTime();
|
||||||
const c = (m, T, p) => {
|
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)
|
if (o = (o + (/* @__PURE__ */ new Date()).getTime()) / 2, d(this, s, Z).call(this, m, T, p, o), h(this, J) && this.idTokenParsed && this.idTokenParsed.nonce !== e.storedNonce)
|
||||||
throw h(this, M).call(this, "[KEYCLOAK] Invalid nonce, clearing token"), this.clearToken(), new Error("Invalid nonce.");
|
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 (e.kc_action_status && this.onActionUpdate && this.onActionUpdate(e.kc_action_status, e.kc_action), i) {
|
||||||
@ -1236,16 +1236,16 @@ function He(r) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function Ye(r) {
|
function $e(r) {
|
||||||
return Je(r, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
|
return Ye(r, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
|
||||||
}
|
}
|
||||||
async function $e(r, e) {
|
async function Je(r, e) {
|
||||||
if (r !== "S256")
|
if (r !== "S256")
|
||||||
throw new TypeError(`Invalid value for 'pkceMethod', expected 'S256' but got '${r}'.`);
|
throw new TypeError(`Invalid value for 'pkceMethod', expected 'S256' but got '${r}'.`);
|
||||||
const t = new Uint8Array(await tt(e));
|
const t = new Uint8Array(await tt(e));
|
||||||
return et(t).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
return et(t).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
||||||
}
|
}
|
||||||
function Je(r, e) {
|
function Ye(r, e) {
|
||||||
const t = qe(r), i = new Array(r);
|
const t = qe(r), i = new Array(r);
|
||||||
for (let n = 0; n < r; n++)
|
for (let n = 0; n < r; n++)
|
||||||
i[n] = e.charCodeAt(t[n] % e.length);
|
i[n] = e.charCodeAt(t[n] % e.length);
|
||||||
@ -1274,8 +1274,8 @@ function Qe() {
|
|||||||
return new Ze();
|
return new Ze();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const Y = "kc-callback-";
|
const $ = "kc-callback-";
|
||||||
var x, he, De, fe, Ke;
|
var x, he, De, fe, Ne;
|
||||||
class Xe {
|
class Xe {
|
||||||
constructor() {
|
constructor() {
|
||||||
A(this, x);
|
A(this, x);
|
||||||
@ -1289,7 +1289,7 @@ class Xe {
|
|||||||
if (!e)
|
if (!e)
|
||||||
return null;
|
return null;
|
||||||
d(this, x, he).call(this);
|
d(this, x, he).call(this);
|
||||||
const t = Y + e, i = globalThis.localStorage.getItem(t);
|
const t = $ + e, i = globalThis.localStorage.getItem(t);
|
||||||
return i ? (globalThis.localStorage.removeItem(t), JSON.parse(i)) : null;
|
return i ? (globalThis.localStorage.removeItem(t), JSON.parse(i)) : null;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -1297,7 +1297,7 @@ class Xe {
|
|||||||
*/
|
*/
|
||||||
add(e) {
|
add(e) {
|
||||||
d(this, x, he).call(this);
|
d(this, x, he).call(this);
|
||||||
const t = Y + e.state, i = JSON.stringify({
|
const t = $ + e.state, i = JSON.stringify({
|
||||||
...e,
|
...e,
|
||||||
// Set the expiry time to 1 hour from now.
|
// Set the expiry time to 1 hour from now.
|
||||||
expires: Date.now() + 60 * 60 * 1e3
|
expires: Date.now() + 60 * 60 * 1e3
|
||||||
@ -1315,7 +1315,7 @@ x = new WeakSet(), /**
|
|||||||
he = function() {
|
he = function() {
|
||||||
const e = Date.now();
|
const e = Date.now();
|
||||||
for (const [t, i] of d(this, x, fe).call(this)) {
|
for (const [t, i] of d(this, x, fe).call(this)) {
|
||||||
const n = d(this, x, Ke).call(this, i);
|
const n = d(this, x, Ne).call(this, i);
|
||||||
(n === null || n < e) && globalThis.localStorage.removeItem(t);
|
(n === null || n < e) && globalThis.localStorage.removeItem(t);
|
||||||
}
|
}
|
||||||
}, /**
|
}, /**
|
||||||
@ -1329,13 +1329,13 @@ De = function() {
|
|||||||
* @returns {[string, string][]} An array of key-value pairs.
|
* @returns {[string, string][]} An array of key-value pairs.
|
||||||
*/
|
*/
|
||||||
fe = function() {
|
fe = function() {
|
||||||
return Object.entries(globalThis.localStorage).filter(([e]) => e.startsWith(Y));
|
return Object.entries(globalThis.localStorage).filter(([e]) => e.startsWith($));
|
||||||
}, /**
|
}, /**
|
||||||
* Parses the expiry time from a value stored in local storage.
|
* Parses the expiry time from a value stored in local storage.
|
||||||
* @param {string} value
|
* @param {string} value
|
||||||
* @returns {number | null} The expiry time in milliseconds, or `null` if the value is malformed.
|
* @returns {number | null} The expiry time in milliseconds, or `null` if the value is malformed.
|
||||||
*/
|
*/
|
||||||
Ke = function(e) {
|
Ne = function(e) {
|
||||||
let t;
|
let t;
|
||||||
try {
|
try {
|
||||||
t = JSON.parse(e);
|
t = JSON.parse(e);
|
||||||
@ -1344,7 +1344,7 @@ Ke = function(e) {
|
|||||||
}
|
}
|
||||||
return me(t) && "expires" in t && typeof t.expires == "number" ? t.expires : null;
|
return me(t) && "expires" in t && typeof t.expires == "number" ? t.expires : null;
|
||||||
};
|
};
|
||||||
var D, Ne, pe, we;
|
var D, Ke, pe, we;
|
||||||
class Ze {
|
class Ze {
|
||||||
constructor() {
|
constructor() {
|
||||||
A(this, D);
|
A(this, D);
|
||||||
@ -1356,21 +1356,21 @@ class Ze {
|
|||||||
get(e) {
|
get(e) {
|
||||||
if (!e)
|
if (!e)
|
||||||
return null;
|
return null;
|
||||||
const t = d(this, D, Ne).call(this, Y + e);
|
const t = d(this, D, Ke).call(this, $ + e);
|
||||||
return d(this, D, pe).call(this, Y + e, "", d(this, D, we).call(this, -100)), t ? JSON.parse(t) : null;
|
return d(this, D, pe).call(this, $ + e, "", d(this, D, we).call(this, -100)), t ? JSON.parse(t) : null;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param {CallbackState} state
|
* @param {CallbackState} state
|
||||||
*/
|
*/
|
||||||
add(e) {
|
add(e) {
|
||||||
d(this, D, pe).call(this, Y + e.state, JSON.stringify(e), d(this, D, we).call(this, 60));
|
d(this, D, pe).call(this, $ + e.state, JSON.stringify(e), d(this, D, we).call(this, 60));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
D = new WeakSet(), /**
|
D = new WeakSet(), /**
|
||||||
* @param {string} key
|
* @param {string} key
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
Ne = function(e) {
|
Ke = function(e) {
|
||||||
const t = e + "=", i = document.cookie.split(";");
|
const t = e + "=", i = document.cookie.split(";");
|
||||||
for (let n = 0; n < i.length; n++) {
|
for (let n = 0; n < i.length; n++) {
|
||||||
let o = i[n];
|
let o = i[n];
|
||||||
@ -1515,14 +1515,14 @@ class Be extends Error {
|
|||||||
this.response = i.response;
|
this.response = i.response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const lt = (r) => new Promise((e) => setTimeout(e, r)), dt = "https://auth.ibagher.ir", ut = "bi";
|
const lt = (r) => new Promise((e) => setTimeout(e, r));
|
||||||
let b = null, se = null, ge = !1;
|
let b = null, se = null, ge = !1;
|
||||||
const ht = Oe(null), ft = (r) => (b || (b = new Fe({
|
const dt = We(null), ut = ({ url: r, realm: e, clientId: t }) => (b || (b = new Fe({
|
||||||
url: dt,
|
url: r,
|
||||||
realm: ut,
|
realm: e,
|
||||||
clientId: r
|
clientId: t
|
||||||
})), b), pt = ({ clientId: r, initOptions: e = {} }) => {
|
})), b), ht = ({ config: r, initOptions: e = {} }) => {
|
||||||
const t = ft(r);
|
const t = ut(r);
|
||||||
return se || (se = t.init({
|
return se || (se = t.init({
|
||||||
onLoad: "login-required",
|
onLoad: "login-required",
|
||||||
checkLoginIframe: !1,
|
checkLoginIframe: !1,
|
||||||
@ -1531,16 +1531,16 @@ const ht = Oe(null), ft = (r) => (b || (b = new Fe({
|
|||||||
}).then((i) => (ge = !0, i)).catch((i) => {
|
}).then((i) => (ge = !0, i)).catch((i) => {
|
||||||
throw ge = !0, i;
|
throw ge = !0, i;
|
||||||
})), se;
|
})), se;
|
||||||
}, Tt = () => ge, Ut = () => !!(b != null && b.authenticated), _t = () => (b == null ? void 0 : b.token) ?? null, Et = async (r = 30) => b ? b.updateToken(r) : !1, At = (r) => b == null ? void 0 : b.logout(r), It = (r) => b == null ? void 0 : b.login(r), xt = ({
|
}, St = () => ge, Ct = () => !!(b != null && b.authenticated), Tt = () => (b == null ? void 0 : b.token) ?? null, Ut = async (r = 30) => b ? b.updateToken(r) : !1, _t = (r) => b == null ? void 0 : b.logout(r), Et = (r) => b == null ? void 0 : b.login(r), At = ({
|
||||||
children: r,
|
children: r,
|
||||||
clientId: e,
|
config: e,
|
||||||
initOptions: t,
|
initOptions: t,
|
||||||
loading: i = null
|
loading: i = null
|
||||||
}) => {
|
}) => {
|
||||||
const [n, o] = I(!1), [c, a] = I(!1), [l, u] = I(null), w = ie(!1), m = H(() => {
|
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));
|
b && (a(!!b.authenticated), u(b.token ?? null));
|
||||||
}, []);
|
}, []);
|
||||||
W(() => (w.current = !0, pt({ clientId: e, initOptions: t }).then((C) => {
|
O(() => (w.current = !0, ht({ config: e, initOptions: t }).then((C) => {
|
||||||
w.current && (a(!!C), u((b == null ? void 0 : b.token) ?? null), o(!0));
|
w.current && (a(!!C), u((b == null ? void 0 : b.token) ?? null), o(!0));
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
w.current && (a(!1), u(null), o(!0));
|
w.current && (a(!1), u(null), o(!0));
|
||||||
@ -1554,7 +1554,7 @@ const ht = Oe(null), ft = (r) => (b || (b = new Fe({
|
|||||||
return m(), F;
|
return m(), F;
|
||||||
},
|
},
|
||||||
[m]
|
[m]
|
||||||
), g = We(
|
), g = Oe(
|
||||||
() => ({
|
() => ({
|
||||||
initialized: n,
|
initialized: n,
|
||||||
authenticated: c,
|
authenticated: c,
|
||||||
@ -1565,21 +1565,21 @@ const ht = Oe(null), ft = (r) => (b || (b = new Fe({
|
|||||||
}),
|
}),
|
||||||
[n, c, l, T, p, k]
|
[n, c, l, T, p, k]
|
||||||
);
|
);
|
||||||
return n ? /* @__PURE__ */ S(ht.Provider, { value: g, children: r }) : i;
|
return n ? /* @__PURE__ */ S(dt.Provider, { value: g, children: r }) : i;
|
||||||
};
|
};
|
||||||
export {
|
export {
|
||||||
xt as KeycloakProvider,
|
At as KeycloakProvider,
|
||||||
vt as LightPagination,
|
bt as LightPagination,
|
||||||
St as Pagination,
|
yt as Pagination,
|
||||||
Ct as SimplePagination,
|
vt as SimplePagination,
|
||||||
_t as getKeycloakToken,
|
Tt as getKeycloakToken,
|
||||||
pt as initKeycloak,
|
ht as initKeycloak,
|
||||||
Ut as isKeycloakAuthenticated,
|
Ct as isKeycloakAuthenticated,
|
||||||
Tt as isKeycloakInitialized,
|
St as isKeycloakInitialized,
|
||||||
It as loginKeycloak,
|
Et as loginKeycloak,
|
||||||
At as logoutKeycloak,
|
_t as logoutKeycloak,
|
||||||
V as toEnDigits,
|
V as toEnDigits,
|
||||||
v as toFaDigits,
|
v as toFaDigits,
|
||||||
yt as toFaNumber,
|
kt as toFaNumber,
|
||||||
Et as updateKeycloakToken
|
Ut as updateKeycloakToken
|
||||||
};
|
};
|
||||||
|
|||||||
@ -9,28 +9,25 @@ import {
|
|||||||
useState,
|
useState,
|
||||||
} from "react";
|
} from "react";
|
||||||
|
|
||||||
const KEYCLOAK_URL = "https://auth.ibagher.ir";
|
|
||||||
const KEYCLOAK_REALM = "bi";
|
|
||||||
|
|
||||||
let keycloakInstance = null;
|
let keycloakInstance = null;
|
||||||
let initPromise = null;
|
let initPromise = null;
|
||||||
let initializedValue = false;
|
let initializedValue = false;
|
||||||
|
|
||||||
const KeycloakContext = createContext(null);
|
const KeycloakContext = createContext(null);
|
||||||
|
|
||||||
const createKeycloak = (clientId) => {
|
const createKeycloak = ({ url, realm, clientId }) => {
|
||||||
if (!keycloakInstance) {
|
if (!keycloakInstance) {
|
||||||
keycloakInstance = new Keycloak({
|
keycloakInstance = new Keycloak({
|
||||||
url: KEYCLOAK_URL,
|
url,
|
||||||
realm: KEYCLOAK_REALM,
|
realm,
|
||||||
clientId,
|
clientId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return keycloakInstance;
|
return keycloakInstance;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initKeycloak = ({ clientId, initOptions = {} }) => {
|
export const initKeycloak = ({ config, initOptions = {} }) => {
|
||||||
const keycloak = createKeycloak(clientId);
|
const keycloak = createKeycloak(config);
|
||||||
if (!initPromise) {
|
if (!initPromise) {
|
||||||
initPromise = keycloak
|
initPromise = keycloak
|
||||||
.init({
|
.init({
|
||||||
@ -79,7 +76,7 @@ export const loginKeycloak = (options) => {
|
|||||||
|
|
||||||
export const KeycloakProvider = ({
|
export const KeycloakProvider = ({
|
||||||
children,
|
children,
|
||||||
clientId,
|
config,
|
||||||
initOptions,
|
initOptions,
|
||||||
loading = null,
|
loading = null,
|
||||||
}) => {
|
}) => {
|
||||||
@ -96,7 +93,7 @@ export const KeycloakProvider = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
mountedRef.current = true;
|
mountedRef.current = true;
|
||||||
initKeycloak({ clientId, initOptions })
|
initKeycloak({ config, initOptions })
|
||||||
.then((auth) => {
|
.then((auth) => {
|
||||||
if (!mountedRef.current) return;
|
if (!mountedRef.current) return;
|
||||||
setAuthenticated(Boolean(auth));
|
setAuthenticated(Boolean(auth));
|
||||||
@ -112,7 +109,7 @@ export const KeycloakProvider = ({
|
|||||||
return () => {
|
return () => {
|
||||||
mountedRef.current = false;
|
mountedRef.current = false;
|
||||||
};
|
};
|
||||||
}, [clientId, initOptions]);
|
}, [config, initOptions]);
|
||||||
|
|
||||||
const login = useCallback(() => {
|
const login = useCallback(() => {
|
||||||
return keycloakInstance?.login();
|
return keycloakInstance?.login();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user