@axa-fr/react-oidc 7.26.1-alpha.1797 → 7.26.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/OidcProvider.d.ts.map +1 -1
- package/dist/ReactOidc.d.ts.map +1 -1
- package/dist/User.d.ts.map +1 -1
- package/dist/index.js +186 -204
- package/dist/index.umd.cjs +1 -1
- package/package.json +20 -20
- package/src/FetchToken.tsx +1 -1
- package/src/OidcProvider.tsx +6 -3
- package/src/ReactOidc.tsx +2 -14
- package/src/User.ts +12 -3
- package/src/core/routes/OidcRoutes.spec.tsx +16 -2
- package/src/core/routes/__snapshots__/OidcRoutes.spec.tsx.snap +0 -6
- package/src/core/routes/withRouter.spec.tsx +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OidcProvider.d.ts","sourceRoot":"","sources":["../src/OidcProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAEL,cAAc,EACd,UAAU,EACV,iBAAiB,EAElB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,iBAAiB,EAAuB,MAAM,OAAO,CAAC;AAWlF,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,MAAM,MAAM,WAAW,GAAG;IACxB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;CAC7B,CAAC;AAIF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,wBAAwB,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAC9C,oBAAoB,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAC1C,uBAAuB,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAC7C,4BAA4B,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAClD,gBAAgB,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IACtC,kCAAkC,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IACxD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAClC,QAAQ,EAAE,GAAG,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAC3B,sBAAsB,CAAC,EAAE,MAAM,IAAI,CAAC;IACpC,mBAAmB,CAAC,EAAE,MAAM,IAAI,CAAC;IACjC,iBAAiB,CAAC,EAAE,MAAM,aAAa,CAAC;IACxC,OAAO,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;IACnE,QAAQ,CAAC,EAAE,MAAM,KAAK,CAAC;IACvB,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,iBAAiB,CAAC,GAAG,CAAC,CAAC;CAC1C,CAAC;AAqCF,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,
|
|
1
|
+
{"version":3,"file":"OidcProvider.d.ts","sourceRoot":"","sources":["../src/OidcProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAEL,cAAc,EACd,UAAU,EACV,iBAAiB,EAElB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,iBAAiB,EAAuB,MAAM,OAAO,CAAC;AAWlF,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,MAAM,MAAM,WAAW,GAAG;IACxB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;CAC7B,CAAC;AAIF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,wBAAwB,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAC9C,oBAAoB,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAC1C,uBAAuB,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAC7C,4BAA4B,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAClD,gBAAgB,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IACtC,kCAAkC,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IACxD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAClC,QAAQ,EAAE,GAAG,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAC3B,sBAAsB,CAAC,EAAE,MAAM,IAAI,CAAC;IACpC,mBAAmB,CAAC,EAAE,MAAM,IAAI,CAAC;IACjC,iBAAiB,CAAC,EAAE,MAAM,aAAa,CAAC;IACxC,OAAO,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;IACnE,QAAQ,CAAC,EAAE,MAAM,KAAK,CAAC;IACvB,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,iBAAiB,CAAC,GAAG,CAAC,CAAC;CAC1C,CAAC;AAqCF,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAgLjE,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
package/dist/ReactOidc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactOidc.d.ts","sourceRoot":"","sources":["../src/ReactOidc.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,SAAS,EAAU,MAAM,qBAAqB,CAAC;AAkBpE,eAAO,MAAM,OAAO,GAAI,0BAA4C;
|
|
1
|
+
{"version":3,"file":"ReactOidc.d.ts","sourceRoot":"","sources":["../src/ReactOidc.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,SAAS,EAAU,MAAM,qBAAqB,CAAC;AAkBpE,eAAO,MAAM,OAAO,GAAI,0BAA4C;2BA4BlD,MAAM,GAAG,SAAS,WACxB,SAAS,GAAG,SAAS,qCAEtB,MAAM;4BAWC,MAAM,GAAG,IAAI,GAAG,SAAS,WAC/B,SAAS,GAAG,SAAS;2BAKrB,SAAS,GAAG,SAAS,KAC5B,OAAO,CAAC,eAAe,GAAG,WAAW,CAAC;;CAe1C,CAAC;AAsBF,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,CAAC,EAAE,GAAG,CAAC;IAClB,kBAAkB,CAAC,EAAE,GAAG,CAAC;IACzB,6CAA6C,CAAC,EAAE,GAAG,CAAC;CACrD,CAAC;AASF,eAAO,MAAM,kBAAkB,GAAI,0BAA4C,oBAsC9E,CAAC;AAeF,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,cAAc,CAAC,EAAE,GAAG,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,0BAA4C,gBAiC1E,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,EAAc,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGpE,oBAAY,cAAc;IACxB,eAAe,oBAAoB;IACnC,OAAO,iBAAiB;IACxB,MAAM,gBAAgB;IACtB,YAAY,uBAAuB;CACpC;AAED,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY,IAAI;IAC5D,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IACf,MAAM,EAAE,cAAc,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,YAAY,GAAG,YAAY,EAC/D,0BAA6B,EAC7B,2CAAyC;;;;
|
|
1
|
+
{"version":3,"file":"User.d.ts","sourceRoot":"","sources":["../src/User.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGpE,oBAAY,cAAc;IACxB,eAAe,oBAAoB;IACnC,OAAO,iBAAiB;IACxB,MAAM,gBAAgB;IACtB,YAAY,uBAAuB;CACpC;AAED,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY,IAAI;IAC5D,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IACf,MAAM,EAAE,cAAc,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,YAAY,GAAG,YAAY,EAC/D,0BAA6B,EAC7B,2CAAyC;;;;CA+D1C,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
import { jsx as i, jsxs as
|
|
2
|
-
import { OidcClient as
|
|
3
|
-
import { OidcClient as
|
|
4
|
-
import Z, { useCallback as ee, useState as
|
|
5
|
-
const
|
|
6
|
-
const { fetch:
|
|
1
|
+
import { jsx as i, jsxs as S, Fragment as m } from "react/jsx-runtime";
|
|
2
|
+
import { OidcClient as c, getParseQueryStringFromLocation as V, getPath as O, OidcLocation as M, getFetchDefault as X } from "@axa-fr/oidc-client";
|
|
3
|
+
import { OidcClient as Fe, OidcLocation as qe, TokenAutomaticRenewMode as De, TokenRenewMode as xe } from "@axa-fr/oidc-client";
|
|
4
|
+
import Z, { useCallback as ee, useState as f, useEffect as p } from "react";
|
|
5
|
+
const D = "default", te = (t, n, e = !1) => async (...s) => await n().fetchWithTokens(t, e)(...s), Oe = (t = null, n = D, e = !1) => (s) => (o) => {
|
|
6
|
+
const { fetch: r } = ne(
|
|
7
7
|
t || o.fetch,
|
|
8
8
|
n,
|
|
9
9
|
e
|
|
10
10
|
);
|
|
11
|
-
return /* @__PURE__ */ i(s, { ...o, fetch:
|
|
12
|
-
}, ne = (t = null, n =
|
|
13
|
-
const s = t || window.fetch, o =
|
|
11
|
+
return /* @__PURE__ */ i(s, { ...o, fetch: r });
|
|
12
|
+
}, ne = (t = null, n = D, e = !1) => {
|
|
13
|
+
const s = t || window.fetch, o = c.get;
|
|
14
14
|
return { fetch: ee(
|
|
15
|
-
(
|
|
15
|
+
(a, l) => te(
|
|
16
16
|
s,
|
|
17
17
|
() => o(n),
|
|
18
18
|
e
|
|
19
|
-
)(
|
|
20
|
-
[s, n]
|
|
19
|
+
)(a, l),
|
|
20
|
+
[s, n, e]
|
|
21
21
|
) };
|
|
22
|
-
},
|
|
22
|
+
}, x = () => /* @__PURE__ */ i("div", { className: "oidc-authenticating", children: /* @__PURE__ */ S("div", { className: "oidc-authenticating__container", children: [
|
|
23
23
|
/* @__PURE__ */ i("h1", { className: "oidc-authenticating__title", children: "Error authentication" }),
|
|
24
24
|
/* @__PURE__ */ i("p", { className: "oidc-authenticating__content", children: "An error occurred during authentication." })
|
|
25
|
-
] }) }), se = () => /* @__PURE__ */ i("div", { className: "oidc-authenticating", children: /* @__PURE__ */
|
|
25
|
+
] }) }), se = () => /* @__PURE__ */ i("div", { className: "oidc-authenticating", children: /* @__PURE__ */ S("div", { className: "oidc-authenticating__container", children: [
|
|
26
26
|
/* @__PURE__ */ i("h1", { className: "oidc-authenticating__title", children: "Authentication in progress" }),
|
|
27
27
|
/* @__PURE__ */ i("p", { className: "oidc-authenticating__content", children: "You will be redirected to the login page." })
|
|
28
28
|
] }) }), oe = () => Math.random().toString(36).slice(2, 8), ce = (t, n) => (e, s) => {
|
|
29
29
|
if (typeof t.CustomEvent == "function")
|
|
30
30
|
return new t.CustomEvent(e, s);
|
|
31
|
-
const o = s || { bubbles: !1, cancelable: !1, detail: void 0 },
|
|
32
|
-
return
|
|
31
|
+
const o = s || { bubbles: !1, cancelable: !1, detail: void 0 }, r = n.createEvent("CustomEvent");
|
|
32
|
+
return r.initCustomEvent(
|
|
33
33
|
e,
|
|
34
34
|
o.bubbles,
|
|
35
35
|
o.cancelable,
|
|
36
36
|
o.detail
|
|
37
|
-
),
|
|
37
|
+
), r.prototype = t.Event.prototype, r;
|
|
38
38
|
}, re = (t, n, e) => ({
|
|
39
39
|
replaceState: (s, o) => {
|
|
40
|
-
const
|
|
41
|
-
t.history.replaceState({ key:
|
|
40
|
+
const r = e(), a = o || t.history.state;
|
|
41
|
+
t.history.replaceState({ key: r, state: a }, null, s), t.dispatchEvent(n("popstate"));
|
|
42
42
|
}
|
|
43
|
-
}), ie = () => re(window, ce(window, document), oe),
|
|
43
|
+
}), ie = () => re(window, ce(window, document), oe), W = () => /* @__PURE__ */ i("div", { className: "oidc-callback", children: /* @__PURE__ */ S("div", { className: "oidc-callback__container", children: [
|
|
44
44
|
/* @__PURE__ */ i("h1", { className: "oidc-callback__title", children: "Authentication complete" }),
|
|
45
45
|
/* @__PURE__ */ i("p", { className: "oidc-callback__content", children: "You will be redirected to your application." })
|
|
46
|
-
] }) }),
|
|
46
|
+
] }) }), le = ({
|
|
47
47
|
callBackError: t,
|
|
48
48
|
callBackSuccess: n,
|
|
49
49
|
configurationName: e,
|
|
50
50
|
withCustomHistory: s
|
|
51
51
|
}) => {
|
|
52
|
-
const [o,
|
|
53
|
-
|
|
52
|
+
const [o, r] = f(!1);
|
|
53
|
+
p(() => {
|
|
54
54
|
let d = !0;
|
|
55
55
|
return (async () => {
|
|
56
|
-
const _ =
|
|
56
|
+
const _ = c.get;
|
|
57
57
|
try {
|
|
58
|
-
const { callbackPath:
|
|
59
|
-
(s ? s() : ie()).replaceState(
|
|
60
|
-
} catch (
|
|
61
|
-
d && (console.warn(
|
|
58
|
+
const { callbackPath: k } = await _(e).loginCallbackAsync();
|
|
59
|
+
(s ? s() : ie()).replaceState(k || "/");
|
|
60
|
+
} catch (k) {
|
|
61
|
+
d && (console.warn(k), r(!0));
|
|
62
62
|
}
|
|
63
63
|
})(), () => {
|
|
64
64
|
d = !1;
|
|
65
65
|
};
|
|
66
66
|
}, []);
|
|
67
|
-
const
|
|
68
|
-
return o ? /* @__PURE__ */ i(
|
|
69
|
-
},
|
|
67
|
+
const a = t || x, l = n || W;
|
|
68
|
+
return o ? /* @__PURE__ */ i(a, { configurationName: e }) : /* @__PURE__ */ i(l, { configurationName: e });
|
|
69
|
+
}, ae = () => /* @__PURE__ */ i("span", { className: "oidc-loading", children: "Loading" }), de = () => /* @__PURE__ */ i("div", { className: "oidc-serviceworker", children: /* @__PURE__ */ S("div", { className: "oidc-serviceworker__container", children: [
|
|
70
70
|
/* @__PURE__ */ i("h1", { className: "oidc-serviceworker__title", children: "Unable to authenticate on this browser" }),
|
|
71
71
|
/* @__PURE__ */ i("p", { className: "oidc-serviceworker__content", children: "Your browser is not secure enough to make authentication work. Try updating your browser or use a newer browser." })
|
|
72
|
-
] }) }), ue = () => /* @__PURE__ */ i("div", { className: "oidc-session-lost", children: /* @__PURE__ */
|
|
72
|
+
] }) }), ue = () => /* @__PURE__ */ i("div", { className: "oidc-session-lost", children: /* @__PURE__ */ S("div", { className: "oidc-session-lost__container", children: [
|
|
73
73
|
/* @__PURE__ */ i("h1", { className: "oidc-session-lost__title", children: "Session timed out" }),
|
|
74
74
|
/* @__PURE__ */ i("p", { className: "oidc-session-lost__content", children: "Your session has expired. Please re-authenticate." })
|
|
75
|
-
] }) }),
|
|
75
|
+
] }) }), he = ({ configurationName: t }) => (p(() => {
|
|
76
76
|
(async () => {
|
|
77
|
-
|
|
77
|
+
c.get(t).silentLoginCallbackAsync();
|
|
78
78
|
})().catch((e) => {
|
|
79
79
|
console.error("Error during silent login callback:", e);
|
|
80
80
|
});
|
|
81
|
-
}, [t]), null),
|
|
82
|
-
const n = V(window.location.href), e =
|
|
81
|
+
}, [t]), null), ke = ({ configurationName: t }) => {
|
|
82
|
+
const n = V(window.location.href), e = c.get, s = e(t);
|
|
83
83
|
let o = null;
|
|
84
|
-
for (const [
|
|
85
|
-
|
|
86
|
-
return
|
|
84
|
+
for (const [r, a] of Object.entries(n))
|
|
85
|
+
r === "state" || r === "scope" || (o === null && (o = {}), o[r] = a);
|
|
86
|
+
return p(() => {
|
|
87
87
|
s.tokens || s.loginAsync(null, o, !0, n.scope);
|
|
88
88
|
}, []), /* @__PURE__ */ i(m, {});
|
|
89
89
|
}, _e = ({
|
|
@@ -92,142 +92,135 @@ const x = "default", te = (t, n, e = !1) => async (...s) => await n().fetchWithT
|
|
|
92
92
|
redirect_uri: e,
|
|
93
93
|
silent_redirect_uri: s,
|
|
94
94
|
silent_login_uri: o,
|
|
95
|
-
children:
|
|
96
|
-
configurationName:
|
|
97
|
-
withCustomHistory:
|
|
95
|
+
children: r,
|
|
96
|
+
configurationName: a,
|
|
97
|
+
withCustomHistory: l = null
|
|
98
98
|
}) => {
|
|
99
|
-
const d = window ? O(window.location.href) : "", [u, _] =
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
return
|
|
99
|
+
const d = window ? O(window.location.href) : "", [u, _] = f(d);
|
|
100
|
+
p(() => {
|
|
101
|
+
const v = () => _(O(window.location.href));
|
|
102
|
+
return v(), window.addEventListener("popstate", v, !1), () => window.removeEventListener("popstate", v, !1);
|
|
103
103
|
}, []);
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
callBackSuccess: n,
|
|
116
|
-
configurationName: l,
|
|
117
|
-
withCustomHistory: a
|
|
118
|
-
}
|
|
119
|
-
);
|
|
120
|
-
default:
|
|
121
|
-
return /* @__PURE__ */ i(m, { children: c });
|
|
122
|
-
}
|
|
123
|
-
}, ve = Z.memo(_e), D = { name: "", data: null }, fe = ({
|
|
104
|
+
const k = O(e);
|
|
105
|
+
return s && u === O(s) ? /* @__PURE__ */ i(he, { configurationName: a }) : o && u === O(o) ? /* @__PURE__ */ i(ke, { configurationName: a }) : u === k ? /* @__PURE__ */ i(
|
|
106
|
+
le,
|
|
107
|
+
{
|
|
108
|
+
callBackError: t,
|
|
109
|
+
callBackSuccess: n,
|
|
110
|
+
configurationName: a,
|
|
111
|
+
withCustomHistory: l
|
|
112
|
+
}
|
|
113
|
+
) : /* @__PURE__ */ i(m, { children: r });
|
|
114
|
+
}, ve = Z.memo(_e), F = { name: "", data: null }, fe = ({
|
|
124
115
|
loadingComponent: t,
|
|
125
116
|
children: n,
|
|
126
117
|
configurationName: e
|
|
127
118
|
}) => {
|
|
128
|
-
const [s, o] =
|
|
129
|
-
return
|
|
119
|
+
const [s, o] = f(!0), r = c.get, a = r(e);
|
|
120
|
+
return p(() => {
|
|
130
121
|
let d = !0;
|
|
131
|
-
return
|
|
122
|
+
return a && a.tryKeepExistingSessionAsync().then(() => {
|
|
132
123
|
d && o(!1);
|
|
133
124
|
}), () => {
|
|
134
125
|
d = !1;
|
|
135
126
|
};
|
|
136
127
|
}, [e]), /* @__PURE__ */ i(m, { children: s ? /* @__PURE__ */ i(t, { configurationName: e }) : /* @__PURE__ */ i(m, { children: n }) });
|
|
137
|
-
},
|
|
128
|
+
}, E = ({ isLoading: t, loadingComponent: n, children: e, configurationName: s }) => {
|
|
138
129
|
const o = n;
|
|
139
130
|
return t ? /* @__PURE__ */ i(o, { configurationName: s, children: e }) : /* @__PURE__ */ i(m, { children: e });
|
|
140
|
-
},
|
|
131
|
+
}, Ee = ({
|
|
141
132
|
children: t,
|
|
142
133
|
configuration: n,
|
|
143
134
|
configurationName: e = "default",
|
|
144
|
-
callbackSuccessComponent: s =
|
|
135
|
+
callbackSuccessComponent: s = W,
|
|
145
136
|
authenticatingComponent: o = se,
|
|
146
|
-
loadingComponent:
|
|
147
|
-
serviceWorkerNotSupportedComponent:
|
|
148
|
-
authenticatingErrorComponent:
|
|
137
|
+
loadingComponent: r = ae,
|
|
138
|
+
serviceWorkerNotSupportedComponent: a = de,
|
|
139
|
+
authenticatingErrorComponent: l = x,
|
|
149
140
|
sessionLostComponent: d = ue,
|
|
150
141
|
onSessionLost: u = null,
|
|
151
142
|
onLogoutFromAnotherTab: _ = null,
|
|
152
|
-
onLogoutFromSameTab:
|
|
153
|
-
withCustomHistory:
|
|
154
|
-
onEvent:
|
|
143
|
+
onLogoutFromSameTab: k = null,
|
|
144
|
+
withCustomHistory: v = null,
|
|
145
|
+
onEvent: w = null,
|
|
155
146
|
getFetch: y = null,
|
|
156
|
-
location:
|
|
147
|
+
location: P = null
|
|
157
148
|
}) => {
|
|
158
149
|
if (n && n.redirect_uri && n.silent_redirect_uri && n.redirect_uri === n.silent_redirect_uri)
|
|
159
150
|
throw new Error("redirect_uri and silent_redirect_uri must be different");
|
|
160
|
-
const
|
|
151
|
+
const T = (L = "default") => c.getOrCreate(y ?? X, P ?? new M())(
|
|
161
152
|
n,
|
|
162
153
|
L
|
|
163
|
-
), [j, B] =
|
|
164
|
-
|
|
165
|
-
const I =
|
|
166
|
-
|
|
154
|
+
), [j, B] = f(!0), [z, C] = f(F), [K, $] = f(e);
|
|
155
|
+
p(() => {
|
|
156
|
+
const I = T(e).subscribeEvents((h, g) => {
|
|
157
|
+
w && w(e, h, g);
|
|
167
158
|
});
|
|
168
159
|
return () => {
|
|
169
|
-
|
|
160
|
+
T(e).removeEventSubscription(I);
|
|
170
161
|
};
|
|
171
|
-
}, [e,
|
|
172
|
-
const I =
|
|
173
|
-
if (
|
|
162
|
+
}, [e, w]), p(() => {
|
|
163
|
+
const I = T(e).subscribeEvents((h, g) => {
|
|
164
|
+
if (h === c.eventNames.refreshTokensAsync_error || h === c.eventNames.syncTokensAsync_error) {
|
|
174
165
|
if (u != null) {
|
|
175
166
|
u();
|
|
176
167
|
return;
|
|
177
168
|
}
|
|
178
|
-
C({ name:
|
|
179
|
-
} else if (
|
|
169
|
+
C({ name: h, data: g });
|
|
170
|
+
} else if (h === c.eventNames.logout_from_another_tab) {
|
|
180
171
|
if (_ != null) {
|
|
181
172
|
_();
|
|
182
173
|
return;
|
|
183
174
|
}
|
|
184
|
-
C({ name:
|
|
185
|
-
} else
|
|
175
|
+
C({ name: h, data: g });
|
|
176
|
+
} else h === c.eventNames.logout_from_same_tab ? k?.() : h === c.eventNames.loginAsync_begin || h === c.eventNames.loginCallbackAsync_end || h === c.eventNames.loginAsync_error || h === c.eventNames.loginCallbackAsync_error ? C({ name: h, data: g }) : h === c.eventNames.service_worker_not_supported_by_browser && n.service_worker_only === !0 && C({ name: h, data: g });
|
|
186
177
|
});
|
|
187
|
-
return
|
|
188
|
-
|
|
178
|
+
return queueMicrotask(() => {
|
|
179
|
+
$(e), B(!1);
|
|
180
|
+
}), () => {
|
|
181
|
+
T(e).removeEventSubscription(I), C(F);
|
|
189
182
|
};
|
|
190
183
|
}, [n, e]);
|
|
191
|
-
const G = d, H = o,
|
|
184
|
+
const G = d, H = o, b = r, Q = a, J = l, A = j || K !== e, N = T(e);
|
|
192
185
|
switch (z.name) {
|
|
193
|
-
case
|
|
186
|
+
case c.eventNames.service_worker_not_supported_by_browser:
|
|
194
187
|
return /* @__PURE__ */ i(
|
|
195
|
-
|
|
188
|
+
E,
|
|
196
189
|
{
|
|
197
|
-
loadingComponent:
|
|
190
|
+
loadingComponent: b,
|
|
198
191
|
isLoading: A,
|
|
199
192
|
configurationName: e,
|
|
200
193
|
children: /* @__PURE__ */ i(Q, { configurationName: e })
|
|
201
194
|
}
|
|
202
195
|
);
|
|
203
|
-
case
|
|
196
|
+
case c.eventNames.loginAsync_begin:
|
|
204
197
|
return /* @__PURE__ */ i(
|
|
205
|
-
|
|
198
|
+
E,
|
|
206
199
|
{
|
|
207
|
-
loadingComponent:
|
|
200
|
+
loadingComponent: b,
|
|
208
201
|
isLoading: A,
|
|
209
202
|
configurationName: e,
|
|
210
203
|
children: /* @__PURE__ */ i(H, { configurationName: e })
|
|
211
204
|
}
|
|
212
205
|
);
|
|
213
|
-
case
|
|
214
|
-
case
|
|
206
|
+
case c.eventNames.loginAsync_error:
|
|
207
|
+
case c.eventNames.loginCallbackAsync_error:
|
|
215
208
|
return /* @__PURE__ */ i(
|
|
216
|
-
|
|
209
|
+
E,
|
|
217
210
|
{
|
|
218
|
-
loadingComponent:
|
|
211
|
+
loadingComponent: b,
|
|
219
212
|
isLoading: A,
|
|
220
213
|
configurationName: e,
|
|
221
214
|
children: /* @__PURE__ */ i(J, { configurationName: e })
|
|
222
215
|
}
|
|
223
216
|
);
|
|
224
|
-
case
|
|
225
|
-
case
|
|
226
|
-
case
|
|
217
|
+
case c.eventNames.refreshTokensAsync_error:
|
|
218
|
+
case c.eventNames.syncTokensAsync_error:
|
|
219
|
+
case c.eventNames.logout_from_another_tab:
|
|
227
220
|
return /* @__PURE__ */ i(
|
|
228
|
-
|
|
221
|
+
E,
|
|
229
222
|
{
|
|
230
|
-
loadingComponent:
|
|
223
|
+
loadingComponent: b,
|
|
231
224
|
isLoading: A,
|
|
232
225
|
configurationName: e,
|
|
233
226
|
children: /* @__PURE__ */ i(G, { configurationName: e })
|
|
@@ -235,9 +228,9 @@ const x = "default", te = (t, n, e = !1) => async (...s) => await n().fetchWithT
|
|
|
235
228
|
);
|
|
236
229
|
default:
|
|
237
230
|
return /* @__PURE__ */ i(
|
|
238
|
-
|
|
231
|
+
E,
|
|
239
232
|
{
|
|
240
|
-
loadingComponent:
|
|
233
|
+
loadingComponent: b,
|
|
241
234
|
isLoading: A,
|
|
242
235
|
configurationName: e,
|
|
243
236
|
children: /* @__PURE__ */ i(
|
|
@@ -247,12 +240,12 @@ const x = "default", te = (t, n, e = !1) => async (...s) => await n().fetchWithT
|
|
|
247
240
|
silent_redirect_uri: N.configuration.silent_redirect_uri,
|
|
248
241
|
silent_login_uri: N.configuration.silent_login_uri,
|
|
249
242
|
callbackSuccessComponent: s,
|
|
250
|
-
callbackErrorComponent:
|
|
243
|
+
callbackErrorComponent: l,
|
|
251
244
|
authenticatingComponent: o,
|
|
252
245
|
configurationName: e,
|
|
253
|
-
withCustomHistory:
|
|
254
|
-
location:
|
|
255
|
-
children: /* @__PURE__ */ i(fe, { loadingComponent:
|
|
246
|
+
withCustomHistory: v,
|
|
247
|
+
location: P ?? new M(),
|
|
248
|
+
children: /* @__PURE__ */ i(fe, { loadingComponent: b, configurationName: e, children: t })
|
|
256
249
|
}
|
|
257
250
|
)
|
|
258
251
|
}
|
|
@@ -264,35 +257,33 @@ const x = "default", te = (t, n, e = !1) => async (...s) => await n().fetchWithT
|
|
|
264
257
|
extras: e = null,
|
|
265
258
|
configurationName: s = "default"
|
|
266
259
|
}) => {
|
|
267
|
-
const o =
|
|
268
|
-
return
|
|
269
|
-
|
|
270
|
-
}, [s, n, e]),
|
|
271
|
-
},
|
|
260
|
+
const o = c.get, r = o(s);
|
|
261
|
+
return p(() => {
|
|
262
|
+
r.tokens || r.loginAsync(n, e);
|
|
263
|
+
}, [s, n, e]), r.tokens ? /* @__PURE__ */ i(m, { children: t }) : null;
|
|
264
|
+
}, Se = (t, n = null, e = null, s = "default") => (o) => /* @__PURE__ */ i(pe, { callbackPath: n, extras: e, configurationName: s, children: /* @__PURE__ */ i(t, { ...o }) }), U = "default", q = (t, n) => {
|
|
272
265
|
let e = !1;
|
|
273
266
|
return t(n) && (e = t(n).tokens != null), e;
|
|
274
|
-
},
|
|
275
|
-
const n =
|
|
276
|
-
|
|
267
|
+
}, Pe = (t = U) => {
|
|
268
|
+
const n = c.get, [e, s] = f(
|
|
269
|
+
q(n, t)
|
|
277
270
|
);
|
|
278
|
-
return
|
|
279
|
-
let
|
|
280
|
-
const d = n(t)
|
|
281
|
-
|
|
282
|
-
const u = d.subscribeEvents((_, h) => {
|
|
283
|
-
(_ === r.eventNames.logout_from_another_tab || _ === r.eventNames.logout_from_same_tab || _ === r.eventNames.token_acquired) && a && s(U(n, t));
|
|
271
|
+
return p(() => {
|
|
272
|
+
let l = !0;
|
|
273
|
+
const d = n(t), u = d.subscribeEvents((_, k) => {
|
|
274
|
+
(_ === c.eventNames.logout_from_another_tab || _ === c.eventNames.logout_from_same_tab || _ === c.eventNames.token_acquired) && l && s(q(n, t));
|
|
284
275
|
});
|
|
285
276
|
return () => {
|
|
286
|
-
|
|
277
|
+
l = !1, d.removeEventSubscription(u);
|
|
287
278
|
};
|
|
288
|
-
}, [t]), { login: (
|
|
289
|
-
|
|
279
|
+
}, [t]), { login: (l = void 0, d = void 0, u = !1, _ = void 0) => n(t).loginAsync(
|
|
280
|
+
l,
|
|
290
281
|
d,
|
|
291
282
|
!1,
|
|
292
283
|
_,
|
|
293
284
|
u
|
|
294
|
-
), logout: (
|
|
295
|
-
const d = await n(t).renewTokensAsync(
|
|
285
|
+
), logout: (l = void 0, d = void 0) => n(t).logoutAsync(l, d), renewTokens: async (l = void 0) => {
|
|
286
|
+
const d = await n(t).renewTokensAsync(l);
|
|
296
287
|
return {
|
|
297
288
|
// @ts-ignore
|
|
298
289
|
accessToken: d.accessToken,
|
|
@@ -304,142 +295,133 @@ const x = "default", te = (t, n, e = !1) => async (...s) => await n().fetchWithT
|
|
|
304
295
|
idTokenPayload: d.idTokenPayload
|
|
305
296
|
};
|
|
306
297
|
}, isAuthenticated: e };
|
|
307
|
-
},
|
|
308
|
-
const n =
|
|
298
|
+
}, R = { accessToken: null, accessTokenPayload: null }, ye = (t) => {
|
|
299
|
+
const n = c.get, e = n(t);
|
|
309
300
|
if (e.tokens) {
|
|
310
301
|
const s = e.tokens;
|
|
311
302
|
return {
|
|
312
303
|
accessToken: s.accessToken,
|
|
313
304
|
accessTokenPayload: s.accessTokenPayload,
|
|
314
|
-
generateDemonstrationOfProofOfPossessionAsync: e.configuration.demonstrating_proof_of_possession ? (o,
|
|
305
|
+
generateDemonstrationOfProofOfPossessionAsync: e.configuration.demonstrating_proof_of_possession ? (o, r) => e.generateDemonstrationOfProofOfPossessionAsync(s.accessToken, o, r) : null
|
|
315
306
|
};
|
|
316
307
|
}
|
|
317
|
-
return
|
|
308
|
+
return R;
|
|
318
309
|
};
|
|
319
|
-
function
|
|
310
|
+
function be(t, n) {
|
|
320
311
|
return t.configuration.demonstrating_proof_of_possession ? (e, s, o = {}) => t.generateDemonstrationOfProofOfPossessionAsync(n.accessToken, e, s, o) : null;
|
|
321
312
|
}
|
|
322
|
-
const Ne = (t =
|
|
323
|
-
const n =
|
|
324
|
-
return
|
|
313
|
+
const Ne = (t = U) => {
|
|
314
|
+
const n = c.get, [e, s] = f(() => ye(t));
|
|
315
|
+
return p(() => {
|
|
325
316
|
let o = !0;
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
s({
|
|
330
|
-
accessToken: a.accessToken,
|
|
331
|
-
accessTokenPayload: a.accessTokenPayload
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
const l = c.subscribeEvents((a, d) => {
|
|
335
|
-
if ((a === r.eventNames.token_renewed || a === r.eventNames.token_acquired || a === r.eventNames.logout_from_another_tab || a === r.eventNames.logout_from_same_tab || a === r.eventNames.refreshTokensAsync_error || a === r.eventNames.syncTokensAsync_error) && o) {
|
|
336
|
-
const u = c.tokens;
|
|
317
|
+
const r = n(t), a = r.subscribeEvents((l, d) => {
|
|
318
|
+
if ((l === c.eventNames.token_renewed || l === c.eventNames.token_acquired || l === c.eventNames.logout_from_another_tab || l === c.eventNames.logout_from_same_tab || l === c.eventNames.refreshTokensAsync_error || l === c.eventNames.syncTokensAsync_error) && o) {
|
|
319
|
+
const u = r.tokens;
|
|
337
320
|
s(
|
|
338
321
|
u != null ? {
|
|
339
322
|
accessToken: u.accessToken,
|
|
340
323
|
accessTokenPayload: u.accessTokenPayload,
|
|
341
|
-
generateDemonstrationOfProofOfPossessionAsync:
|
|
342
|
-
} :
|
|
324
|
+
generateDemonstrationOfProofOfPossessionAsync: be(r, u)
|
|
325
|
+
} : R
|
|
343
326
|
);
|
|
344
327
|
}
|
|
345
328
|
});
|
|
346
329
|
return () => {
|
|
347
|
-
o = !1,
|
|
330
|
+
o = !1, r.removeEventSubscription(a);
|
|
348
331
|
};
|
|
349
332
|
}, [t]), e;
|
|
350
|
-
}, Y = { idToken: null, idTokenPayload: null },
|
|
351
|
-
const n =
|
|
333
|
+
}, Y = { idToken: null, idTokenPayload: null }, ge = (t) => {
|
|
334
|
+
const n = c.get, e = n(t);
|
|
352
335
|
if (e.tokens) {
|
|
353
336
|
const s = e.tokens;
|
|
354
337
|
return { idToken: s.idToken, idTokenPayload: s.idTokenPayload };
|
|
355
338
|
}
|
|
356
339
|
return Y;
|
|
357
|
-
}, Le = (t =
|
|
358
|
-
const n =
|
|
359
|
-
return
|
|
340
|
+
}, Le = (t = U) => {
|
|
341
|
+
const n = c.get, [e, s] = f(() => ge(t));
|
|
342
|
+
return p(() => {
|
|
360
343
|
let o = !0;
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
s({ idToken: a.idToken, idTokenPayload: a.idTokenPayload });
|
|
365
|
-
}
|
|
366
|
-
const l = c.subscribeEvents((a, d) => {
|
|
367
|
-
if ((a === r.eventNames.token_renewed || a === r.eventNames.token_acquired || a === r.eventNames.logout_from_another_tab || a === r.eventNames.logout_from_same_tab || a === r.eventNames.refreshTokensAsync_error || a === r.eventNames.syncTokensAsync_error) && o) {
|
|
368
|
-
const u = c.tokens;
|
|
344
|
+
const r = n(t), a = r.subscribeEvents((l, d) => {
|
|
345
|
+
if ((l === c.eventNames.token_renewed || l === c.eventNames.token_acquired || l === c.eventNames.logout_from_another_tab || l === c.eventNames.logout_from_same_tab || l === c.eventNames.refreshTokensAsync_error || l === c.eventNames.syncTokensAsync_error) && o) {
|
|
346
|
+
const u = r.tokens;
|
|
369
347
|
s(
|
|
370
348
|
u != null ? { idToken: u.idToken, idTokenPayload: u.idTokenPayload } : Y
|
|
371
349
|
);
|
|
372
350
|
}
|
|
373
351
|
});
|
|
374
352
|
return () => {
|
|
375
|
-
o = !1,
|
|
353
|
+
o = !1, r.removeEventSubscription(a);
|
|
376
354
|
};
|
|
377
355
|
}, [t]), e;
|
|
378
356
|
};
|
|
379
357
|
var me = /* @__PURE__ */ ((t) => (t.Unauthenticated = "Unauthenticated", t.Loading = "Loading user", t.Loaded = "User loaded", t.LoadingError = "Error loading user", t))(me || {});
|
|
380
358
|
const Ie = (t = "default", n = !1) => {
|
|
381
|
-
const s =
|
|
359
|
+
const s = c.get(t).userInfo(), [o, r] = f({
|
|
382
360
|
user: s,
|
|
383
361
|
status: s ? "User loaded" : "Unauthenticated"
|
|
384
362
|
/* Unauthenticated */
|
|
385
|
-
}), [
|
|
386
|
-
|
|
387
|
-
const
|
|
388
|
-
let
|
|
389
|
-
if (
|
|
390
|
-
const y =
|
|
391
|
-
if (y &&
|
|
363
|
+
}), [a, l] = f(s ? 1 : 0), [d, u] = f(s ? 1 : 0);
|
|
364
|
+
p(() => {
|
|
365
|
+
const k = c.get(t);
|
|
366
|
+
let v = !0;
|
|
367
|
+
if (k && k.tokens) {
|
|
368
|
+
const y = a === d;
|
|
369
|
+
if (y && k.userInfo())
|
|
392
370
|
return;
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
371
|
+
queueMicrotask(() => {
|
|
372
|
+
v && (r({
|
|
373
|
+
...o,
|
|
374
|
+
status: "Loading user"
|
|
375
|
+
/* Loading */
|
|
376
|
+
}), u(a));
|
|
377
|
+
}), k.userInfoAsync(!y, n).then((P) => {
|
|
378
|
+
v && r({
|
|
379
|
+
user: P,
|
|
400
380
|
status: "User loaded"
|
|
401
381
|
/* Loaded */
|
|
402
382
|
});
|
|
403
|
-
}).catch(() =>
|
|
383
|
+
}).catch(() => r({
|
|
404
384
|
...o,
|
|
405
385
|
status: "Error loading user"
|
|
406
386
|
/* LoadingError */
|
|
407
|
-
}))
|
|
387
|
+
}));
|
|
408
388
|
} else
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
389
|
+
queueMicrotask(() => {
|
|
390
|
+
v && r({
|
|
391
|
+
user: null,
|
|
392
|
+
status: "Unauthenticated"
|
|
393
|
+
/* Unauthenticated */
|
|
394
|
+
});
|
|
413
395
|
});
|
|
414
|
-
const
|
|
415
|
-
(y ===
|
|
396
|
+
const w = k.subscribeEvents((y) => {
|
|
397
|
+
(y === c.eventNames.logout_from_another_tab || y === c.eventNames.logout_from_same_tab) && v && r({
|
|
416
398
|
user: null,
|
|
417
399
|
status: "Unauthenticated"
|
|
418
400
|
/* Unauthenticated */
|
|
419
401
|
});
|
|
420
402
|
});
|
|
421
403
|
return () => {
|
|
422
|
-
|
|
404
|
+
v = !1, k.removeEventSubscription(w);
|
|
423
405
|
};
|
|
424
|
-
}, [
|
|
406
|
+
}, [a]);
|
|
425
407
|
const _ = () => {
|
|
426
|
-
a
|
|
408
|
+
l(a + 1);
|
|
427
409
|
};
|
|
428
410
|
return { oidcUser: o.user, oidcUserLoadingState: o.status, reloadOidcUser: _ };
|
|
429
411
|
};
|
|
430
412
|
export {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
413
|
+
Fe as OidcClient,
|
|
414
|
+
qe as OidcLocation,
|
|
415
|
+
Ee as OidcProvider,
|
|
434
416
|
pe as OidcSecure,
|
|
435
417
|
me as OidcUserStatus,
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
418
|
+
De as TokenAutomaticRenewMode,
|
|
419
|
+
xe as TokenRenewMode,
|
|
420
|
+
Pe as useOidc,
|
|
439
421
|
Ne as useOidcAccessToken,
|
|
440
422
|
ne as useOidcFetch,
|
|
441
423
|
Le as useOidcIdToken,
|
|
442
424
|
Ie as useOidcUser,
|
|
443
425
|
Oe as withOidcFetch,
|
|
444
|
-
|
|
426
|
+
Se as withOidcSecure
|
|
445
427
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(h,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("react/jsx-runtime"),require("@axa-fr/oidc-client"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@axa-fr/oidc-client","react"],o):(h=typeof globalThis<"u"?globalThis:h||self,o(h["react-oidc"]={},h.jsxRuntime,h.oidcClient,h.React))})(this,function(h,o,s,l){"use strict";const F="default",B=(t,n,e=!1)=>async(...c)=>await n().fetchWithTokens(t,e)(...c),z=(t=null,n=F,e=!1)=>c=>r=>{const{fetch:i}=I(t||r.fetch,n,e);return o.jsx(c,{...r,fetch:i})},I=(t=null,n=F,e=!1)=>{const c=t||window.fetch,r=s.OidcClient.get;return{fetch:l.useCallback((d,a)=>B(c,()=>r(n),e)(d,a),[c,n])}},U=()=>o.jsx("div",{className:"oidc-authenticating",children:o.jsxs("div",{className:"oidc-authenticating__container",children:[o.jsx("h1",{className:"oidc-authenticating__title",children:"Error authentication"}),o.jsx("p",{className:"oidc-authenticating__content",children:"An error occurred during authentication."})]})}),K=()=>o.jsx("div",{className:"oidc-authenticating",children:o.jsxs("div",{className:"oidc-authenticating__container",children:[o.jsx("h1",{className:"oidc-authenticating__title",children:"Authentication in progress"}),o.jsx("p",{className:"oidc-authenticating__content",children:"You will be redirected to the login page."})]})}),$=()=>Math.random().toString(36).slice(2,8),G=(t,n)=>(e,c)=>{if(typeof t.CustomEvent=="function")return new t.CustomEvent(e,c);const r=c||{bubbles:!1,cancelable:!1,detail:void 0},i=n.createEvent("CustomEvent");return i.initCustomEvent(e,r.bubbles,r.cancelable,r.detail),i.prototype=t.Event.prototype,i},H=(t,n,e)=>({replaceState:(c,r)=>{const i=e(),d=r||t.history.state;t.history.replaceState({key:i,state:d},null,c),t.dispatchEvent(n("popstate"))}}),Q=()=>H(window,G(window,document),$),M=()=>o.jsx("div",{className:"oidc-callback",children:o.jsxs("div",{className:"oidc-callback__container",children:[o.jsx("h1",{className:"oidc-callback__title",children:"Authentication complete"}),o.jsx("p",{className:"oidc-callback__content",children:"You will be redirected to your application."})]})}),J=({callBackError:t,callBackSuccess:n,configurationName:e,withCustomHistory:c})=>{const[r,i]=l.useState(!1);l.useEffect(()=>{let u=!0;return(async()=>{const O=s.OidcClient.get;try{const{callbackPath:_}=await O(e).loginCallbackAsync();(c?c():Q()).replaceState(_||"/")}catch(_){u&&(console.warn(_),i(!0))}})(),()=>{u=!1}},[]);const d=t||U,a=n||M;return r?o.jsx(d,{configurationName:e}):o.jsx(a,{configurationName:e})},V=()=>o.jsx("span",{className:"oidc-loading",children:"Loading"}),X=()=>o.jsx("div",{className:"oidc-serviceworker",children:o.jsxs("div",{className:"oidc-serviceworker__container",children:[o.jsx("h1",{className:"oidc-serviceworker__title",children:"Unable to authenticate on this browser"}),o.jsx("p",{className:"oidc-serviceworker__content",children:"Your browser is not secure enough to make authentication work. Try updating your browser or use a newer browser."})]})}),Z=()=>o.jsx("div",{className:"oidc-session-lost",children:o.jsxs("div",{className:"oidc-session-lost__container",children:[o.jsx("h1",{className:"oidc-session-lost__title",children:"Session timed out"}),o.jsx("p",{className:"oidc-session-lost__content",children:"Your session has expired. Please re-authenticate."})]})}),x=({configurationName:t})=>(l.useEffect(()=>{(async()=>{s.OidcClient.get(t).silentLoginCallbackAsync()})().catch(e=>{console.error("Error during silent login callback:",e)})},[t]),null),R=({configurationName:t})=>{const n=s.getParseQueryStringFromLocation(window.location.href),e=s.OidcClient.get,c=e(t);let r=null;for(const[i,d]of Object.entries(n))i==="state"||i==="scope"||(r===null&&(r={}),r[i]=d);return l.useEffect(()=>{c.tokens||c.loginAsync(null,r,!0,n.scope)},[]),o.jsx(o.Fragment,{})},ee=({callbackErrorComponent:t,callbackSuccessComponent:n,redirect_uri:e,silent_redirect_uri:c,silent_login_uri:r,children:i,configurationName:d,withCustomHistory:a=null})=>{const u=window?s.getPath(window.location.href):"",[f,O]=l.useState(u);l.useEffect(()=>{const v=()=>O(s.getPath(window.location.href));return v(),window.addEventListener("popstate",v,!1),()=>window.removeEventListener("popstate",v,!1)},[]);const _=s.getPath(e);if(c&&f===s.getPath(c))return o.jsx(x,{configurationName:d});if(r&&f===s.getPath(r))return o.jsx(R,{configurationName:d});switch(f){case _:return o.jsx(J,{callBackError:t,callBackSuccess:n,configurationName:d,withCustomHistory:a});default:return o.jsx(o.Fragment,{children:i})}},te=l.memo(ee),q={name:"",data:null},se=({loadingComponent:t,children:n,configurationName:e})=>{const[c,r]=l.useState(!0),i=s.OidcClient.get,d=i(e);l.useEffect(()=>{let u=!0;return d&&d.tryKeepExistingSessionAsync().then(()=>{u&&r(!1)}),()=>{u=!1}},[e]);const a=t;return o.jsx(o.Fragment,{children:c?o.jsx(a,{configurationName:e}):o.jsx(o.Fragment,{children:n})})},p=({isLoading:t,loadingComponent:n,children:e,configurationName:c})=>{const r=n;return t?o.jsx(r,{configurationName:c,children:e}):o.jsx(o.Fragment,{children:e})},ne=({children:t,configuration:n,configurationName:e="default",callbackSuccessComponent:c=M,authenticatingComponent:r=K,loadingComponent:i=V,serviceWorkerNotSupportedComponent:d=X,authenticatingErrorComponent:a=U,sessionLostComponent:u=Z,onSessionLost:f=null,onLogoutFromAnotherTab:O=null,onLogoutFromSameTab:_=null,withCustomHistory:v=null,onEvent:T=null,getFetch:y=null,location:P=null})=>{if(n&&n.redirect_uri&&n.silent_redirect_uri&&n.redirect_uri===n.silent_redirect_uri)throw new Error("redirect_uri and silent_redirect_uri must be different");const w=(N="default")=>s.OidcClient.getOrCreate(y??s.getFetchDefault,P??new s.OidcLocation)(n,N),[fe,he]=l.useState(!0),[ke,S]=l.useState(q),[_e,Oe]=l.useState("default");l.useEffect(()=>{const m=w(e).subscribeEvents((k,b)=>{T&&T(e,k,b)});return()=>{w(e).removeEventSubscription(m)}},[e,T]),l.useEffect(()=>{const m=w(e).subscribeEvents((k,b)=>{if(k===s.OidcClient.eventNames.refreshTokensAsync_error||k===s.OidcClient.eventNames.syncTokensAsync_error){if(f!=null){f();return}S({name:k,data:b})}else if(k===s.OidcClient.eventNames.logout_from_another_tab){if(O!=null){O();return}S({name:k,data:b})}else k===s.OidcClient.eventNames.logout_from_same_tab?_!=null&&_():k===s.OidcClient.eventNames.loginAsync_begin||k===s.OidcClient.eventNames.loginCallbackAsync_end||k===s.OidcClient.eventNames.loginAsync_error||k===s.OidcClient.eventNames.loginCallbackAsync_error?S({name:k,data:b}):k===s.OidcClient.eventNames.service_worker_not_supported_by_browser&&n.service_worker_only===!0&&S({name:k,data:b})});return Oe(e),he(!1),()=>{w(e).removeEventSubscription(m),S(q)}},[n,e]);const ve=u,ye=r,g=i,ge=d,be=a,A=fe||_e!==e,L=w(e);switch(ke.name){case s.OidcClient.eventNames.service_worker_not_supported_by_browser:return o.jsx(p,{loadingComponent:g,isLoading:A,configurationName:e,children:o.jsx(ge,{configurationName:e})});case s.OidcClient.eventNames.loginAsync_begin:return o.jsx(p,{loadingComponent:g,isLoading:A,configurationName:e,children:o.jsx(ye,{configurationName:e})});case s.OidcClient.eventNames.loginAsync_error:case s.OidcClient.eventNames.loginCallbackAsync_error:return o.jsx(p,{loadingComponent:g,isLoading:A,configurationName:e,children:o.jsx(be,{configurationName:e})});case s.OidcClient.eventNames.refreshTokensAsync_error:case s.OidcClient.eventNames.syncTokensAsync_error:case s.OidcClient.eventNames.logout_from_another_tab:return o.jsx(p,{loadingComponent:g,isLoading:A,configurationName:e,children:o.jsx(ve,{configurationName:e})});default:return o.jsx(p,{loadingComponent:g,isLoading:A,configurationName:e,children:o.jsx(te,{redirect_uri:L.configuration.redirect_uri,silent_redirect_uri:L.configuration.silent_redirect_uri,silent_login_uri:L.configuration.silent_login_uri,callbackSuccessComponent:c,callbackErrorComponent:a,authenticatingComponent:r,configurationName:e,withCustomHistory:v,location:P??new s.OidcLocation,children:o.jsx(se,{loadingComponent:g,configurationName:e,children:t})})})}},D=({children:t,callbackPath:n=null,extras:e=null,configurationName:c="default"})=>{const r=s.OidcClient.get,i=r(c);return l.useEffect(()=>{i.tokens||i.loginAsync(n,e)},[c,n,e]),i.tokens?o.jsx(o.Fragment,{children:t}):null},oe=(t,n=null,e=null,c="default")=>r=>o.jsx(D,{callbackPath:n,extras:e,configurationName:c,children:o.jsx(t,{...r})}),E="default",C=(t,n)=>{let e=!1;return t(n)&&(e=t(n).tokens!=null),e},ce=(t=E)=>{const n=s.OidcClient.get,[e,c]=l.useState(C(n,t));return l.useEffect(()=>{let a=!0;const u=n(t);c(C(n,t));const f=u.subscribeEvents((O,_)=>{(O===s.OidcClient.eventNames.logout_from_another_tab||O===s.OidcClient.eventNames.logout_from_same_tab||O===s.OidcClient.eventNames.token_acquired)&&a&&c(C(n,t))});return()=>{a=!1,u.removeEventSubscription(f)}},[t]),{login:(a=void 0,u=void 0,f=!1,O=void 0)=>n(t).loginAsync(a,u,!1,O,f),logout:(a=void 0,u=void 0)=>n(t).logoutAsync(a,u),renewTokens:async(a=void 0)=>{const u=await n(t).renewTokensAsync(a);return{accessToken:u.accessToken,accessTokenPayload:u.accessTokenPayload,idToken:u.idToken,idTokenPayload:u.idTokenPayload}},isAuthenticated:e}},W={accessToken:null,accessTokenPayload:null},re=t=>{const n=s.OidcClient.get,e=n(t);if(e.tokens){const c=e.tokens;return{accessToken:c.accessToken,accessTokenPayload:c.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:e.configuration.demonstrating_proof_of_possession?(r,i)=>e.generateDemonstrationOfProofOfPossessionAsync(c.accessToken,r,i):null}}return W};function ie(t,n){return t.configuration.demonstrating_proof_of_possession?(e,c,r={})=>t.generateDemonstrationOfProofOfPossessionAsync(n.accessToken,e,c,r):null}const ae=(t=E)=>{const n=s.OidcClient.get,[e,c]=l.useState(re(t));return l.useEffect(()=>{let r=!0;const i=n(t);if(i.tokens){const a=i.tokens;c({accessToken:a.accessToken,accessTokenPayload:a.accessTokenPayload})}const d=i.subscribeEvents((a,u)=>{if((a===s.OidcClient.eventNames.token_renewed||a===s.OidcClient.eventNames.token_acquired||a===s.OidcClient.eventNames.logout_from_another_tab||a===s.OidcClient.eventNames.logout_from_same_tab||a===s.OidcClient.eventNames.refreshTokensAsync_error||a===s.OidcClient.eventNames.syncTokensAsync_error)&&r){const f=i.tokens;c(f!=null?{accessToken:f.accessToken,accessTokenPayload:f.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:ie(i,f)}:W)}});return()=>{r=!1,i.removeEventSubscription(d)}},[t]),e},j={idToken:null,idTokenPayload:null},le=t=>{const n=s.OidcClient.get,e=n(t);if(e.tokens){const c=e.tokens;return{idToken:c.idToken,idTokenPayload:c.idTokenPayload}}return j},de=(t=E)=>{const n=s.OidcClient.get,[e,c]=l.useState(le(t));return l.useEffect(()=>{let r=!0;const i=n(t);if(i.tokens){const a=i.tokens;c({idToken:a.idToken,idTokenPayload:a.idTokenPayload})}const d=i.subscribeEvents((a,u)=>{if((a===s.OidcClient.eventNames.token_renewed||a===s.OidcClient.eventNames.token_acquired||a===s.OidcClient.eventNames.logout_from_another_tab||a===s.OidcClient.eventNames.logout_from_same_tab||a===s.OidcClient.eventNames.refreshTokensAsync_error||a===s.OidcClient.eventNames.syncTokensAsync_error)&&r){const f=i.tokens;c(f!=null?{idToken:f.idToken,idTokenPayload:f.idTokenPayload}:j)}});return()=>{r=!1,i.removeEventSubscription(d)}},[t]),e};var Y=(t=>(t.Unauthenticated="Unauthenticated",t.Loading="Loading user",t.Loaded="User loaded",t.LoadingError="Error loading user",t))(Y||{});const ue=(t="default",n=!1)=>{const c=s.OidcClient.get(t).userInfo(),[r,i]=l.useState({user:c,status:c?"User loaded":"Unauthenticated"}),[d,a]=l.useState(c?1:0),[u,f]=l.useState(c?1:0);l.useEffect(()=>{const _=s.OidcClient.get(t);let v=!0;if(_&&_.tokens){const y=d===u;if(y&&_.userInfo())return;i({...r,status:"Loading user"}),_.userInfoAsync(!y,n).then(P=>{v&&i({user:P,status:"User loaded"})}).catch(()=>i({...r,status:"Error loading user"})),f(d)}else i({user:null,status:"Unauthenticated"});const T=_.subscribeEvents(y=>{(y===s.OidcClient.eventNames.logout_from_another_tab||y===s.OidcClient.eventNames.logout_from_same_tab)&&v&&i({user:null,status:"Unauthenticated"})});return()=>{v=!1,_.removeEventSubscription(T)}},[d]);const O=()=>{a(d+1)};return{oidcUser:r.user,oidcUserLoadingState:r.status,reloadOidcUser:O}};Object.defineProperty(h,"OidcClient",{enumerable:!0,get:()=>s.OidcClient}),Object.defineProperty(h,"OidcLocation",{enumerable:!0,get:()=>s.OidcLocation}),Object.defineProperty(h,"TokenAutomaticRenewMode",{enumerable:!0,get:()=>s.TokenAutomaticRenewMode}),Object.defineProperty(h,"TokenRenewMode",{enumerable:!0,get:()=>s.TokenRenewMode}),h.OidcProvider=ne,h.OidcSecure=D,h.OidcUserStatus=Y,h.useOidc=ce,h.useOidcAccessToken=ae,h.useOidcFetch=I,h.useOidcIdToken=de,h.useOidcUser=ue,h.withOidcFetch=z,h.withOidcSecure=oe,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(h,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("@axa-fr/oidc-client"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@axa-fr/oidc-client","react"],n):(h=typeof globalThis<"u"?globalThis:h||self,n(h["react-oidc"]={},h.jsxRuntime,h.oidcClient,h.React))})(this,(function(h,n,s,l){"use strict";const m="default",B=(t,c,e=!1)=>async(...o)=>await c().fetchWithTokens(t,e)(...o),z=(t=null,c=m,e=!1)=>o=>r=>{const{fetch:i}=F(t||r.fetch,c,e);return n.jsx(o,{...r,fetch:i})},F=(t=null,c=m,e=!1)=>{const o=t||window.fetch,r=s.OidcClient.get;return{fetch:l.useCallback((d,a)=>B(o,()=>r(c),e)(d,a),[o,c,e])}},I=()=>n.jsx("div",{className:"oidc-authenticating",children:n.jsxs("div",{className:"oidc-authenticating__container",children:[n.jsx("h1",{className:"oidc-authenticating__title",children:"Error authentication"}),n.jsx("p",{className:"oidc-authenticating__content",children:"An error occurred during authentication."})]})}),K=()=>n.jsx("div",{className:"oidc-authenticating",children:n.jsxs("div",{className:"oidc-authenticating__container",children:[n.jsx("h1",{className:"oidc-authenticating__title",children:"Authentication in progress"}),n.jsx("p",{className:"oidc-authenticating__content",children:"You will be redirected to the login page."})]})}),$=()=>Math.random().toString(36).slice(2,8),G=(t,c)=>(e,o)=>{if(typeof t.CustomEvent=="function")return new t.CustomEvent(e,o);const r=o||{bubbles:!1,cancelable:!1,detail:void 0},i=c.createEvent("CustomEvent");return i.initCustomEvent(e,r.bubbles,r.cancelable,r.detail),i.prototype=t.Event.prototype,i},H=(t,c,e)=>({replaceState:(o,r)=>{const i=e(),d=r||t.history.state;t.history.replaceState({key:i,state:d},null,o),t.dispatchEvent(c("popstate"))}}),Q=()=>H(window,G(window,document),$),U=()=>n.jsx("div",{className:"oidc-callback",children:n.jsxs("div",{className:"oidc-callback__container",children:[n.jsx("h1",{className:"oidc-callback__title",children:"Authentication complete"}),n.jsx("p",{className:"oidc-callback__content",children:"You will be redirected to your application."})]})}),J=({callBackError:t,callBackSuccess:c,configurationName:e,withCustomHistory:o})=>{const[r,i]=l.useState(!1);l.useEffect(()=>{let u=!0;return(async()=>{const O=s.OidcClient.get;try{const{callbackPath:_}=await O(e).loginCallbackAsync();(o?o():Q()).replaceState(_||"/")}catch(_){u&&(console.warn(_),i(!0))}})(),()=>{u=!1}},[]);const d=t||I,a=c||U;return r?n.jsx(d,{configurationName:e}):n.jsx(a,{configurationName:e})},V=()=>n.jsx("span",{className:"oidc-loading",children:"Loading"}),X=()=>n.jsx("div",{className:"oidc-serviceworker",children:n.jsxs("div",{className:"oidc-serviceworker__container",children:[n.jsx("h1",{className:"oidc-serviceworker__title",children:"Unable to authenticate on this browser"}),n.jsx("p",{className:"oidc-serviceworker__content",children:"Your browser is not secure enough to make authentication work. Try updating your browser or use a newer browser."})]})}),Z=()=>n.jsx("div",{className:"oidc-session-lost",children:n.jsxs("div",{className:"oidc-session-lost__container",children:[n.jsx("h1",{className:"oidc-session-lost__title",children:"Session timed out"}),n.jsx("p",{className:"oidc-session-lost__content",children:"Your session has expired. Please re-authenticate."})]})}),x=({configurationName:t})=>(l.useEffect(()=>{(async()=>{s.OidcClient.get(t).silentLoginCallbackAsync()})().catch(e=>{console.error("Error during silent login callback:",e)})},[t]),null),R=({configurationName:t})=>{const c=s.getParseQueryStringFromLocation(window.location.href),e=s.OidcClient.get,o=e(t);let r=null;for(const[i,d]of Object.entries(c))i==="state"||i==="scope"||(r===null&&(r={}),r[i]=d);return l.useEffect(()=>{o.tokens||o.loginAsync(null,r,!0,c.scope)},[]),n.jsx(n.Fragment,{})},ee=({callbackErrorComponent:t,callbackSuccessComponent:c,redirect_uri:e,silent_redirect_uri:o,silent_login_uri:r,children:i,configurationName:d,withCustomHistory:a=null})=>{const u=window?s.getPath(window.location.href):"",[f,O]=l.useState(u);l.useEffect(()=>{const v=()=>O(s.getPath(window.location.href));return v(),window.addEventListener("popstate",v,!1),()=>window.removeEventListener("popstate",v,!1)},[]);const _=s.getPath(e);return o&&f===s.getPath(o)?n.jsx(x,{configurationName:d}):r&&f===s.getPath(r)?n.jsx(R,{configurationName:d}):f===_?n.jsx(J,{callBackError:t,callBackSuccess:c,configurationName:d,withCustomHistory:a}):n.jsx(n.Fragment,{children:i})},te=l.memo(ee),M={name:"",data:null},se=({loadingComponent:t,children:c,configurationName:e})=>{const[o,r]=l.useState(!0),i=s.OidcClient.get,d=i(e);l.useEffect(()=>{let u=!0;return d&&d.tryKeepExistingSessionAsync().then(()=>{u&&r(!1)}),()=>{u=!1}},[e]);const a=t;return n.jsx(n.Fragment,{children:o?n.jsx(a,{configurationName:e}):n.jsx(n.Fragment,{children:c})})},p=({isLoading:t,loadingComponent:c,children:e,configurationName:o})=>{const r=c;return t?n.jsx(r,{configurationName:o,children:e}):n.jsx(n.Fragment,{children:e})},ne=({children:t,configuration:c,configurationName:e="default",callbackSuccessComponent:o=U,authenticatingComponent:r=K,loadingComponent:i=V,serviceWorkerNotSupportedComponent:d=X,authenticatingErrorComponent:a=I,sessionLostComponent:u=Z,onSessionLost:f=null,onLogoutFromAnotherTab:O=null,onLogoutFromSameTab:_=null,withCustomHistory:v=null,onEvent:w=null,getFetch:g=null,location:E=null})=>{if(c&&c.redirect_uri&&c.silent_redirect_uri&&c.redirect_uri===c.silent_redirect_uri)throw new Error("redirect_uri and silent_redirect_uri must be different");const T=(L="default")=>s.OidcClient.getOrCreate(g??s.getFetchDefault,E??new s.OidcLocation)(c,L),[fe,he]=l.useState(!0),[ke,S]=l.useState(M),[_e,Oe]=l.useState(e);l.useEffect(()=>{const N=T(e).subscribeEvents((k,b)=>{w&&w(e,k,b)});return()=>{T(e).removeEventSubscription(N)}},[e,w]),l.useEffect(()=>{const N=T(e).subscribeEvents((k,b)=>{if(k===s.OidcClient.eventNames.refreshTokensAsync_error||k===s.OidcClient.eventNames.syncTokensAsync_error){if(f!=null){f();return}S({name:k,data:b})}else if(k===s.OidcClient.eventNames.logout_from_another_tab){if(O!=null){O();return}S({name:k,data:b})}else k===s.OidcClient.eventNames.logout_from_same_tab?_?.():k===s.OidcClient.eventNames.loginAsync_begin||k===s.OidcClient.eventNames.loginCallbackAsync_end||k===s.OidcClient.eventNames.loginAsync_error||k===s.OidcClient.eventNames.loginCallbackAsync_error?S({name:k,data:b}):k===s.OidcClient.eventNames.service_worker_not_supported_by_browser&&c.service_worker_only===!0&&S({name:k,data:b})});return queueMicrotask(()=>{Oe(e),he(!1)}),()=>{T(e).removeEventSubscription(N),S(M)}},[c,e]);const ve=u,ge=r,y=i,ye=d,be=a,A=fe||_e!==e,C=T(e);switch(ke.name){case s.OidcClient.eventNames.service_worker_not_supported_by_browser:return n.jsx(p,{loadingComponent:y,isLoading:A,configurationName:e,children:n.jsx(ye,{configurationName:e})});case s.OidcClient.eventNames.loginAsync_begin:return n.jsx(p,{loadingComponent:y,isLoading:A,configurationName:e,children:n.jsx(ge,{configurationName:e})});case s.OidcClient.eventNames.loginAsync_error:case s.OidcClient.eventNames.loginCallbackAsync_error:return n.jsx(p,{loadingComponent:y,isLoading:A,configurationName:e,children:n.jsx(be,{configurationName:e})});case s.OidcClient.eventNames.refreshTokensAsync_error:case s.OidcClient.eventNames.syncTokensAsync_error:case s.OidcClient.eventNames.logout_from_another_tab:return n.jsx(p,{loadingComponent:y,isLoading:A,configurationName:e,children:n.jsx(ve,{configurationName:e})});default:return n.jsx(p,{loadingComponent:y,isLoading:A,configurationName:e,children:n.jsx(te,{redirect_uri:C.configuration.redirect_uri,silent_redirect_uri:C.configuration.silent_redirect_uri,silent_login_uri:C.configuration.silent_login_uri,callbackSuccessComponent:o,callbackErrorComponent:a,authenticatingComponent:r,configurationName:e,withCustomHistory:v,location:E??new s.OidcLocation,children:n.jsx(se,{loadingComponent:y,configurationName:e,children:t})})})}},q=({children:t,callbackPath:c=null,extras:e=null,configurationName:o="default"})=>{const r=s.OidcClient.get,i=r(o);return l.useEffect(()=>{i.tokens||i.loginAsync(c,e)},[o,c,e]),i.tokens?n.jsx(n.Fragment,{children:t}):null},ce=(t,c=null,e=null,o="default")=>r=>n.jsx(q,{callbackPath:c,extras:e,configurationName:o,children:n.jsx(t,{...r})}),P="default",D=(t,c)=>{let e=!1;return t(c)&&(e=t(c).tokens!=null),e},oe=(t=P)=>{const c=s.OidcClient.get,[e,o]=l.useState(D(c,t));return l.useEffect(()=>{let a=!0;const u=c(t),f=u.subscribeEvents((O,_)=>{(O===s.OidcClient.eventNames.logout_from_another_tab||O===s.OidcClient.eventNames.logout_from_same_tab||O===s.OidcClient.eventNames.token_acquired)&&a&&o(D(c,t))});return()=>{a=!1,u.removeEventSubscription(f)}},[t]),{login:(a=void 0,u=void 0,f=!1,O=void 0)=>c(t).loginAsync(a,u,!1,O,f),logout:(a=void 0,u=void 0)=>c(t).logoutAsync(a,u),renewTokens:async(a=void 0)=>{const u=await c(t).renewTokensAsync(a);return{accessToken:u.accessToken,accessTokenPayload:u.accessTokenPayload,idToken:u.idToken,idTokenPayload:u.idTokenPayload}},isAuthenticated:e}},W={accessToken:null,accessTokenPayload:null},re=t=>{const c=s.OidcClient.get,e=c(t);if(e.tokens){const o=e.tokens;return{accessToken:o.accessToken,accessTokenPayload:o.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:e.configuration.demonstrating_proof_of_possession?(r,i)=>e.generateDemonstrationOfProofOfPossessionAsync(o.accessToken,r,i):null}}return W};function ie(t,c){return t.configuration.demonstrating_proof_of_possession?(e,o,r={})=>t.generateDemonstrationOfProofOfPossessionAsync(c.accessToken,e,o,r):null}const ae=(t=P)=>{const c=s.OidcClient.get,[e,o]=l.useState(()=>re(t));return l.useEffect(()=>{let r=!0;const i=c(t),d=i.subscribeEvents((a,u)=>{if((a===s.OidcClient.eventNames.token_renewed||a===s.OidcClient.eventNames.token_acquired||a===s.OidcClient.eventNames.logout_from_another_tab||a===s.OidcClient.eventNames.logout_from_same_tab||a===s.OidcClient.eventNames.refreshTokensAsync_error||a===s.OidcClient.eventNames.syncTokensAsync_error)&&r){const f=i.tokens;o(f!=null?{accessToken:f.accessToken,accessTokenPayload:f.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:ie(i,f)}:W)}});return()=>{r=!1,i.removeEventSubscription(d)}},[t]),e},j={idToken:null,idTokenPayload:null},le=t=>{const c=s.OidcClient.get,e=c(t);if(e.tokens){const o=e.tokens;return{idToken:o.idToken,idTokenPayload:o.idTokenPayload}}return j},de=(t=P)=>{const c=s.OidcClient.get,[e,o]=l.useState(()=>le(t));return l.useEffect(()=>{let r=!0;const i=c(t),d=i.subscribeEvents((a,u)=>{if((a===s.OidcClient.eventNames.token_renewed||a===s.OidcClient.eventNames.token_acquired||a===s.OidcClient.eventNames.logout_from_another_tab||a===s.OidcClient.eventNames.logout_from_same_tab||a===s.OidcClient.eventNames.refreshTokensAsync_error||a===s.OidcClient.eventNames.syncTokensAsync_error)&&r){const f=i.tokens;o(f!=null?{idToken:f.idToken,idTokenPayload:f.idTokenPayload}:j)}});return()=>{r=!1,i.removeEventSubscription(d)}},[t]),e};var Y=(t=>(t.Unauthenticated="Unauthenticated",t.Loading="Loading user",t.Loaded="User loaded",t.LoadingError="Error loading user",t))(Y||{});const ue=(t="default",c=!1)=>{const o=s.OidcClient.get(t).userInfo(),[r,i]=l.useState({user:o,status:o?"User loaded":"Unauthenticated"}),[d,a]=l.useState(o?1:0),[u,f]=l.useState(o?1:0);l.useEffect(()=>{const _=s.OidcClient.get(t);let v=!0;if(_&&_.tokens){const g=d===u;if(g&&_.userInfo())return;queueMicrotask(()=>{v&&(i({...r,status:"Loading user"}),f(d))}),_.userInfoAsync(!g,c).then(E=>{v&&i({user:E,status:"User loaded"})}).catch(()=>i({...r,status:"Error loading user"}))}else queueMicrotask(()=>{v&&i({user:null,status:"Unauthenticated"})});const w=_.subscribeEvents(g=>{(g===s.OidcClient.eventNames.logout_from_another_tab||g===s.OidcClient.eventNames.logout_from_same_tab)&&v&&i({user:null,status:"Unauthenticated"})});return()=>{v=!1,_.removeEventSubscription(w)}},[d]);const O=()=>{a(d+1)};return{oidcUser:r.user,oidcUserLoadingState:r.status,reloadOidcUser:O}};Object.defineProperty(h,"OidcClient",{enumerable:!0,get:()=>s.OidcClient}),Object.defineProperty(h,"OidcLocation",{enumerable:!0,get:()=>s.OidcLocation}),Object.defineProperty(h,"TokenAutomaticRenewMode",{enumerable:!0,get:()=>s.TokenAutomaticRenewMode}),Object.defineProperty(h,"TokenRenewMode",{enumerable:!0,get:()=>s.TokenRenewMode}),h.OidcProvider=ne,h.OidcSecure=q,h.OidcUserStatus=Y,h.useOidc=oe,h.useOidcAccessToken=ae,h.useOidcFetch=F,h.useOidcIdToken=de,h.useOidcUser=ue,h.withOidcFetch=z,h.withOidcSecure=ce,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axa-fr/react-oidc",
|
|
3
|
-
"version": "7.26.
|
|
3
|
+
"version": "7.26.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.umd.cjs",
|
|
@@ -40,31 +40,31 @@
|
|
|
40
40
|
"lint": "eslint src"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@axa-fr/oidc-client-service-worker": "7.26.
|
|
44
|
-
"@axa-fr/oidc-client": "7.26.
|
|
43
|
+
"@axa-fr/oidc-client-service-worker": "7.26.3",
|
|
44
|
+
"@axa-fr/oidc-client": "7.26.3"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"react": "^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@testing-library/jest-dom": "6.
|
|
51
|
-
"@testing-library/react": "16.3.
|
|
50
|
+
"@testing-library/jest-dom": "6.9.1",
|
|
51
|
+
"@testing-library/react": "16.3.2",
|
|
52
52
|
"@testing-library/user-event": "14.6.1",
|
|
53
|
-
"@types/react": "19.
|
|
54
|
-
"@vitejs/plugin-react": "
|
|
55
|
-
"@vitest/coverage-v8": "
|
|
56
|
-
"cpy": "
|
|
57
|
-
"cpy-cli": "^
|
|
58
|
-
"cross-env": "^
|
|
59
|
-
"jsdom": "
|
|
60
|
-
"msw": "2.7
|
|
61
|
-
"react": "^19.
|
|
62
|
-
"react-dom": "^19.
|
|
63
|
-
"rimraf": "6.
|
|
64
|
-
"typescript": "5.
|
|
65
|
-
"vite": "
|
|
66
|
-
"vite-plugin-dts": "4.5.
|
|
67
|
-
"vitest": "
|
|
53
|
+
"@types/react": "19.2.10",
|
|
54
|
+
"@vitejs/plugin-react": "5.1.2",
|
|
55
|
+
"@vitest/coverage-v8": "4.0.18",
|
|
56
|
+
"cpy": "12.1.0",
|
|
57
|
+
"cpy-cli": "^6.0.0",
|
|
58
|
+
"cross-env": "^10.1.0",
|
|
59
|
+
"jsdom": "27.4.0",
|
|
60
|
+
"msw": "2.12.7",
|
|
61
|
+
"react": "^19.2.4",
|
|
62
|
+
"react-dom": "^19.2.4",
|
|
63
|
+
"rimraf": "6.1.2",
|
|
64
|
+
"typescript": "5.9.3",
|
|
65
|
+
"vite": "7.3.1",
|
|
66
|
+
"vite-plugin-dts": "4.5.4",
|
|
67
|
+
"vitest": "4.0.18"
|
|
68
68
|
},
|
|
69
69
|
"license": "MIT",
|
|
70
70
|
"publishConfig": {
|
package/src/FetchToken.tsx
CHANGED
package/src/OidcProvider.tsx
CHANGED
|
@@ -117,7 +117,7 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
|
|
|
117
117
|
|
|
118
118
|
const [loading, setLoading] = useState(true);
|
|
119
119
|
const [event, setEvent] = useState(defaultEventState);
|
|
120
|
-
const [currentConfigurationName, setConfigurationName] = useState(
|
|
120
|
+
const [currentConfigurationName, setConfigurationName] = useState(configurationName);
|
|
121
121
|
|
|
122
122
|
useEffect(() => {
|
|
123
123
|
const oidc = getOidc(configurationName);
|
|
@@ -170,8 +170,11 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
|
|
|
170
170
|
}
|
|
171
171
|
});
|
|
172
172
|
|
|
173
|
-
|
|
174
|
-
|
|
173
|
+
queueMicrotask(() => {
|
|
174
|
+
setConfigurationName(configurationName);
|
|
175
|
+
setLoading(false);
|
|
176
|
+
});
|
|
177
|
+
|
|
175
178
|
return () => {
|
|
176
179
|
const previousOidc = getOidc(configurationName);
|
|
177
180
|
previousOidc.removeEventSubscription(newSubscriptionId);
|
package/src/ReactOidc.tsx
CHANGED
|
@@ -25,7 +25,6 @@ export const useOidc = (configurationName = defaultConfigurationName) => {
|
|
|
25
25
|
useEffect(() => {
|
|
26
26
|
let isMounted = true;
|
|
27
27
|
const oidc = getOidc(configurationName);
|
|
28
|
-
setIsAuthenticated(defaultIsAuthenticated(getOidc, configurationName));
|
|
29
28
|
|
|
30
29
|
const newSubscriptionId = oidc.subscribeEvents((name: string, data: any) => {
|
|
31
30
|
if (
|
|
@@ -118,18 +117,11 @@ function getGenerateDemonstrationOfProofOfPossessionAsync(oidc: OidcClient, toke
|
|
|
118
117
|
|
|
119
118
|
export const useOidcAccessToken = (configurationName = defaultConfigurationName) => {
|
|
120
119
|
const getOidc = OidcClient.get;
|
|
121
|
-
const [state, setAccessToken] = useState<OidcAccessToken>(initTokens(configurationName));
|
|
120
|
+
const [state, setAccessToken] = useState<OidcAccessToken>(() => initTokens(configurationName));
|
|
122
121
|
|
|
123
122
|
useEffect(() => {
|
|
124
123
|
let isMounted = true;
|
|
125
124
|
const oidc = getOidc(configurationName);
|
|
126
|
-
if (oidc.tokens) {
|
|
127
|
-
const tokens = oidc.tokens;
|
|
128
|
-
setAccessToken({
|
|
129
|
-
accessToken: tokens.accessToken,
|
|
130
|
-
accessTokenPayload: tokens.accessTokenPayload,
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
125
|
|
|
134
126
|
const newSubscriptionId = oidc.subscribeEvents((name: string, data: any) => {
|
|
135
127
|
if (
|
|
@@ -183,15 +175,11 @@ export type OidcIdToken = {
|
|
|
183
175
|
|
|
184
176
|
export const useOidcIdToken = (configurationName = defaultConfigurationName) => {
|
|
185
177
|
const getOidc = OidcClient.get;
|
|
186
|
-
const [state, setIDToken] = useState<OidcIdToken>(initIdToken(configurationName));
|
|
178
|
+
const [state, setIDToken] = useState<OidcIdToken>(() => initIdToken(configurationName));
|
|
187
179
|
|
|
188
180
|
useEffect(() => {
|
|
189
181
|
let isMounted = true;
|
|
190
182
|
const oidc = getOidc(configurationName);
|
|
191
|
-
if (oidc.tokens) {
|
|
192
|
-
const tokens = oidc.tokens;
|
|
193
|
-
setIDToken({ idToken: tokens.idToken, idTokenPayload: tokens.idTokenPayload });
|
|
194
|
-
}
|
|
195
183
|
|
|
196
184
|
const newSubscriptionId = oidc.subscribeEvents((name: string, data: any) => {
|
|
197
185
|
if (
|
package/src/User.ts
CHANGED
|
@@ -34,7 +34,13 @@ export const useOidcUser = <T extends OidcUserInfo = OidcUserInfo>(
|
|
|
34
34
|
if (isCache && oidc.userInfo<T>()) {
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
// Use queueMicrotask to defer setState to avoid synchronous call in effect
|
|
38
|
+
queueMicrotask(() => {
|
|
39
|
+
if (isMounted) {
|
|
40
|
+
setOidcUser({ ...oidcUser, status: OidcUserStatus.Loading });
|
|
41
|
+
setPreviousOidcUserId(oidcUserId);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
38
44
|
oidc
|
|
39
45
|
.userInfoAsync(!isCache, demonstrating_proof_of_possession)
|
|
40
46
|
.then(info => {
|
|
@@ -44,9 +50,12 @@ export const useOidcUser = <T extends OidcUserInfo = OidcUserInfo>(
|
|
|
44
50
|
}
|
|
45
51
|
})
|
|
46
52
|
.catch(() => setOidcUser({ ...oidcUser, status: OidcUserStatus.LoadingError }));
|
|
47
|
-
setPreviousOidcUserId(oidcUserId);
|
|
48
53
|
} else {
|
|
49
|
-
|
|
54
|
+
queueMicrotask(() => {
|
|
55
|
+
if (isMounted) {
|
|
56
|
+
setOidcUser({ user: null, status: OidcUserStatus.Unauthenticated });
|
|
57
|
+
}
|
|
58
|
+
});
|
|
50
59
|
}
|
|
51
60
|
const newSubscriptionId = oidc.subscribeEvents((name: string) => {
|
|
52
61
|
if (
|
|
@@ -1,16 +1,30 @@
|
|
|
1
1
|
import { render } from '@testing-library/react';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
4
|
|
|
5
5
|
import OidcRoutes from './OidcRoutes';
|
|
6
6
|
|
|
7
7
|
describe('Authenticating test suite', () => {
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
// Mock window.location
|
|
10
|
+
delete (window as any).location;
|
|
11
|
+
window.location = { href: 'http://example.com:3000/' } as any;
|
|
12
|
+
|
|
13
|
+
// Mock window event listeners
|
|
14
|
+
window.addEventListener = vi.fn();
|
|
15
|
+
window.removeEventListener = vi.fn();
|
|
16
|
+
});
|
|
17
|
+
|
|
8
18
|
it('renders correctly', () => {
|
|
9
19
|
const props = {
|
|
10
20
|
children: 'http://url.com',
|
|
11
|
-
callbackComponent: () => <div>tcallback component</div>,
|
|
12
21
|
redirect_uri: 'http://example.com:3000/authentication/callback',
|
|
13
22
|
configurationName: '',
|
|
23
|
+
location: {
|
|
24
|
+
pathname: '/',
|
|
25
|
+
search: '',
|
|
26
|
+
hash: '',
|
|
27
|
+
},
|
|
14
28
|
};
|
|
15
29
|
const { asFragment } = render(<OidcRoutes {...props} />);
|
|
16
30
|
expect(asFragment()).toMatchSnapshot();
|
|
@@ -7,7 +7,7 @@ describe('WithRouter test Suite', () => {
|
|
|
7
7
|
beforeEach(() => {});
|
|
8
8
|
it('should CreateEvent return correct Event if not on IE', () => {
|
|
9
9
|
const windowMock = {
|
|
10
|
-
CustomEvent: vi.fn(
|
|
10
|
+
CustomEvent: vi.fn(function (event, params) {
|
|
11
11
|
return { event, params };
|
|
12
12
|
}),
|
|
13
13
|
};
|