@axa-fr/react-oidc 7.26.1-alpha.1797 → 7.26.4
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 +257 -273
- package/dist/index.umd.cjs +1 -1
- package/package.json +20 -20
- package/src/FetchToken.tsx +1 -1
- package/src/OidcProvider.tsx +11 -4
- package/src/ReactOidc.tsx +3 -15
- package/src/User.ts +13 -4
- 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,CAoLjE,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,445 +1,429 @@
|
|
|
1
|
-
import { jsx as i, jsxs as
|
|
2
|
-
import { OidcClient as
|
|
3
|
-
import { OidcClient as
|
|
4
|
-
import
|
|
5
|
-
const x = "default",
|
|
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 Q, getPath as O, OidcLocation as F, getFetchDefault as J } from "@axa-fr/oidc-client";
|
|
3
|
+
import { OidcClient as Ue, OidcLocation as Me, TokenAutomaticRenewMode as Fe, TokenRenewMode as qe } from "@axa-fr/oidc-client";
|
|
4
|
+
import V, { useCallback as X, useState as p, useEffect as v } from "react";
|
|
5
|
+
const x = "default", Z = (t, s, e = !1) => async (...n) => await s().fetchWithTokens(t, e)(...n), Ce = (t = null, s = x, e = !1) => (n) => (o) => {
|
|
6
|
+
const { fetch: r } = ee(
|
|
7
7
|
t || o.fetch,
|
|
8
|
-
|
|
8
|
+
s,
|
|
9
9
|
e
|
|
10
10
|
);
|
|
11
|
-
return /* @__PURE__ */ i(
|
|
12
|
-
},
|
|
13
|
-
const
|
|
14
|
-
return { fetch:
|
|
15
|
-
(
|
|
16
|
-
|
|
17
|
-
() => o(
|
|
11
|
+
return /* @__PURE__ */ i(n, { ...o, fetch: r });
|
|
12
|
+
}, ee = (t = null, s = x, e = !1) => {
|
|
13
|
+
const n = t || window.fetch, o = c.get;
|
|
14
|
+
return { fetch: X(
|
|
15
|
+
(d, l) => Z(
|
|
16
|
+
n,
|
|
17
|
+
() => o(s),
|
|
18
18
|
e
|
|
19
|
-
)(
|
|
20
|
-
[s,
|
|
19
|
+
)(d, l),
|
|
20
|
+
[n, s, e]
|
|
21
21
|
) };
|
|
22
|
-
}, W = () => /* @__PURE__ */ i("div", { className: "oidc-authenticating", children: /* @__PURE__ */
|
|
22
|
+
}, W = () => /* @__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
|
-
] }) }),
|
|
25
|
+
] }) }), te = () => /* @__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
|
+
] }) }), se = () => Math.random().toString(36).slice(2, 8), ne = (t, s) => (e, n) => {
|
|
29
29
|
if (typeof t.CustomEvent == "function")
|
|
30
|
-
return new t.CustomEvent(e,
|
|
31
|
-
const o =
|
|
32
|
-
return
|
|
30
|
+
return new t.CustomEvent(e, n);
|
|
31
|
+
const o = n || { bubbles: !1, cancelable: !1, detail: void 0 }, r = s.createEvent("CustomEvent");
|
|
32
|
+
return r.initCustomEvent(
|
|
33
33
|
e,
|
|
34
34
|
o.bubbles,
|
|
35
35
|
o.cancelable,
|
|
36
36
|
o.detail
|
|
37
|
-
),
|
|
38
|
-
},
|
|
39
|
-
replaceState: (
|
|
40
|
-
const
|
|
41
|
-
t.history.replaceState({ key:
|
|
37
|
+
), r.prototype = t.Event.prototype, r;
|
|
38
|
+
}, oe = (t, s, e) => ({
|
|
39
|
+
replaceState: (n, o) => {
|
|
40
|
+
const r = e(), d = o || t.history.state;
|
|
41
|
+
t.history.replaceState({ key: r, state: d }, null, n), t.dispatchEvent(s("popstate"));
|
|
42
42
|
}
|
|
43
|
-
}),
|
|
43
|
+
}), ce = () => oe(window, ne(window, document), se), R = () => /* @__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
|
+
] }) }), re = ({
|
|
47
47
|
callBackError: t,
|
|
48
|
-
callBackSuccess:
|
|
48
|
+
callBackSuccess: s,
|
|
49
49
|
configurationName: e,
|
|
50
|
-
withCustomHistory:
|
|
50
|
+
withCustomHistory: n
|
|
51
51
|
}) => {
|
|
52
|
-
const [o,
|
|
53
|
-
|
|
54
|
-
let
|
|
52
|
+
const [o, r] = p(!1);
|
|
53
|
+
v(() => {
|
|
54
|
+
let a = !0;
|
|
55
55
|
return (async () => {
|
|
56
|
-
const _ =
|
|
56
|
+
const _ = c.get;
|
|
57
57
|
try {
|
|
58
|
-
const { callbackPath:
|
|
59
|
-
(
|
|
60
|
-
} catch (
|
|
61
|
-
|
|
58
|
+
const { callbackPath: k } = await _(e).loginCallbackAsync();
|
|
59
|
+
(n ? n() : ce()).replaceState(k || "/");
|
|
60
|
+
} catch (k) {
|
|
61
|
+
a && (console.warn(k), r(!0));
|
|
62
62
|
}
|
|
63
63
|
})(), () => {
|
|
64
|
-
|
|
64
|
+
a = !1;
|
|
65
65
|
};
|
|
66
66
|
}, []);
|
|
67
|
-
const
|
|
68
|
-
return o ? /* @__PURE__ */ i(
|
|
69
|
-
},
|
|
67
|
+
const d = t || W, l = s || R;
|
|
68
|
+
return o ? /* @__PURE__ */ i(d, { configurationName: e }) : /* @__PURE__ */ i(l, { configurationName: e });
|
|
69
|
+
}, ie = () => /* @__PURE__ */ i("span", { className: "oidc-loading", children: "Loading" }), le = () => /* @__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
|
-
] }) }),
|
|
72
|
+
] }) }), ae = () => /* @__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
|
+
] }) }), de = ({ configurationName: t }) => (v(() => {
|
|
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
|
|
81
|
+
}, [t]), null), ue = ({ configurationName: t }) => {
|
|
82
|
+
const s = Q(window.location.href), e = c.get, n = e(t);
|
|
83
83
|
let o = null;
|
|
84
|
-
for (const [
|
|
85
|
-
|
|
86
|
-
return
|
|
87
|
-
|
|
84
|
+
for (const [r, d] of Object.entries(s))
|
|
85
|
+
r === "state" || r === "scope" || (o === null && (o = {}), o[r] = d);
|
|
86
|
+
return v(() => {
|
|
87
|
+
n.tokens || n.loginAsync(null, o, !0, s.scope);
|
|
88
88
|
}, []), /* @__PURE__ */ i(m, {});
|
|
89
|
-
},
|
|
89
|
+
}, he = ({
|
|
90
90
|
callbackErrorComponent: t,
|
|
91
|
-
callbackSuccessComponent:
|
|
91
|
+
callbackSuccessComponent: s,
|
|
92
92
|
redirect_uri: e,
|
|
93
|
-
silent_redirect_uri:
|
|
93
|
+
silent_redirect_uri: n,
|
|
94
94
|
silent_login_uri: o,
|
|
95
|
-
children:
|
|
96
|
-
configurationName:
|
|
97
|
-
withCustomHistory:
|
|
95
|
+
children: r,
|
|
96
|
+
configurationName: d,
|
|
97
|
+
withCustomHistory: l = null
|
|
98
98
|
}) => {
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
return
|
|
99
|
+
const a = window ? O(window.location.href) : "", [u, _] = p(a);
|
|
100
|
+
v(() => {
|
|
101
|
+
const f = () => _(O(window.location.href));
|
|
102
|
+
return f(), window.addEventListener("popstate", f, !1), () => window.removeEventListener("popstate", f, !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 n && u === O(n) ? /* @__PURE__ */ i(de, { configurationName: d }) : o && u === O(o) ? /* @__PURE__ */ i(ue, { configurationName: d }) : u === k ? /* @__PURE__ */ i(
|
|
106
|
+
re,
|
|
107
|
+
{
|
|
108
|
+
callBackError: t,
|
|
109
|
+
callBackSuccess: s,
|
|
110
|
+
configurationName: d,
|
|
111
|
+
withCustomHistory: l
|
|
112
|
+
}
|
|
113
|
+
) : /* @__PURE__ */ i(m, { children: r });
|
|
114
|
+
}, ke = V.memo(he), q = { name: "", data: null }, _e = ({
|
|
124
115
|
loadingComponent: t,
|
|
125
|
-
children:
|
|
116
|
+
children: s,
|
|
126
117
|
configurationName: e
|
|
127
118
|
}) => {
|
|
128
|
-
const [
|
|
129
|
-
return
|
|
130
|
-
let
|
|
131
|
-
return
|
|
132
|
-
|
|
119
|
+
const [n, o] = p(!0), r = c.get, d = r(e);
|
|
120
|
+
return v(() => {
|
|
121
|
+
let a = !0;
|
|
122
|
+
return d && d.tryKeepExistingSessionAsync().then(() => {
|
|
123
|
+
a && o(!1);
|
|
133
124
|
}), () => {
|
|
134
|
-
|
|
125
|
+
a = !1;
|
|
135
126
|
};
|
|
136
|
-
}, [e]), /* @__PURE__ */ i(m, { children:
|
|
137
|
-
},
|
|
138
|
-
const o =
|
|
139
|
-
return t ? /* @__PURE__ */ i(o, { configurationName:
|
|
140
|
-
},
|
|
127
|
+
}, [e]), /* @__PURE__ */ i(m, { children: n ? /* @__PURE__ */ i(t, { configurationName: e }) : /* @__PURE__ */ i(m, { children: s }) });
|
|
128
|
+
}, E = ({ isLoading: t, loadingComponent: s, children: e, configurationName: n }) => {
|
|
129
|
+
const o = s;
|
|
130
|
+
return t ? /* @__PURE__ */ i(o, { configurationName: n, children: e }) : /* @__PURE__ */ i(m, { children: e });
|
|
131
|
+
}, Ae = ({
|
|
141
132
|
children: t,
|
|
142
|
-
configuration:
|
|
133
|
+
configuration: s,
|
|
143
134
|
configurationName: e = "default",
|
|
144
|
-
callbackSuccessComponent:
|
|
145
|
-
authenticatingComponent: o =
|
|
146
|
-
loadingComponent:
|
|
147
|
-
serviceWorkerNotSupportedComponent:
|
|
148
|
-
authenticatingErrorComponent:
|
|
149
|
-
sessionLostComponent:
|
|
135
|
+
callbackSuccessComponent: n = R,
|
|
136
|
+
authenticatingComponent: o = te,
|
|
137
|
+
loadingComponent: r = ie,
|
|
138
|
+
serviceWorkerNotSupportedComponent: d = le,
|
|
139
|
+
authenticatingErrorComponent: l = W,
|
|
140
|
+
sessionLostComponent: a = ae,
|
|
150
141
|
onSessionLost: u = null,
|
|
151
142
|
onLogoutFromAnotherTab: _ = null,
|
|
152
|
-
onLogoutFromSameTab:
|
|
153
|
-
withCustomHistory:
|
|
154
|
-
onEvent:
|
|
143
|
+
onLogoutFromSameTab: k = null,
|
|
144
|
+
withCustomHistory: f = null,
|
|
145
|
+
onEvent: w = null,
|
|
155
146
|
getFetch: y = null,
|
|
156
|
-
location:
|
|
147
|
+
location: P = null
|
|
157
148
|
}) => {
|
|
158
|
-
if (
|
|
149
|
+
if (s && s.redirect_uri && s.silent_redirect_uri && s.redirect_uri === s.silent_redirect_uri)
|
|
159
150
|
throw new Error("redirect_uri and silent_redirect_uri must be different");
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
), [
|
|
164
|
-
|
|
165
|
-
const I =
|
|
166
|
-
|
|
151
|
+
const T = (N = "default") => c.getOrCreate(y ?? J, P ?? new F())(
|
|
152
|
+
s,
|
|
153
|
+
N
|
|
154
|
+
), [B, C] = p(q), [z, M] = p(e);
|
|
155
|
+
v(() => {
|
|
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]), v(() => {
|
|
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 && s.service_worker_only === !0 && C({ name: h, data: g });
|
|
186
177
|
});
|
|
187
|
-
return
|
|
188
|
-
|
|
178
|
+
return queueMicrotask(() => {
|
|
179
|
+
M(e), setLoading(!1);
|
|
180
|
+
}), () => {
|
|
181
|
+
T(e).removeEventSubscription(I), C(q);
|
|
189
182
|
};
|
|
190
|
-
}, [
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
183
|
+
}, [s, e]), v(() => {
|
|
184
|
+
M(e);
|
|
185
|
+
}, [e]);
|
|
186
|
+
const K = a, $ = o, b = r, G = d, H = l, A = z !== e, L = T(e);
|
|
187
|
+
switch (B.name) {
|
|
188
|
+
case c.eventNames.service_worker_not_supported_by_browser:
|
|
194
189
|
return /* @__PURE__ */ i(
|
|
195
|
-
|
|
190
|
+
E,
|
|
196
191
|
{
|
|
197
|
-
loadingComponent:
|
|
192
|
+
loadingComponent: b,
|
|
198
193
|
isLoading: A,
|
|
199
194
|
configurationName: e,
|
|
200
|
-
children: /* @__PURE__ */ i(
|
|
195
|
+
children: /* @__PURE__ */ i(G, { configurationName: e })
|
|
201
196
|
}
|
|
202
197
|
);
|
|
203
|
-
case
|
|
198
|
+
case c.eventNames.loginAsync_begin:
|
|
204
199
|
return /* @__PURE__ */ i(
|
|
205
|
-
|
|
200
|
+
E,
|
|
206
201
|
{
|
|
207
|
-
loadingComponent:
|
|
202
|
+
loadingComponent: b,
|
|
208
203
|
isLoading: A,
|
|
209
204
|
configurationName: e,
|
|
210
|
-
children: /* @__PURE__ */ i(
|
|
205
|
+
children: /* @__PURE__ */ i($, { configurationName: e })
|
|
211
206
|
}
|
|
212
207
|
);
|
|
213
|
-
case
|
|
214
|
-
case
|
|
208
|
+
case c.eventNames.loginAsync_error:
|
|
209
|
+
case c.eventNames.loginCallbackAsync_error:
|
|
215
210
|
return /* @__PURE__ */ i(
|
|
216
|
-
|
|
211
|
+
E,
|
|
217
212
|
{
|
|
218
|
-
loadingComponent:
|
|
213
|
+
loadingComponent: b,
|
|
219
214
|
isLoading: A,
|
|
220
215
|
configurationName: e,
|
|
221
|
-
children: /* @__PURE__ */ i(
|
|
216
|
+
children: /* @__PURE__ */ i(H, { configurationName: e })
|
|
222
217
|
}
|
|
223
218
|
);
|
|
224
|
-
case
|
|
225
|
-
case
|
|
226
|
-
case
|
|
219
|
+
case c.eventNames.refreshTokensAsync_error:
|
|
220
|
+
case c.eventNames.syncTokensAsync_error:
|
|
221
|
+
case c.eventNames.logout_from_another_tab:
|
|
227
222
|
return /* @__PURE__ */ i(
|
|
228
|
-
|
|
223
|
+
E,
|
|
229
224
|
{
|
|
230
|
-
loadingComponent:
|
|
225
|
+
loadingComponent: b,
|
|
231
226
|
isLoading: A,
|
|
232
227
|
configurationName: e,
|
|
233
|
-
children: /* @__PURE__ */ i(
|
|
228
|
+
children: /* @__PURE__ */ i(K, { configurationName: e })
|
|
234
229
|
}
|
|
235
230
|
);
|
|
236
231
|
default:
|
|
237
232
|
return /* @__PURE__ */ i(
|
|
238
|
-
|
|
233
|
+
E,
|
|
239
234
|
{
|
|
240
|
-
loadingComponent:
|
|
235
|
+
loadingComponent: b,
|
|
241
236
|
isLoading: A,
|
|
242
237
|
configurationName: e,
|
|
243
238
|
children: /* @__PURE__ */ i(
|
|
244
|
-
|
|
239
|
+
ke,
|
|
245
240
|
{
|
|
246
|
-
redirect_uri:
|
|
247
|
-
silent_redirect_uri:
|
|
248
|
-
silent_login_uri:
|
|
249
|
-
callbackSuccessComponent:
|
|
250
|
-
callbackErrorComponent:
|
|
241
|
+
redirect_uri: L.configuration.redirect_uri,
|
|
242
|
+
silent_redirect_uri: L.configuration.silent_redirect_uri,
|
|
243
|
+
silent_login_uri: L.configuration.silent_login_uri,
|
|
244
|
+
callbackSuccessComponent: n,
|
|
245
|
+
callbackErrorComponent: l,
|
|
251
246
|
authenticatingComponent: o,
|
|
252
247
|
configurationName: e,
|
|
253
|
-
withCustomHistory:
|
|
254
|
-
location:
|
|
255
|
-
children: /* @__PURE__ */ i(
|
|
248
|
+
withCustomHistory: f,
|
|
249
|
+
location: P ?? new F(),
|
|
250
|
+
children: /* @__PURE__ */ i(_e, { loadingComponent: b, configurationName: e, children: t })
|
|
256
251
|
}
|
|
257
252
|
)
|
|
258
253
|
}
|
|
259
254
|
);
|
|
260
255
|
}
|
|
261
|
-
},
|
|
256
|
+
}, ve = ({
|
|
262
257
|
children: t,
|
|
263
|
-
callbackPath:
|
|
258
|
+
callbackPath: s = null,
|
|
264
259
|
extras: e = null,
|
|
265
|
-
configurationName:
|
|
260
|
+
configurationName: n = "default"
|
|
266
261
|
}) => {
|
|
267
|
-
const o =
|
|
268
|
-
return
|
|
269
|
-
|
|
270
|
-
}, [
|
|
271
|
-
},
|
|
262
|
+
const o = c.get, r = o(n);
|
|
263
|
+
return v(() => {
|
|
264
|
+
r.tokens || r.loginAsync(s, e);
|
|
265
|
+
}, [n, s, e]), r.tokens ? /* @__PURE__ */ i(m, { children: t }) : null;
|
|
266
|
+
}, Oe = (t, s = null, e = null, n = "default") => (o) => /* @__PURE__ */ i(ve, { callbackPath: s, extras: e, configurationName: n, children: /* @__PURE__ */ i(t, { ...o }) }), U = "default", D = (t, s) => {
|
|
272
267
|
let e = !1;
|
|
273
|
-
return t(
|
|
274
|
-
},
|
|
275
|
-
const
|
|
276
|
-
|
|
268
|
+
return t(s) && (e = t(s).tokens != null), e;
|
|
269
|
+
}, Ee = (t = U) => {
|
|
270
|
+
const s = c.get, [e, n] = p(
|
|
271
|
+
() => D(s, t)
|
|
277
272
|
);
|
|
278
|
-
return
|
|
279
|
-
let
|
|
280
|
-
const
|
|
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));
|
|
273
|
+
return v(() => {
|
|
274
|
+
let l = !0;
|
|
275
|
+
const a = s(t), u = a.subscribeEvents((_, k) => {
|
|
276
|
+
(_ === c.eventNames.logout_from_another_tab || _ === c.eventNames.logout_from_same_tab || _ === c.eventNames.token_acquired) && l && n(D(s, t));
|
|
284
277
|
});
|
|
285
278
|
return () => {
|
|
286
|
-
|
|
279
|
+
l = !1, a.removeEventSubscription(u);
|
|
287
280
|
};
|
|
288
|
-
}, [t]), { login: (
|
|
281
|
+
}, [t]), { login: (l = void 0, a = void 0, u = !1, _ = void 0) => s(t).loginAsync(
|
|
282
|
+
l,
|
|
289
283
|
a,
|
|
290
|
-
d,
|
|
291
284
|
!1,
|
|
292
285
|
_,
|
|
293
286
|
u
|
|
294
|
-
), logout: (
|
|
295
|
-
const
|
|
287
|
+
), logout: (l = void 0, a = void 0) => s(t).logoutAsync(l, a), renewTokens: async (l = void 0) => {
|
|
288
|
+
const a = await s(t).renewTokensAsync(l);
|
|
296
289
|
return {
|
|
297
290
|
// @ts-ignore
|
|
298
|
-
accessToken:
|
|
291
|
+
accessToken: a.accessToken,
|
|
299
292
|
// @ts-ignore
|
|
300
|
-
accessTokenPayload:
|
|
293
|
+
accessTokenPayload: a.accessTokenPayload,
|
|
301
294
|
// @ts-ignore
|
|
302
|
-
idToken:
|
|
295
|
+
idToken: a.idToken,
|
|
303
296
|
// @ts-ignore
|
|
304
|
-
idTokenPayload:
|
|
297
|
+
idTokenPayload: a.idTokenPayload
|
|
305
298
|
};
|
|
306
299
|
}, isAuthenticated: e };
|
|
307
|
-
},
|
|
308
|
-
const
|
|
300
|
+
}, Y = { accessToken: null, accessTokenPayload: null }, fe = (t) => {
|
|
301
|
+
const s = c.get, e = s(t);
|
|
309
302
|
if (e.tokens) {
|
|
310
|
-
const
|
|
303
|
+
const n = e.tokens;
|
|
311
304
|
return {
|
|
312
|
-
accessToken:
|
|
313
|
-
accessTokenPayload:
|
|
314
|
-
generateDemonstrationOfProofOfPossessionAsync: e.configuration.demonstrating_proof_of_possession ? (o,
|
|
305
|
+
accessToken: n.accessToken,
|
|
306
|
+
accessTokenPayload: n.accessTokenPayload,
|
|
307
|
+
generateDemonstrationOfProofOfPossessionAsync: e.configuration.demonstrating_proof_of_possession ? (o, r) => e.generateDemonstrationOfProofOfPossessionAsync(n.accessToken, o, r) : null
|
|
315
308
|
};
|
|
316
309
|
}
|
|
317
|
-
return
|
|
310
|
+
return Y;
|
|
318
311
|
};
|
|
319
|
-
function
|
|
320
|
-
return t.configuration.demonstrating_proof_of_possession ? (e,
|
|
312
|
+
function pe(t, s) {
|
|
313
|
+
return t.configuration.demonstrating_proof_of_possession ? (e, n, o = {}) => t.generateDemonstrationOfProofOfPossessionAsync(s.accessToken, e, n, o) : null;
|
|
321
314
|
}
|
|
322
|
-
const
|
|
323
|
-
const
|
|
324
|
-
return
|
|
315
|
+
const Se = (t = U) => {
|
|
316
|
+
const s = c.get, [e, n] = p(() => fe(t));
|
|
317
|
+
return v(() => {
|
|
325
318
|
let o = !0;
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
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;
|
|
337
|
-
s(
|
|
319
|
+
const r = s(t), d = r.subscribeEvents((l, a) => {
|
|
320
|
+
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) {
|
|
321
|
+
const u = r.tokens;
|
|
322
|
+
n(
|
|
338
323
|
u != null ? {
|
|
339
324
|
accessToken: u.accessToken,
|
|
340
325
|
accessTokenPayload: u.accessTokenPayload,
|
|
341
|
-
generateDemonstrationOfProofOfPossessionAsync:
|
|
342
|
-
} :
|
|
326
|
+
generateDemonstrationOfProofOfPossessionAsync: pe(r, u)
|
|
327
|
+
} : Y
|
|
343
328
|
);
|
|
344
329
|
}
|
|
345
330
|
});
|
|
346
331
|
return () => {
|
|
347
|
-
o = !1,
|
|
332
|
+
o = !1, r.removeEventSubscription(d);
|
|
348
333
|
};
|
|
349
334
|
}, [t]), e;
|
|
350
|
-
},
|
|
351
|
-
const
|
|
335
|
+
}, j = { idToken: null, idTokenPayload: null }, ye = (t) => {
|
|
336
|
+
const s = c.get, e = s(t);
|
|
352
337
|
if (e.tokens) {
|
|
353
|
-
const
|
|
354
|
-
return { idToken:
|
|
338
|
+
const n = e.tokens;
|
|
339
|
+
return { idToken: n.idToken, idTokenPayload: n.idTokenPayload };
|
|
355
340
|
}
|
|
356
|
-
return
|
|
357
|
-
},
|
|
358
|
-
const
|
|
359
|
-
return
|
|
341
|
+
return j;
|
|
342
|
+
}, Pe = (t = U) => {
|
|
343
|
+
const s = c.get, [e, n] = p(() => ye(t));
|
|
344
|
+
return v(() => {
|
|
360
345
|
let o = !0;
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
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;
|
|
369
|
-
s(
|
|
370
|
-
u != null ? { idToken: u.idToken, idTokenPayload: u.idTokenPayload } : Y
|
|
346
|
+
const r = s(t), d = r.subscribeEvents((l, a) => {
|
|
347
|
+
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) {
|
|
348
|
+
const u = r.tokens;
|
|
349
|
+
n(
|
|
350
|
+
u != null ? { idToken: u.idToken, idTokenPayload: u.idTokenPayload } : j
|
|
371
351
|
);
|
|
372
352
|
}
|
|
373
353
|
});
|
|
374
354
|
return () => {
|
|
375
|
-
o = !1,
|
|
355
|
+
o = !1, r.removeEventSubscription(d);
|
|
376
356
|
};
|
|
377
357
|
}, [t]), e;
|
|
378
358
|
};
|
|
379
|
-
var
|
|
380
|
-
const
|
|
381
|
-
const
|
|
382
|
-
user:
|
|
383
|
-
status:
|
|
359
|
+
var be = /* @__PURE__ */ ((t) => (t.Unauthenticated = "Unauthenticated", t.Loading = "Loading user", t.Loaded = "User loaded", t.LoadingError = "Error loading user", t))(be || {});
|
|
360
|
+
const Le = (t = "default", s = !1) => {
|
|
361
|
+
const n = c.get(t).userInfo(), [o, r] = p({
|
|
362
|
+
user: n,
|
|
363
|
+
status: n ? "User loaded" : "Unauthenticated"
|
|
384
364
|
/* Unauthenticated */
|
|
385
|
-
}), [
|
|
386
|
-
|
|
387
|
-
const
|
|
388
|
-
let
|
|
389
|
-
if (
|
|
390
|
-
const y =
|
|
391
|
-
if (y &&
|
|
365
|
+
}), [d, l] = p(n ? 1 : 0), [a, u] = p(n ? 1 : 0);
|
|
366
|
+
v(() => {
|
|
367
|
+
const k = c.get(t);
|
|
368
|
+
let f = !0;
|
|
369
|
+
if (k && k.tokens) {
|
|
370
|
+
const y = d === a;
|
|
371
|
+
if (y && k.userInfo())
|
|
392
372
|
return;
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
373
|
+
queueMicrotask(() => {
|
|
374
|
+
f && (r({
|
|
375
|
+
...o,
|
|
376
|
+
status: "Loading user"
|
|
377
|
+
/* Loading */
|
|
378
|
+
}), u(d));
|
|
379
|
+
}), k.userInfoAsync(!y, s).then((P) => {
|
|
380
|
+
f && r({
|
|
381
|
+
user: P,
|
|
400
382
|
status: "User loaded"
|
|
401
383
|
/* Loaded */
|
|
402
384
|
});
|
|
403
|
-
}).catch(() =>
|
|
385
|
+
}).catch(() => r({
|
|
404
386
|
...o,
|
|
405
387
|
status: "Error loading user"
|
|
406
388
|
/* LoadingError */
|
|
407
|
-
}))
|
|
389
|
+
}));
|
|
408
390
|
} else
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
391
|
+
queueMicrotask(() => {
|
|
392
|
+
f && r({
|
|
393
|
+
user: null,
|
|
394
|
+
status: "Unauthenticated"
|
|
395
|
+
/* Unauthenticated */
|
|
396
|
+
});
|
|
413
397
|
});
|
|
414
|
-
const
|
|
415
|
-
(y ===
|
|
398
|
+
const w = k.subscribeEvents((y) => {
|
|
399
|
+
(y === c.eventNames.logout_from_another_tab || y === c.eventNames.logout_from_same_tab) && f && r({
|
|
416
400
|
user: null,
|
|
417
401
|
status: "Unauthenticated"
|
|
418
402
|
/* Unauthenticated */
|
|
419
403
|
});
|
|
420
404
|
});
|
|
421
405
|
return () => {
|
|
422
|
-
|
|
406
|
+
f = !1, k.removeEventSubscription(w);
|
|
423
407
|
};
|
|
424
|
-
}, [
|
|
408
|
+
}, [d, t, s, a]);
|
|
425
409
|
const _ = () => {
|
|
426
|
-
|
|
410
|
+
l(d + 1);
|
|
427
411
|
};
|
|
428
412
|
return { oidcUser: o.user, oidcUserLoadingState: o.status, reloadOidcUser: _ };
|
|
429
413
|
};
|
|
430
414
|
export {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
415
|
+
Ue as OidcClient,
|
|
416
|
+
Me as OidcLocation,
|
|
417
|
+
Ae as OidcProvider,
|
|
418
|
+
ve as OidcSecure,
|
|
419
|
+
be as OidcUserStatus,
|
|
420
|
+
Fe as TokenAutomaticRenewMode,
|
|
421
|
+
qe as TokenRenewMode,
|
|
422
|
+
Ee as useOidc,
|
|
423
|
+
Se as useOidcAccessToken,
|
|
424
|
+
ee as useOidcFetch,
|
|
425
|
+
Pe as useOidcIdToken,
|
|
426
|
+
Le as useOidcUser,
|
|
427
|
+
Ce as withOidcFetch,
|
|
428
|
+
Oe as withOidcSecure
|
|
445
429
|
};
|
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(f,c){typeof exports=="object"&&typeof module<"u"?c(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"],c):(f=typeof globalThis<"u"?globalThis:f||self,c(f["react-oidc"]={},f.jsxRuntime,f.oidcClient,f.React))})(this,(function(f,c,s,d){"use strict";const F="default",z=(t,n,e=!1)=>async(...o)=>await n().fetchWithTokens(t,e)(...o),K=(t=null,n=F,e=!1)=>o=>r=>{const{fetch:i}=I(t||r.fetch,n,e);return c.jsx(o,{...r,fetch:i})},I=(t=null,n=F,e=!1)=>{const o=t||window.fetch,r=s.OidcClient.get;return{fetch:d.useCallback((u,a)=>z(o,()=>r(n),e)(u,a),[o,n,e])}},U=()=>c.jsx("div",{className:"oidc-authenticating",children:c.jsxs("div",{className:"oidc-authenticating__container",children:[c.jsx("h1",{className:"oidc-authenticating__title",children:"Error authentication"}),c.jsx("p",{className:"oidc-authenticating__content",children:"An error occurred during authentication."})]})}),$=()=>c.jsx("div",{className:"oidc-authenticating",children:c.jsxs("div",{className:"oidc-authenticating__container",children:[c.jsx("h1",{className:"oidc-authenticating__title",children:"Authentication in progress"}),c.jsx("p",{className:"oidc-authenticating__content",children:"You will be redirected to the login page."})]})}),G=()=>Math.random().toString(36).slice(2,8),H=(t,n)=>(e,o)=>{if(typeof t.CustomEvent=="function")return new t.CustomEvent(e,o);const r=o||{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},Q=(t,n,e)=>({replaceState:(o,r)=>{const i=e(),u=r||t.history.state;t.history.replaceState({key:i,state:u},null,o),t.dispatchEvent(n("popstate"))}}),J=()=>Q(window,H(window,document),G),m=()=>c.jsx("div",{className:"oidc-callback",children:c.jsxs("div",{className:"oidc-callback__container",children:[c.jsx("h1",{className:"oidc-callback__title",children:"Authentication complete"}),c.jsx("p",{className:"oidc-callback__content",children:"You will be redirected to your application."})]})}),V=({callBackError:t,callBackSuccess:n,configurationName:e,withCustomHistory:o})=>{const[r,i]=d.useState(!1);d.useEffect(()=>{let l=!0;return(async()=>{const O=s.OidcClient.get;try{const{callbackPath:_}=await O(e).loginCallbackAsync();(o?o():J()).replaceState(_||"/")}catch(_){l&&(console.warn(_),i(!0))}})(),()=>{l=!1}},[]);const u=t||U,a=n||m;return r?c.jsx(u,{configurationName:e}):c.jsx(a,{configurationName:e})},X=()=>c.jsx("span",{className:"oidc-loading",children:"Loading"}),Z=()=>c.jsx("div",{className:"oidc-serviceworker",children:c.jsxs("div",{className:"oidc-serviceworker__container",children:[c.jsx("h1",{className:"oidc-serviceworker__title",children:"Unable to authenticate on this browser"}),c.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."})]})}),x=()=>c.jsx("div",{className:"oidc-session-lost",children:c.jsxs("div",{className:"oidc-session-lost__container",children:[c.jsx("h1",{className:"oidc-session-lost__title",children:"Session timed out"}),c.jsx("p",{className:"oidc-session-lost__content",children:"Your session has expired. Please re-authenticate."})]})}),R=({configurationName:t})=>(d.useEffect(()=>{(async()=>{s.OidcClient.get(t).silentLoginCallbackAsync()})().catch(e=>{console.error("Error during silent login callback:",e)})},[t]),null),ee=({configurationName:t})=>{const n=s.getParseQueryStringFromLocation(window.location.href),e=s.OidcClient.get,o=e(t);let r=null;for(const[i,u]of Object.entries(n))i==="state"||i==="scope"||(r===null&&(r={}),r[i]=u);return d.useEffect(()=>{o.tokens||o.loginAsync(null,r,!0,n.scope)},[]),c.jsx(c.Fragment,{})},te=({callbackErrorComponent:t,callbackSuccessComponent:n,redirect_uri:e,silent_redirect_uri:o,silent_login_uri:r,children:i,configurationName:u,withCustomHistory:a=null})=>{const l=window?s.getPath(window.location.href):"",[h,O]=d.useState(l);d.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&&h===s.getPath(o)?c.jsx(R,{configurationName:u}):r&&h===s.getPath(r)?c.jsx(ee,{configurationName:u}):h===_?c.jsx(V,{callBackError:t,callBackSuccess:n,configurationName:u,withCustomHistory:a}):c.jsx(c.Fragment,{children:i})},se=d.memo(te),M={name:"",data:null},ne=({loadingComponent:t,children:n,configurationName:e})=>{const[o,r]=d.useState(!0),i=s.OidcClient.get,u=i(e);d.useEffect(()=>{let l=!0;return u&&u.tryKeepExistingSessionAsync().then(()=>{l&&r(!1)}),()=>{l=!1}},[e]);const a=t;return c.jsx(c.Fragment,{children:o?c.jsx(a,{configurationName:e}):c.jsx(c.Fragment,{children:n})})},p=({isLoading:t,loadingComponent:n,children:e,configurationName:o})=>{const r=n;return t?c.jsx(r,{configurationName:o,children:e}):c.jsx(c.Fragment,{children:e})},ce=({children:t,configuration:n,configurationName:e="default",callbackSuccessComponent:o=m,authenticatingComponent:r=$,loadingComponent:i=X,serviceWorkerNotSupportedComponent:u=Z,authenticatingErrorComponent:a=U,sessionLostComponent:l=x,onSessionLost:h=null,onLogoutFromAnotherTab:O=null,onLogoutFromSameTab:_=null,withCustomHistory:v=null,onEvent:w=null,getFetch:y=null,location:E=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 T=(L="default")=>s.OidcClient.getOrCreate(y??s.getFetchDefault,E??new s.OidcLocation)(n,L),[fe,S]=d.useState(M),[ke,B]=d.useState(e);d.useEffect(()=>{const N=T(e).subscribeEvents((k,g)=>{w&&w(e,k,g)});return()=>{T(e).removeEventSubscription(N)}},[e,w]),d.useEffect(()=>{const N=T(e).subscribeEvents((k,g)=>{if(k===s.OidcClient.eventNames.refreshTokensAsync_error||k===s.OidcClient.eventNames.syncTokensAsync_error){if(h!=null){h();return}S({name:k,data:g})}else if(k===s.OidcClient.eventNames.logout_from_another_tab){if(O!=null){O();return}S({name:k,data:g})}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:g}):k===s.OidcClient.eventNames.service_worker_not_supported_by_browser&&n.service_worker_only===!0&&S({name:k,data:g})});return queueMicrotask(()=>{B(e),setLoading(!1)}),()=>{T(e).removeEventSubscription(N),S(M)}},[n,e]),d.useEffect(()=>{B(e)},[e]);const _e=l,Oe=r,b=i,ve=u,ye=a,A=ke!==e,C=T(e);switch(fe.name){case s.OidcClient.eventNames.service_worker_not_supported_by_browser:return c.jsx(p,{loadingComponent:b,isLoading:A,configurationName:e,children:c.jsx(ve,{configurationName:e})});case s.OidcClient.eventNames.loginAsync_begin:return c.jsx(p,{loadingComponent:b,isLoading:A,configurationName:e,children:c.jsx(Oe,{configurationName:e})});case s.OidcClient.eventNames.loginAsync_error:case s.OidcClient.eventNames.loginCallbackAsync_error:return c.jsx(p,{loadingComponent:b,isLoading:A,configurationName:e,children:c.jsx(ye,{configurationName:e})});case s.OidcClient.eventNames.refreshTokensAsync_error:case s.OidcClient.eventNames.syncTokensAsync_error:case s.OidcClient.eventNames.logout_from_another_tab:return c.jsx(p,{loadingComponent:b,isLoading:A,configurationName:e,children:c.jsx(_e,{configurationName:e})});default:return c.jsx(p,{loadingComponent:b,isLoading:A,configurationName:e,children:c.jsx(se,{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:c.jsx(ne,{loadingComponent:b,configurationName:e,children:t})})})}},q=({children:t,callbackPath:n=null,extras:e=null,configurationName:o="default"})=>{const r=s.OidcClient.get,i=r(o);return d.useEffect(()=>{i.tokens||i.loginAsync(n,e)},[o,n,e]),i.tokens?c.jsx(c.Fragment,{children:t}):null},oe=(t,n=null,e=null,o="default")=>r=>c.jsx(q,{callbackPath:n,extras:e,configurationName:o,children:c.jsx(t,{...r})}),P="default",D=(t,n)=>{let e=!1;return t(n)&&(e=t(n).tokens!=null),e},re=(t=P)=>{const n=s.OidcClient.get,[e,o]=d.useState(()=>D(n,t));return d.useEffect(()=>{let a=!0;const l=n(t),h=l.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(n,t))});return()=>{a=!1,l.removeEventSubscription(h)}},[t]),{login:(a=void 0,l=void 0,h=!1,O=void 0)=>n(t).loginAsync(a,l,!1,O,h),logout:(a=void 0,l=void 0)=>n(t).logoutAsync(a,l),renewTokens:async(a=void 0)=>{const l=await n(t).renewTokensAsync(a);return{accessToken:l.accessToken,accessTokenPayload:l.accessTokenPayload,idToken:l.idToken,idTokenPayload:l.idTokenPayload}},isAuthenticated:e}},W={accessToken:null,accessTokenPayload:null},ie=t=>{const n=s.OidcClient.get,e=n(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 ae(t,n){return t.configuration.demonstrating_proof_of_possession?(e,o,r={})=>t.generateDemonstrationOfProofOfPossessionAsync(n.accessToken,e,o,r):null}const le=(t=P)=>{const n=s.OidcClient.get,[e,o]=d.useState(()=>ie(t));return d.useEffect(()=>{let r=!0;const i=n(t),u=i.subscribeEvents((a,l)=>{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 h=i.tokens;o(h!=null?{accessToken:h.accessToken,accessTokenPayload:h.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:ae(i,h)}:W)}});return()=>{r=!1,i.removeEventSubscription(u)}},[t]),e},j={idToken:null,idTokenPayload:null},de=t=>{const n=s.OidcClient.get,e=n(t);if(e.tokens){const o=e.tokens;return{idToken:o.idToken,idTokenPayload:o.idTokenPayload}}return j},ue=(t=P)=>{const n=s.OidcClient.get,[e,o]=d.useState(()=>de(t));return d.useEffect(()=>{let r=!0;const i=n(t),u=i.subscribeEvents((a,l)=>{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 h=i.tokens;o(h!=null?{idToken:h.idToken,idTokenPayload:h.idTokenPayload}:j)}});return()=>{r=!1,i.removeEventSubscription(u)}},[t]),e};var Y=(t=>(t.Unauthenticated="Unauthenticated",t.Loading="Loading user",t.Loaded="User loaded",t.LoadingError="Error loading user",t))(Y||{});const he=(t="default",n=!1)=>{const o=s.OidcClient.get(t).userInfo(),[r,i]=d.useState({user:o,status:o?"User loaded":"Unauthenticated"}),[u,a]=d.useState(o?1:0),[l,h]=d.useState(o?1:0);d.useEffect(()=>{const _=s.OidcClient.get(t);let v=!0;if(_&&_.tokens){const y=u===l;if(y&&_.userInfo())return;queueMicrotask(()=>{v&&(i({...r,status:"Loading user"}),h(u))}),_.userInfoAsync(!y,n).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(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(w)}},[u,t,n,l]);const O=()=>{a(u+1)};return{oidcUser:r.user,oidcUserLoadingState:r.status,reloadOidcUser:O}};Object.defineProperty(f,"OidcClient",{enumerable:!0,get:()=>s.OidcClient}),Object.defineProperty(f,"OidcLocation",{enumerable:!0,get:()=>s.OidcLocation}),Object.defineProperty(f,"TokenAutomaticRenewMode",{enumerable:!0,get:()=>s.TokenAutomaticRenewMode}),Object.defineProperty(f,"TokenRenewMode",{enumerable:!0,get:()=>s.TokenRenewMode}),f.OidcProvider=ce,f.OidcSecure=q,f.OidcUserStatus=Y,f.useOidc=re,f.useOidcAccessToken=le,f.useOidcFetch=I,f.useOidcIdToken=ue,f.useOidcUser=he,f.withOidcFetch=K,f.withOidcSecure=oe,Object.defineProperty(f,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.4",
|
|
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.4",
|
|
44
|
+
"@axa-fr/oidc-client": "7.26.4"
|
|
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
|
@@ -115,9 +115,9 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
|
|
|
115
115
|
);
|
|
116
116
|
};
|
|
117
117
|
|
|
118
|
-
const
|
|
118
|
+
const loading = false;
|
|
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);
|
|
@@ -179,6 +182,10 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
|
|
|
179
182
|
};
|
|
180
183
|
}, [configuration, configurationName]);
|
|
181
184
|
|
|
185
|
+
useEffect(() => {
|
|
186
|
+
setConfigurationName(configurationName);
|
|
187
|
+
}, [configurationName]);
|
|
188
|
+
|
|
182
189
|
const SessionLostComponent = sessionLostComponent;
|
|
183
190
|
const AuthenticatingComponent = authenticatingComponent;
|
|
184
191
|
const LoadingComponent = loadingComponent;
|
package/src/ReactOidc.tsx
CHANGED
|
@@ -18,14 +18,13 @@ const defaultIsAuthenticated = (getOidc: GetOidcFn, configurationName: string) =
|
|
|
18
18
|
|
|
19
19
|
export const useOidc = (configurationName = defaultConfigurationName) => {
|
|
20
20
|
const getOidc = OidcClient.get;
|
|
21
|
-
const [isAuthenticated, setIsAuthenticated] = useState<boolean>(
|
|
21
|
+
const [isAuthenticated, setIsAuthenticated] = useState<boolean>(() =>
|
|
22
22
|
defaultIsAuthenticated(getOidc, configurationName),
|
|
23
23
|
);
|
|
24
24
|
|
|
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 (
|
|
@@ -62,7 +71,7 @@ export const useOidcUser = <T extends OidcUserInfo = OidcUserInfo>(
|
|
|
62
71
|
isMounted = false;
|
|
63
72
|
oidc.removeEventSubscription(newSubscriptionId);
|
|
64
73
|
};
|
|
65
|
-
}, [oidcUserId]);
|
|
74
|
+
}, [oidcUserId, configurationName, demonstrating_proof_of_possession, oidcPreviousUserId]);
|
|
66
75
|
|
|
67
76
|
const reloadOidcUser = () => {
|
|
68
77
|
setOidcUserId(oidcUserId + 1);
|
|
@@ -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
|
};
|