@axa-fr/react-oidc 7.25.16 → 7.26.1-alpha.1797
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/OidcProvider.d.ts.map +1 -1
- package/dist/index.js +102 -100
- package/dist/index.umd.cjs +1 -1
- package/package.json +3 -3
- package/src/OidcProvider.tsx +6 -0
package/README.md
CHANGED
|
@@ -182,6 +182,9 @@ const App = () => (
|
|
|
182
182
|
render(<App />, document.getElementById('root'));
|
|
183
183
|
```
|
|
184
184
|
|
|
185
|
+
> [!WARNING]
|
|
186
|
+
> If you have both `redirect_uri` and `silent_redirect_uri` configured, their value must be different.
|
|
187
|
+
|
|
185
188
|
```javascript
|
|
186
189
|
const configuration = {
|
|
187
190
|
loadingComponent: ReactComponent, // you can inject your own loading component
|
|
@@ -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,CA6KjE,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,22 +2,22 @@ import { jsx as i, jsxs as E, Fragment as m } from "react/jsx-runtime";
|
|
|
2
2
|
import { OidcClient as r, getParseQueryStringFromLocation as V, getPath as O, OidcLocation as M, getFetchDefault as X } from "@axa-fr/oidc-client";
|
|
3
3
|
import { OidcClient as Me, OidcLocation as De, TokenAutomaticRenewMode as xe, TokenRenewMode as We } from "@axa-fr/oidc-client";
|
|
4
4
|
import Z, { useCallback as ee, useState as v, useEffect as f } from "react";
|
|
5
|
-
const x = "default", te = (t,
|
|
5
|
+
const x = "default", te = (t, n, e = !1) => async (...s) => await n().fetchWithTokens(t, e)(...s), Oe = (t = null, n = x, e = !1) => (s) => (o) => {
|
|
6
6
|
const { fetch: c } = ne(
|
|
7
7
|
t || o.fetch,
|
|
8
|
-
|
|
8
|
+
n,
|
|
9
9
|
e
|
|
10
10
|
);
|
|
11
|
-
return /* @__PURE__ */ i(
|
|
12
|
-
}, ne = (t = null,
|
|
13
|
-
const
|
|
11
|
+
return /* @__PURE__ */ i(s, { ...o, fetch: c });
|
|
12
|
+
}, ne = (t = null, n = x, e = !1) => {
|
|
13
|
+
const s = t || window.fetch, o = r.get;
|
|
14
14
|
return { fetch: ee(
|
|
15
15
|
(l, a) => te(
|
|
16
|
-
|
|
17
|
-
() => o(
|
|
16
|
+
s,
|
|
17
|
+
() => o(n),
|
|
18
18
|
e
|
|
19
19
|
)(l, a),
|
|
20
|
-
[
|
|
20
|
+
[s, n]
|
|
21
21
|
) };
|
|
22
22
|
}, W = () => /* @__PURE__ */ i("div", { className: "oidc-authenticating", children: /* @__PURE__ */ E("div", { className: "oidc-authenticating__container", children: [
|
|
23
23
|
/* @__PURE__ */ i("h1", { className: "oidc-authenticating__title", children: "Error authentication" }),
|
|
@@ -25,29 +25,29 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
|
|
|
25
25
|
] }) }), se = () => /* @__PURE__ */ i("div", { className: "oidc-authenticating", children: /* @__PURE__ */ E("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
|
-
] }) }), oe = () => Math.random().toString(36).slice(2, 8), ce = (t,
|
|
28
|
+
] }) }), oe = () => Math.random().toString(36).slice(2, 8), ce = (t, n) => (e, s) => {
|
|
29
29
|
if (typeof t.CustomEvent == "function")
|
|
30
|
-
return new t.CustomEvent(e,
|
|
31
|
-
const o =
|
|
30
|
+
return new t.CustomEvent(e, s);
|
|
31
|
+
const o = s || { bubbles: !1, cancelable: !1, detail: void 0 }, c = n.createEvent("CustomEvent");
|
|
32
32
|
return c.initCustomEvent(
|
|
33
33
|
e,
|
|
34
34
|
o.bubbles,
|
|
35
35
|
o.cancelable,
|
|
36
36
|
o.detail
|
|
37
37
|
), c.prototype = t.Event.prototype, c;
|
|
38
|
-
}, re = (t,
|
|
39
|
-
replaceState: (
|
|
38
|
+
}, re = (t, n, e) => ({
|
|
39
|
+
replaceState: (s, o) => {
|
|
40
40
|
const c = e(), l = o || t.history.state;
|
|
41
|
-
t.history.replaceState({ key: c, state: l }, null,
|
|
41
|
+
t.history.replaceState({ key: c, state: l }, null, s), t.dispatchEvent(n("popstate"));
|
|
42
42
|
}
|
|
43
43
|
}), ie = () => re(window, ce(window, document), oe), R = () => /* @__PURE__ */ i("div", { className: "oidc-callback", children: /* @__PURE__ */ E("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
|
] }) }), ae = ({
|
|
47
47
|
callBackError: t,
|
|
48
|
-
callBackSuccess:
|
|
48
|
+
callBackSuccess: n,
|
|
49
49
|
configurationName: e,
|
|
50
|
-
withCustomHistory:
|
|
50
|
+
withCustomHistory: s
|
|
51
51
|
}) => {
|
|
52
52
|
const [o, c] = v(!1);
|
|
53
53
|
f(() => {
|
|
@@ -56,7 +56,7 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
|
|
|
56
56
|
const _ = r.get;
|
|
57
57
|
try {
|
|
58
58
|
const { callbackPath: h } = await _(e).loginCallbackAsync();
|
|
59
|
-
(
|
|
59
|
+
(s ? s() : ie()).replaceState(h || "/");
|
|
60
60
|
} catch (h) {
|
|
61
61
|
d && (console.warn(h), c(!0));
|
|
62
62
|
}
|
|
@@ -64,7 +64,7 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
|
|
|
64
64
|
d = !1;
|
|
65
65
|
};
|
|
66
66
|
}, []);
|
|
67
|
-
const l = t || W, a =
|
|
67
|
+
const l = t || W, a = n || R;
|
|
68
68
|
return o ? /* @__PURE__ */ i(l, { configurationName: e }) : /* @__PURE__ */ i(a, { configurationName: e });
|
|
69
69
|
}, le = () => /* @__PURE__ */ i("span", { className: "oidc-loading", children: "Loading" }), de = () => /* @__PURE__ */ i("div", { className: "oidc-serviceworker", children: /* @__PURE__ */ E("div", { className: "oidc-serviceworker__container", children: [
|
|
70
70
|
/* @__PURE__ */ i("h1", { className: "oidc-serviceworker__title", children: "Unable to authenticate on this browser" }),
|
|
@@ -79,18 +79,18 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
|
|
|
79
79
|
console.error("Error during silent login callback:", e);
|
|
80
80
|
});
|
|
81
81
|
}, [t]), null), he = ({ configurationName: t }) => {
|
|
82
|
-
const
|
|
82
|
+
const n = V(window.location.href), e = r.get, s = e(t);
|
|
83
83
|
let o = null;
|
|
84
|
-
for (const [c, l] of Object.entries(
|
|
84
|
+
for (const [c, l] of Object.entries(n))
|
|
85
85
|
c === "state" || c === "scope" || (o === null && (o = {}), o[c] = l);
|
|
86
86
|
return f(() => {
|
|
87
|
-
|
|
87
|
+
s.tokens || s.loginAsync(null, o, !0, n.scope);
|
|
88
88
|
}, []), /* @__PURE__ */ i(m, {});
|
|
89
89
|
}, _e = ({
|
|
90
90
|
callbackErrorComponent: t,
|
|
91
|
-
callbackSuccessComponent:
|
|
91
|
+
callbackSuccessComponent: n,
|
|
92
92
|
redirect_uri: e,
|
|
93
|
-
silent_redirect_uri:
|
|
93
|
+
silent_redirect_uri: s,
|
|
94
94
|
silent_login_uri: o,
|
|
95
95
|
children: c,
|
|
96
96
|
configurationName: l,
|
|
@@ -98,11 +98,11 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
|
|
|
98
98
|
}) => {
|
|
99
99
|
const d = window ? O(window.location.href) : "", [u, _] = v(d);
|
|
100
100
|
f(() => {
|
|
101
|
-
const
|
|
102
|
-
return
|
|
101
|
+
const p = () => _(O(window.location.href));
|
|
102
|
+
return p(), window.addEventListener("popstate", p, !1), () => window.removeEventListener("popstate", p, !1);
|
|
103
103
|
}, []);
|
|
104
104
|
const h = O(e);
|
|
105
|
-
if (
|
|
105
|
+
if (s && u === O(s))
|
|
106
106
|
return /* @__PURE__ */ i(ke, { configurationName: l });
|
|
107
107
|
if (o && u === O(o))
|
|
108
108
|
return /* @__PURE__ */ i(he, { configurationName: l });
|
|
@@ -112,7 +112,7 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
|
|
|
112
112
|
ae,
|
|
113
113
|
{
|
|
114
114
|
callBackError: t,
|
|
115
|
-
callBackSuccess:
|
|
115
|
+
callBackSuccess: n,
|
|
116
116
|
configurationName: l,
|
|
117
117
|
withCustomHistory: a
|
|
118
118
|
}
|
|
@@ -122,10 +122,10 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
|
|
|
122
122
|
}
|
|
123
123
|
}, ve = Z.memo(_e), D = { name: "", data: null }, fe = ({
|
|
124
124
|
loadingComponent: t,
|
|
125
|
-
children:
|
|
125
|
+
children: n,
|
|
126
126
|
configurationName: e
|
|
127
127
|
}) => {
|
|
128
|
-
const [
|
|
128
|
+
const [s, o] = v(!0), c = r.get, l = c(e);
|
|
129
129
|
return f(() => {
|
|
130
130
|
let d = !0;
|
|
131
131
|
return l && l.tryKeepExistingSessionAsync().then(() => {
|
|
@@ -133,15 +133,15 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
|
|
|
133
133
|
}), () => {
|
|
134
134
|
d = !1;
|
|
135
135
|
};
|
|
136
|
-
}, [e]), /* @__PURE__ */ i(m, { children:
|
|
137
|
-
}, P = ({ isLoading: t, loadingComponent:
|
|
138
|
-
const o =
|
|
139
|
-
return t ? /* @__PURE__ */ i(o, { configurationName:
|
|
136
|
+
}, [e]), /* @__PURE__ */ i(m, { children: s ? /* @__PURE__ */ i(t, { configurationName: e }) : /* @__PURE__ */ i(m, { children: n }) });
|
|
137
|
+
}, P = ({ isLoading: t, loadingComponent: n, children: e, configurationName: s }) => {
|
|
138
|
+
const o = n;
|
|
139
|
+
return t ? /* @__PURE__ */ i(o, { configurationName: s, children: e }) : /* @__PURE__ */ i(m, { children: e });
|
|
140
140
|
}, Pe = ({
|
|
141
141
|
children: t,
|
|
142
|
-
configuration:
|
|
142
|
+
configuration: n,
|
|
143
143
|
configurationName: e = "default",
|
|
144
|
-
callbackSuccessComponent:
|
|
144
|
+
callbackSuccessComponent: s = R,
|
|
145
145
|
authenticatingComponent: o = se,
|
|
146
146
|
loadingComponent: c = le,
|
|
147
147
|
serviceWorkerNotSupportedComponent: l = de,
|
|
@@ -150,13 +150,15 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
|
|
|
150
150
|
onSessionLost: u = null,
|
|
151
151
|
onLogoutFromAnotherTab: _ = null,
|
|
152
152
|
onLogoutFromSameTab: h = null,
|
|
153
|
-
withCustomHistory:
|
|
153
|
+
withCustomHistory: p = null,
|
|
154
154
|
onEvent: T = null,
|
|
155
|
-
getFetch:
|
|
155
|
+
getFetch: y = null,
|
|
156
156
|
location: S = null
|
|
157
157
|
}) => {
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
if (n && n.redirect_uri && n.silent_redirect_uri && n.redirect_uri === n.silent_redirect_uri)
|
|
159
|
+
throw new Error("redirect_uri and silent_redirect_uri must be different");
|
|
160
|
+
const w = (L = "default") => r.getOrCreate(y ?? X, S ?? new M())(
|
|
161
|
+
n,
|
|
160
162
|
L
|
|
161
163
|
), [j, B] = v(!0), [z, C] = v(D), [K, $] = v("default");
|
|
162
164
|
f(() => {
|
|
@@ -180,19 +182,19 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
|
|
|
180
182
|
return;
|
|
181
183
|
}
|
|
182
184
|
C({ name: k, data: b });
|
|
183
|
-
} else k === r.eventNames.logout_from_same_tab ? h != null && h() : k === r.eventNames.loginAsync_begin || k === r.eventNames.loginCallbackAsync_end || k === r.eventNames.loginAsync_error || k === r.eventNames.loginCallbackAsync_error ? C({ name: k, data: b }) : k === r.eventNames.service_worker_not_supported_by_browser &&
|
|
185
|
+
} else k === r.eventNames.logout_from_same_tab ? h != null && h() : k === r.eventNames.loginAsync_begin || k === r.eventNames.loginCallbackAsync_end || k === r.eventNames.loginAsync_error || k === r.eventNames.loginCallbackAsync_error ? C({ name: k, data: b }) : k === r.eventNames.service_worker_not_supported_by_browser && n.service_worker_only === !0 && C({ name: k, data: b });
|
|
184
186
|
});
|
|
185
187
|
return $(e), B(!1), () => {
|
|
186
188
|
w(e).removeEventSubscription(I), C(D);
|
|
187
189
|
};
|
|
188
|
-
}, [
|
|
189
|
-
const G = d, H = o,
|
|
190
|
+
}, [n, e]);
|
|
191
|
+
const G = d, H = o, g = c, Q = l, J = a, A = j || K !== e, N = w(e);
|
|
190
192
|
switch (z.name) {
|
|
191
193
|
case r.eventNames.service_worker_not_supported_by_browser:
|
|
192
194
|
return /* @__PURE__ */ i(
|
|
193
195
|
P,
|
|
194
196
|
{
|
|
195
|
-
loadingComponent:
|
|
197
|
+
loadingComponent: g,
|
|
196
198
|
isLoading: A,
|
|
197
199
|
configurationName: e,
|
|
198
200
|
children: /* @__PURE__ */ i(Q, { configurationName: e })
|
|
@@ -202,7 +204,7 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
|
|
|
202
204
|
return /* @__PURE__ */ i(
|
|
203
205
|
P,
|
|
204
206
|
{
|
|
205
|
-
loadingComponent:
|
|
207
|
+
loadingComponent: g,
|
|
206
208
|
isLoading: A,
|
|
207
209
|
configurationName: e,
|
|
208
210
|
children: /* @__PURE__ */ i(H, { configurationName: e })
|
|
@@ -213,7 +215,7 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
|
|
|
213
215
|
return /* @__PURE__ */ i(
|
|
214
216
|
P,
|
|
215
217
|
{
|
|
216
|
-
loadingComponent:
|
|
218
|
+
loadingComponent: g,
|
|
217
219
|
isLoading: A,
|
|
218
220
|
configurationName: e,
|
|
219
221
|
children: /* @__PURE__ */ i(J, { configurationName: e })
|
|
@@ -225,7 +227,7 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
|
|
|
225
227
|
return /* @__PURE__ */ i(
|
|
226
228
|
P,
|
|
227
229
|
{
|
|
228
|
-
loadingComponent:
|
|
230
|
+
loadingComponent: g,
|
|
229
231
|
isLoading: A,
|
|
230
232
|
configurationName: e,
|
|
231
233
|
children: /* @__PURE__ */ i(G, { configurationName: e })
|
|
@@ -235,7 +237,7 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
|
|
|
235
237
|
return /* @__PURE__ */ i(
|
|
236
238
|
P,
|
|
237
239
|
{
|
|
238
|
-
loadingComponent:
|
|
240
|
+
loadingComponent: g,
|
|
239
241
|
isLoading: A,
|
|
240
242
|
configurationName: e,
|
|
241
243
|
children: /* @__PURE__ */ i(
|
|
@@ -244,53 +246,53 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
|
|
|
244
246
|
redirect_uri: N.configuration.redirect_uri,
|
|
245
247
|
silent_redirect_uri: N.configuration.silent_redirect_uri,
|
|
246
248
|
silent_login_uri: N.configuration.silent_login_uri,
|
|
247
|
-
callbackSuccessComponent:
|
|
249
|
+
callbackSuccessComponent: s,
|
|
248
250
|
callbackErrorComponent: a,
|
|
249
251
|
authenticatingComponent: o,
|
|
250
252
|
configurationName: e,
|
|
251
|
-
withCustomHistory:
|
|
253
|
+
withCustomHistory: p,
|
|
252
254
|
location: S ?? new M(),
|
|
253
|
-
children: /* @__PURE__ */ i(fe, { loadingComponent:
|
|
255
|
+
children: /* @__PURE__ */ i(fe, { loadingComponent: g, configurationName: e, children: t })
|
|
254
256
|
}
|
|
255
257
|
)
|
|
256
258
|
}
|
|
257
259
|
);
|
|
258
260
|
}
|
|
259
|
-
},
|
|
261
|
+
}, pe = ({
|
|
260
262
|
children: t,
|
|
261
|
-
callbackPath:
|
|
263
|
+
callbackPath: n = null,
|
|
262
264
|
extras: e = null,
|
|
263
|
-
configurationName:
|
|
265
|
+
configurationName: s = "default"
|
|
264
266
|
}) => {
|
|
265
|
-
const o = r.get, c = o(
|
|
267
|
+
const o = r.get, c = o(s);
|
|
266
268
|
return f(() => {
|
|
267
|
-
c.tokens || c.loginAsync(
|
|
268
|
-
}, [
|
|
269
|
-
}, Ee = (t,
|
|
269
|
+
c.tokens || c.loginAsync(n, e);
|
|
270
|
+
}, [s, n, e]), c.tokens ? /* @__PURE__ */ i(m, { children: t }) : null;
|
|
271
|
+
}, Ee = (t, n = null, e = null, s = "default") => (o) => /* @__PURE__ */ i(pe, { callbackPath: n, extras: e, configurationName: s, children: /* @__PURE__ */ i(t, { ...o }) }), F = "default", U = (t, n) => {
|
|
270
272
|
let e = !1;
|
|
271
|
-
return t(
|
|
273
|
+
return t(n) && (e = t(n).tokens != null), e;
|
|
272
274
|
}, Se = (t = F) => {
|
|
273
|
-
const
|
|
274
|
-
U(
|
|
275
|
+
const n = r.get, [e, s] = v(
|
|
276
|
+
U(n, t)
|
|
275
277
|
);
|
|
276
278
|
return f(() => {
|
|
277
279
|
let a = !0;
|
|
278
|
-
const d =
|
|
279
|
-
|
|
280
|
+
const d = n(t);
|
|
281
|
+
s(U(n, t));
|
|
280
282
|
const u = d.subscribeEvents((_, h) => {
|
|
281
|
-
(_ === r.eventNames.logout_from_another_tab || _ === r.eventNames.logout_from_same_tab || _ === r.eventNames.token_acquired) && a &&
|
|
283
|
+
(_ === r.eventNames.logout_from_another_tab || _ === r.eventNames.logout_from_same_tab || _ === r.eventNames.token_acquired) && a && s(U(n, t));
|
|
282
284
|
});
|
|
283
285
|
return () => {
|
|
284
286
|
a = !1, d.removeEventSubscription(u);
|
|
285
287
|
};
|
|
286
|
-
}, [t]), { login: (a = void 0, d = void 0, u = !1, _ = void 0) =>
|
|
288
|
+
}, [t]), { login: (a = void 0, d = void 0, u = !1, _ = void 0) => n(t).loginAsync(
|
|
287
289
|
a,
|
|
288
290
|
d,
|
|
289
291
|
!1,
|
|
290
292
|
_,
|
|
291
293
|
u
|
|
292
|
-
), logout: (a = void 0, d = void 0) =>
|
|
293
|
-
const d = await
|
|
294
|
+
), logout: (a = void 0, d = void 0) => n(t).logoutAsync(a, d), renewTokens: async (a = void 0) => {
|
|
295
|
+
const d = await n(t).renewTokensAsync(a);
|
|
294
296
|
return {
|
|
295
297
|
// @ts-ignore
|
|
296
298
|
accessToken: d.accessToken,
|
|
@@ -302,29 +304,29 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
|
|
|
302
304
|
idTokenPayload: d.idTokenPayload
|
|
303
305
|
};
|
|
304
306
|
}, isAuthenticated: e };
|
|
305
|
-
}, q = { accessToken: null, accessTokenPayload: null },
|
|
306
|
-
const
|
|
307
|
+
}, q = { accessToken: null, accessTokenPayload: null }, ye = (t) => {
|
|
308
|
+
const n = r.get, e = n(t);
|
|
307
309
|
if (e.tokens) {
|
|
308
|
-
const
|
|
310
|
+
const s = e.tokens;
|
|
309
311
|
return {
|
|
310
|
-
accessToken:
|
|
311
|
-
accessTokenPayload:
|
|
312
|
-
generateDemonstrationOfProofOfPossessionAsync: e.configuration.demonstrating_proof_of_possession ? (o, c) => e.generateDemonstrationOfProofOfPossessionAsync(
|
|
312
|
+
accessToken: s.accessToken,
|
|
313
|
+
accessTokenPayload: s.accessTokenPayload,
|
|
314
|
+
generateDemonstrationOfProofOfPossessionAsync: e.configuration.demonstrating_proof_of_possession ? (o, c) => e.generateDemonstrationOfProofOfPossessionAsync(s.accessToken, o, c) : null
|
|
313
315
|
};
|
|
314
316
|
}
|
|
315
317
|
return q;
|
|
316
318
|
};
|
|
317
|
-
function
|
|
318
|
-
return t.configuration.demonstrating_proof_of_possession ? (e,
|
|
319
|
+
function ge(t, n) {
|
|
320
|
+
return t.configuration.demonstrating_proof_of_possession ? (e, s, o = {}) => t.generateDemonstrationOfProofOfPossessionAsync(n.accessToken, e, s, o) : null;
|
|
319
321
|
}
|
|
320
322
|
const Ne = (t = F) => {
|
|
321
|
-
const
|
|
323
|
+
const n = r.get, [e, s] = v(ye(t));
|
|
322
324
|
return f(() => {
|
|
323
325
|
let o = !0;
|
|
324
|
-
const c =
|
|
326
|
+
const c = n(t);
|
|
325
327
|
if (c.tokens) {
|
|
326
328
|
const a = c.tokens;
|
|
327
|
-
|
|
329
|
+
s({
|
|
328
330
|
accessToken: a.accessToken,
|
|
329
331
|
accessTokenPayload: a.accessTokenPayload
|
|
330
332
|
});
|
|
@@ -332,11 +334,11 @@ const Ne = (t = F) => {
|
|
|
332
334
|
const l = c.subscribeEvents((a, d) => {
|
|
333
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) {
|
|
334
336
|
const u = c.tokens;
|
|
335
|
-
|
|
337
|
+
s(
|
|
336
338
|
u != null ? {
|
|
337
339
|
accessToken: u.accessToken,
|
|
338
340
|
accessTokenPayload: u.accessTokenPayload,
|
|
339
|
-
generateDemonstrationOfProofOfPossessionAsync:
|
|
341
|
+
generateDemonstrationOfProofOfPossessionAsync: ge(c, u)
|
|
340
342
|
} : q
|
|
341
343
|
);
|
|
342
344
|
}
|
|
@@ -346,25 +348,25 @@ const Ne = (t = F) => {
|
|
|
346
348
|
};
|
|
347
349
|
}, [t]), e;
|
|
348
350
|
}, Y = { idToken: null, idTokenPayload: null }, be = (t) => {
|
|
349
|
-
const
|
|
351
|
+
const n = r.get, e = n(t);
|
|
350
352
|
if (e.tokens) {
|
|
351
|
-
const
|
|
352
|
-
return { idToken:
|
|
353
|
+
const s = e.tokens;
|
|
354
|
+
return { idToken: s.idToken, idTokenPayload: s.idTokenPayload };
|
|
353
355
|
}
|
|
354
356
|
return Y;
|
|
355
357
|
}, Le = (t = F) => {
|
|
356
|
-
const
|
|
358
|
+
const n = r.get, [e, s] = v(be(t));
|
|
357
359
|
return f(() => {
|
|
358
360
|
let o = !0;
|
|
359
|
-
const c =
|
|
361
|
+
const c = n(t);
|
|
360
362
|
if (c.tokens) {
|
|
361
363
|
const a = c.tokens;
|
|
362
|
-
|
|
364
|
+
s({ idToken: a.idToken, idTokenPayload: a.idTokenPayload });
|
|
363
365
|
}
|
|
364
366
|
const l = c.subscribeEvents((a, d) => {
|
|
365
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) {
|
|
366
368
|
const u = c.tokens;
|
|
367
|
-
|
|
369
|
+
s(
|
|
368
370
|
u != null ? { idToken: u.idToken, idTokenPayload: u.idTokenPayload } : Y
|
|
369
371
|
);
|
|
370
372
|
}
|
|
@@ -375,25 +377,25 @@ const Ne = (t = F) => {
|
|
|
375
377
|
}, [t]), e;
|
|
376
378
|
};
|
|
377
379
|
var me = /* @__PURE__ */ ((t) => (t.Unauthenticated = "Unauthenticated", t.Loading = "Loading user", t.Loaded = "User loaded", t.LoadingError = "Error loading user", t))(me || {});
|
|
378
|
-
const Ie = (t = "default",
|
|
379
|
-
const
|
|
380
|
-
user:
|
|
381
|
-
status:
|
|
380
|
+
const Ie = (t = "default", n = !1) => {
|
|
381
|
+
const s = r.get(t).userInfo(), [o, c] = v({
|
|
382
|
+
user: s,
|
|
383
|
+
status: s ? "User loaded" : "Unauthenticated"
|
|
382
384
|
/* Unauthenticated */
|
|
383
|
-
}), [l, a] = v(
|
|
385
|
+
}), [l, a] = v(s ? 1 : 0), [d, u] = v(s ? 1 : 0);
|
|
384
386
|
f(() => {
|
|
385
387
|
const h = r.get(t);
|
|
386
|
-
let
|
|
388
|
+
let p = !0;
|
|
387
389
|
if (h && h.tokens) {
|
|
388
|
-
const
|
|
389
|
-
if (
|
|
390
|
+
const y = l === d;
|
|
391
|
+
if (y && h.userInfo())
|
|
390
392
|
return;
|
|
391
393
|
c({
|
|
392
394
|
...o,
|
|
393
395
|
status: "Loading user"
|
|
394
396
|
/* Loading */
|
|
395
|
-
}), h.userInfoAsync(!
|
|
396
|
-
|
|
397
|
+
}), h.userInfoAsync(!y, n).then((S) => {
|
|
398
|
+
p && c({
|
|
397
399
|
user: S,
|
|
398
400
|
status: "User loaded"
|
|
399
401
|
/* Loaded */
|
|
@@ -409,15 +411,15 @@ const Ie = (t = "default", s = !1) => {
|
|
|
409
411
|
status: "Unauthenticated"
|
|
410
412
|
/* Unauthenticated */
|
|
411
413
|
});
|
|
412
|
-
const T = h.subscribeEvents((
|
|
413
|
-
(
|
|
414
|
+
const T = h.subscribeEvents((y) => {
|
|
415
|
+
(y === r.eventNames.logout_from_another_tab || y === r.eventNames.logout_from_same_tab) && p && c({
|
|
414
416
|
user: null,
|
|
415
417
|
status: "Unauthenticated"
|
|
416
418
|
/* Unauthenticated */
|
|
417
419
|
});
|
|
418
420
|
});
|
|
419
421
|
return () => {
|
|
420
|
-
|
|
422
|
+
p = !1, h.removeEventSubscription(T);
|
|
421
423
|
};
|
|
422
424
|
}, [l]);
|
|
423
425
|
const _ = () => {
|
|
@@ -429,7 +431,7 @@ export {
|
|
|
429
431
|
Me as OidcClient,
|
|
430
432
|
De as OidcLocation,
|
|
431
433
|
Pe as OidcProvider,
|
|
432
|
-
|
|
434
|
+
pe as OidcSecure,
|
|
433
435
|
me as OidcUserStatus,
|
|
434
436
|
xe as TokenAutomaticRenewMode,
|
|
435
437
|
We as TokenRenewMode,
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(k,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):(k=typeof globalThis<"u"?globalThis:k||self,n(k["react-oidc"]={},k.jsxRuntime,k.oidcClient,k.React))})(this,function(k,n,s,l){"use strict";const F="default",B=(t,c,e=!1)=>async(...o)=>await c().fetchWithTokens(t,e)(...o),z=(t=null,c=F,e=!1)=>o=>r=>{const{fetch:i}=I(t||r.fetch,c,e);return n.jsx(o,{...r,fetch:i})},I=(t=null,c=F,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])}},U=()=>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),$),M=()=>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 _=s.OidcClient.get;try{const{callbackPath:O}=await _(e).loginCallbackAsync();(o?o():Q()).replaceState(O||"/")}catch(O){u&&(console.warn(O),i(!0))}})(),()=>{u=!1}},[]);const d=t||U,a=c||M;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,_]=l.useState(u);l.useEffect(()=>{const v=()=>_(s.getPath(window.location.href));return v(),window.addEventListener("popstate",v,!1),()=>window.removeEventListener("popstate",v,!1)},[]);const O=s.getPath(e);if(o&&f===s.getPath(o))return n.jsx(x,{configurationName:d});if(r&&f===s.getPath(r))return n.jsx(R,{configurationName:d});switch(f){case O:return n.jsx(J,{callBackError:t,callBackSuccess:c,configurationName:d,withCustomHistory:a});default:return n.jsx(n.Fragment,{children:i})}},te=l.memo(ee),q={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=M,authenticatingComponent:r=K,loadingComponent:i=V,serviceWorkerNotSupportedComponent:d=X,authenticatingErrorComponent:a=U,sessionLostComponent:u=Z,onSessionLost:f=null,onLogoutFromAnotherTab:_=null,onLogoutFromSameTab:O=null,withCustomHistory:v=null,onEvent:T=null,getFetch:g=null,location:P=null})=>{const w=(N="default")=>s.OidcClient.getOrCreate(g??s.getFetchDefault,P??new s.OidcLocation)(c,N),[fe,ke]=l.useState(!0),[he,S]=l.useState(q),[Oe,_e]=l.useState("default");l.useEffect(()=>{const m=w(e).subscribeEvents((h,b)=>{T&&T(e,h,b)});return()=>{w(e).removeEventSubscription(m)}},[e,T]),l.useEffect(()=>{const m=w(e).subscribeEvents((h,b)=>{if(h===s.OidcClient.eventNames.refreshTokensAsync_error||h===s.OidcClient.eventNames.syncTokensAsync_error){if(f!=null){f();return}S({name:h,data:b})}else if(h===s.OidcClient.eventNames.logout_from_another_tab){if(_!=null){_();return}S({name:h,data:b})}else h===s.OidcClient.eventNames.logout_from_same_tab?O!=null&&O():h===s.OidcClient.eventNames.loginAsync_begin||h===s.OidcClient.eventNames.loginCallbackAsync_end||h===s.OidcClient.eventNames.loginAsync_error||h===s.OidcClient.eventNames.loginCallbackAsync_error?S({name:h,data:b}):h===s.OidcClient.eventNames.service_worker_not_supported_by_browser&&c.service_worker_only===!0&&S({name:h,data:b})});return _e(e),ke(!1),()=>{w(e).removeEventSubscription(m),S(q)}},[c,e]);const ve=u,ge=r,y=i,ye=d,be=a,A=fe||Oe!==e,L=w(e);switch(he.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:L.configuration.redirect_uri,silent_redirect_uri:L.configuration.silent_redirect_uri,silent_login_uri:L.configuration.silent_login_uri,callbackSuccessComponent:o,callbackErrorComponent:a,authenticatingComponent:r,configurationName:e,withCustomHistory:v,location:P??new s.OidcLocation,children:n.jsx(se,{loadingComponent:y,configurationName:e,children:t})})})}},D=({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},oe=(t,c=null,e=null,o="default")=>r=>n.jsx(D,{callbackPath:c,extras:e,configurationName:o,children:n.jsx(t,{...r})}),E="default",C=(t,c)=>{let e=!1;return t(c)&&(e=t(c).tokens!=null),e},ce=(t=E)=>{const c=s.OidcClient.get,[e,o]=l.useState(C(c,t));return l.useEffect(()=>{let a=!0;const u=c(t);o(C(c,t));const f=u.subscribeEvents((_,O)=>{(_===s.OidcClient.eventNames.logout_from_another_tab||_===s.OidcClient.eventNames.logout_from_same_tab||_===s.OidcClient.eventNames.token_acquired)&&a&&o(C(c,t))});return()=>{a=!1,u.removeEventSubscription(f)}},[t]),{login:(a=void 0,u=void 0,f=!1,_=void 0)=>c(t).loginAsync(a,u,!1,_,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=E)=>{const c=s.OidcClient.get,[e,o]=l.useState(re(t));return l.useEffect(()=>{let r=!0;const i=c(t);if(i.tokens){const a=i.tokens;o({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;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=E)=>{const c=s.OidcClient.get,[e,o]=l.useState(le(t));return l.useEffect(()=>{let r=!0;const i=c(t);if(i.tokens){const a=i.tokens;o({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;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 O=s.OidcClient.get(t);let v=!0;if(O&&O.tokens){const g=d===u;if(g&&O.userInfo())return;i({...r,status:"Loading user"}),O.userInfoAsync(!g,c).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=O.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,O.removeEventSubscription(T)}},[d]);const _=()=>{a(d+1)};return{oidcUser:r.user,oidcUserLoadingState:r.status,reloadOidcUser:_}};Object.defineProperty(k,"OidcClient",{enumerable:!0,get:()=>s.OidcClient}),Object.defineProperty(k,"OidcLocation",{enumerable:!0,get:()=>s.OidcLocation}),Object.defineProperty(k,"TokenAutomaticRenewMode",{enumerable:!0,get:()=>s.TokenAutomaticRenewMode}),Object.defineProperty(k,"TokenRenewMode",{enumerable:!0,get:()=>s.TokenRenewMode}),k.OidcProvider=ne,k.OidcSecure=D,k.OidcUserStatus=Y,k.useOidc=ce,k.useOidcAccessToken=ae,k.useOidcFetch=I,k.useOidcIdToken=de,k.useOidcUser=ue,k.withOidcFetch=z,k.withOidcSecure=oe,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
|
|
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"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axa-fr/react-oidc",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.26.1-alpha.1797",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.umd.cjs",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"lint": "eslint src"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@axa-fr/oidc-client-service-worker": "7.
|
|
44
|
-
"@axa-fr/oidc-client": "7.
|
|
43
|
+
"@axa-fr/oidc-client-service-worker": "7.26.1-alpha.1797",
|
|
44
|
+
"@axa-fr/oidc-client": "7.26.1-alpha.1797"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"react": "^17.0.0 || ^18.0.0 || ^19.0.0"
|
package/src/OidcProvider.tsx
CHANGED
|
@@ -102,6 +102,12 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
|
|
|
102
102
|
getFetch = null,
|
|
103
103
|
location = null,
|
|
104
104
|
}) => {
|
|
105
|
+
if (configuration && configuration.redirect_uri && configuration.silent_redirect_uri) {
|
|
106
|
+
if (configuration.redirect_uri === configuration.silent_redirect_uri) {
|
|
107
|
+
throw new Error('redirect_uri and silent_redirect_uri must be different');
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
105
111
|
const getOidc = (configurationName = 'default') => {
|
|
106
112
|
return OidcClient.getOrCreate(getFetch ?? getFetchDefault, location ?? new OidcLocation())(
|
|
107
113
|
configuration,
|