@axa-fr/react-oidc 7.27.17 → 7.27.18
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/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +157 -157
- package/dist/index.umd.cjs +1 -1
- package/package.json +3 -3
- package/src/index.ts +3 -0
package/dist/index.d.ts
CHANGED
|
@@ -6,5 +6,5 @@ export { useOidc, useOidcAccessToken, useOidcIdToken } from './ReactOidc.js';
|
|
|
6
6
|
export { OidcUserStatus, useOidcUser } from './User.js';
|
|
7
7
|
export type { AuthorityConfiguration, Fetch, ILOidcLocation, OidcConfiguration, StringMap, } from '@axa-fr/oidc-client';
|
|
8
8
|
export type { OidcUserInfo } from '@axa-fr/oidc-client';
|
|
9
|
-
export { OidcClient, OidcLocation, TokenAutomaticRenewMode, TokenRenewMode, } from '@axa-fr/oidc-client';
|
|
9
|
+
export { isOidcStateError, OidcClient, OidcLocation, OidcStateError, OidcStateErrorCode, TokenAutomaticRenewMode, TokenRenewMode, } from '@axa-fr/oidc-client';
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC9D,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxD,YAAY,EACV,sBAAsB,EACtB,KAAK,EACL,cAAc,EACd,iBAAiB,EACjB,SAAS,GACV,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EACL,UAAU,EACV,YAAY,EACZ,uBAAuB,EACvB,cAAc,GACf,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC9D,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxD,YAAY,EACV,sBAAsB,EACtB,KAAK,EACL,cAAc,EACd,iBAAiB,EACjB,SAAS,GACV,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,cAAc,EACd,kBAAkB,EAClB,uBAAuB,EACvB,cAAc,GACf,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { OidcClient as e, OidcClient as t, OidcLocation as n, OidcLocation as r,
|
|
2
|
-
import
|
|
3
|
-
import { Fragment as
|
|
1
|
+
import { OidcClient as e, OidcClient as t, OidcLocation as n, OidcLocation as r, OidcStateError as i, OidcStateErrorCode as a, TokenAutomaticRenewMode as o, TokenRenewMode as s, getFetchDefault as c, getParseQueryStringFromLocation as l, getPath as u, isOidcStateError as d } from "@axa-fr/oidc-client";
|
|
2
|
+
import f, { useCallback as p, useEffect as m, useRef as h, useState as g } from "react";
|
|
3
|
+
import { Fragment as _, jsx as v, jsxs as y } from "react/jsx-runtime";
|
|
4
4
|
//#region src/FetchToken.tsx
|
|
5
|
-
var
|
|
6
|
-
let { fetch: a } =
|
|
7
|
-
return /* @__PURE__ */
|
|
5
|
+
var b = "default", x = (e, t, n = !1) => async (...r) => await t().fetchWithTokens(e, n)(...r), S = (e = null, t = b, n = !1) => (r) => (i) => {
|
|
6
|
+
let { fetch: a } = C(e || i.fetch, t, n);
|
|
7
|
+
return /* @__PURE__ */ v(r, {
|
|
8
8
|
...i,
|
|
9
9
|
fetch: a
|
|
10
10
|
});
|
|
11
|
-
},
|
|
11
|
+
}, C = (e = null, n = b, r = !1) => {
|
|
12
12
|
let i = e || window.fetch, a = t.getOrThrow;
|
|
13
|
-
return { fetch:
|
|
13
|
+
return { fetch: p((e, t) => x(i, () => a(n), r)(e, t), [
|
|
14
14
|
i,
|
|
15
15
|
n,
|
|
16
16
|
r
|
|
17
17
|
]) };
|
|
18
|
-
},
|
|
18
|
+
}, w = () => /* @__PURE__ */ v("div", {
|
|
19
19
|
className: "oidc-authenticating",
|
|
20
|
-
children: /* @__PURE__ */
|
|
20
|
+
children: /* @__PURE__ */ y("div", {
|
|
21
21
|
className: "oidc-authenticating__container",
|
|
22
|
-
children: [/* @__PURE__ */
|
|
22
|
+
children: [/* @__PURE__ */ v("h1", {
|
|
23
23
|
className: "oidc-authenticating__title",
|
|
24
24
|
children: "Error authentication"
|
|
25
|
-
}), /* @__PURE__ */
|
|
25
|
+
}), /* @__PURE__ */ v("p", {
|
|
26
26
|
className: "oidc-authenticating__content",
|
|
27
27
|
children: "An error occurred during authentication."
|
|
28
28
|
})]
|
|
29
29
|
})
|
|
30
|
-
}),
|
|
30
|
+
}), T = () => /* @__PURE__ */ v("div", {
|
|
31
31
|
className: "oidc-authenticating",
|
|
32
|
-
children: /* @__PURE__ */
|
|
32
|
+
children: /* @__PURE__ */ y("div", {
|
|
33
33
|
className: "oidc-authenticating__container",
|
|
34
|
-
children: [/* @__PURE__ */
|
|
34
|
+
children: [/* @__PURE__ */ v("h1", {
|
|
35
35
|
className: "oidc-authenticating__title",
|
|
36
36
|
children: "Authentication in progress"
|
|
37
|
-
}), /* @__PURE__ */
|
|
37
|
+
}), /* @__PURE__ */ v("p", {
|
|
38
38
|
className: "oidc-authenticating__content",
|
|
39
39
|
children: "You will be redirected to the login page."
|
|
40
40
|
})]
|
|
41
41
|
})
|
|
42
|
-
}),
|
|
42
|
+
}), E = () => Math.random().toString(36).slice(2, 8), D = (e, t) => (n, r) => {
|
|
43
43
|
if (typeof e.CustomEvent == "function") return new e.CustomEvent(n, r);
|
|
44
44
|
let i = r || {
|
|
45
45
|
bubbles: !1,
|
|
@@ -47,27 +47,27 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
47
47
|
detail: void 0
|
|
48
48
|
}, a = t.createEvent("CustomEvent");
|
|
49
49
|
return a.initCustomEvent(n, i.bubbles, i.cancelable, i.detail), a.prototype = e.Event.prototype, a;
|
|
50
|
-
},
|
|
50
|
+
}, O = (e, t, n) => ({ replaceState: (r, i) => {
|
|
51
51
|
let a = n(), o = i || e.history.state;
|
|
52
52
|
e.history.replaceState({
|
|
53
53
|
key: a,
|
|
54
54
|
state: o
|
|
55
55
|
}, null, r), e.dispatchEvent(t("popstate"));
|
|
56
|
-
} }),
|
|
56
|
+
} }), k = () => O(window, D(window, document), E), A = () => /* @__PURE__ */ v("div", {
|
|
57
57
|
className: "oidc-callback",
|
|
58
|
-
children: /* @__PURE__ */
|
|
58
|
+
children: /* @__PURE__ */ y("div", {
|
|
59
59
|
className: "oidc-callback__container",
|
|
60
|
-
children: [/* @__PURE__ */
|
|
60
|
+
children: [/* @__PURE__ */ v("h1", {
|
|
61
61
|
className: "oidc-callback__title",
|
|
62
62
|
children: "Authentication complete"
|
|
63
|
-
}), /* @__PURE__ */
|
|
63
|
+
}), /* @__PURE__ */ v("p", {
|
|
64
64
|
className: "oidc-callback__content",
|
|
65
65
|
children: "You will be redirected to your application."
|
|
66
66
|
})]
|
|
67
67
|
})
|
|
68
|
-
}),
|
|
69
|
-
let [o, s] =
|
|
70
|
-
return
|
|
68
|
+
}), j = 200, M = (e, t = window) => t.location.pathname === e || e === "/", N = ({ callBackError: e, callBackSuccess: n, configurationName: r, withCustomHistory: i, navigateAfterCallback: a }) => {
|
|
69
|
+
let [o, s] = g(!1);
|
|
70
|
+
return m(() => {
|
|
71
71
|
let e = !0;
|
|
72
72
|
return (async () => {
|
|
73
73
|
let n = t.getOrThrow;
|
|
@@ -85,11 +85,11 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
85
85
|
error: n
|
|
86
86
|
}), e && (console.warn(n), s(!0));
|
|
87
87
|
}
|
|
88
|
-
else (i ? i() :
|
|
88
|
+
else (i ? i() : k()).replaceState(l), await new Promise((e) => {
|
|
89
89
|
setTimeout(() => {
|
|
90
90
|
e();
|
|
91
|
-
},
|
|
92
|
-
}), e && (
|
|
91
|
+
}, j);
|
|
92
|
+
}), e && (M(l) ? o.publishEvent(t.eventNames.loginCallbackAsync_navigated, {
|
|
93
93
|
configurationName: r,
|
|
94
94
|
callbackPath: l
|
|
95
95
|
}) : (o.publishEvent(t.eventNames.loginCallbackAsync_navigation_error, {
|
|
@@ -103,233 +103,233 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
103
103
|
})(), () => {
|
|
104
104
|
e = !1;
|
|
105
105
|
};
|
|
106
|
-
}, []),
|
|
107
|
-
},
|
|
106
|
+
}, []), v(o ? e || w : n || A, { configurationName: r });
|
|
107
|
+
}, P = () => /* @__PURE__ */ v("span", {
|
|
108
108
|
className: "oidc-loading",
|
|
109
109
|
children: "Loading"
|
|
110
|
-
}),
|
|
110
|
+
}), F = () => /* @__PURE__ */ v("div", {
|
|
111
111
|
className: "oidc-loading-timeout",
|
|
112
|
-
children: /* @__PURE__ */
|
|
112
|
+
children: /* @__PURE__ */ y("div", {
|
|
113
113
|
className: "oidc-loading-timeout__container",
|
|
114
|
-
children: [/* @__PURE__ */
|
|
114
|
+
children: [/* @__PURE__ */ v("h1", {
|
|
115
115
|
className: "oidc-loading-timeout__title",
|
|
116
116
|
children: "Loading timeout"
|
|
117
|
-
}), /* @__PURE__ */
|
|
117
|
+
}), /* @__PURE__ */ v("p", {
|
|
118
118
|
className: "oidc-loading-timeout__content",
|
|
119
119
|
children: "Authentication is taking longer than expected. Please try refreshing the page."
|
|
120
120
|
})]
|
|
121
121
|
})
|
|
122
|
-
}),
|
|
122
|
+
}), ee = () => /* @__PURE__ */ v("div", {
|
|
123
123
|
className: "oidc-serviceworker",
|
|
124
|
-
children: /* @__PURE__ */
|
|
124
|
+
children: /* @__PURE__ */ y("div", {
|
|
125
125
|
className: "oidc-serviceworker__container",
|
|
126
|
-
children: [/* @__PURE__ */
|
|
126
|
+
children: [/* @__PURE__ */ v("h1", {
|
|
127
127
|
className: "oidc-serviceworker__title",
|
|
128
128
|
children: "Unable to authenticate on this browser"
|
|
129
|
-
}), /* @__PURE__ */
|
|
129
|
+
}), /* @__PURE__ */ v("p", {
|
|
130
130
|
className: "oidc-serviceworker__content",
|
|
131
131
|
children: "Your browser is not secure enough to make authentication work. Try updating your browser or use a newer browser."
|
|
132
132
|
})]
|
|
133
133
|
})
|
|
134
|
-
}),
|
|
134
|
+
}), te = () => /* @__PURE__ */ v("div", {
|
|
135
135
|
className: "oidc-session-lost",
|
|
136
|
-
children: /* @__PURE__ */
|
|
136
|
+
children: /* @__PURE__ */ y("div", {
|
|
137
137
|
className: "oidc-session-lost__container",
|
|
138
|
-
children: [/* @__PURE__ */
|
|
138
|
+
children: [/* @__PURE__ */ v("h1", {
|
|
139
139
|
className: "oidc-session-lost__title",
|
|
140
140
|
children: "Session timed out"
|
|
141
|
-
}), /* @__PURE__ */
|
|
141
|
+
}), /* @__PURE__ */ v("p", {
|
|
142
142
|
className: "oidc-session-lost__content",
|
|
143
143
|
children: "Your session has expired. Please re-authenticate."
|
|
144
144
|
})]
|
|
145
145
|
})
|
|
146
|
-
}),
|
|
146
|
+
}), I = ({ configurationName: e }) => (m(() => {
|
|
147
147
|
(async () => {
|
|
148
148
|
t.getOrThrow(e).silentLoginCallbackAsync();
|
|
149
149
|
})().catch((e) => {
|
|
150
150
|
console.error("Error during silent login callback:", e);
|
|
151
151
|
});
|
|
152
|
-
}, [e]), null),
|
|
153
|
-
let n =
|
|
152
|
+
}, [e]), null), L = ({ configurationName: e }) => {
|
|
153
|
+
let n = l(window.location.href), r = t.getOrThrow, i = r(e), a = null;
|
|
154
154
|
for (let [e, t] of Object.entries(n)) e === "state" || e === "scope" || (a === null && (a = {}), a[e] = t);
|
|
155
|
-
return
|
|
155
|
+
return m(() => {
|
|
156
156
|
i.tokens || i.loginAsync(null, a, !0, n.scope);
|
|
157
|
-
}, []), /* @__PURE__ */
|
|
158
|
-
},
|
|
159
|
-
let [
|
|
160
|
-
|
|
161
|
-
let e = () =>
|
|
157
|
+
}, []), /* @__PURE__ */ v(_, {});
|
|
158
|
+
}, R = f.memo(({ callbackErrorComponent: e, callbackSuccessComponent: t, redirect_uri: n, silent_redirect_uri: r, silent_login_uri: i, children: a, configurationName: o, withCustomHistory: s = null, navigateAfterCallback: c = null }) => {
|
|
159
|
+
let [l, d] = g(window ? u(window.location.href) : "");
|
|
160
|
+
m(() => {
|
|
161
|
+
let e = () => d(u(window.location.href));
|
|
162
162
|
return e(), window.addEventListener("popstate", e, !1), () => window.removeEventListener("popstate", e, !1);
|
|
163
163
|
}, []);
|
|
164
|
-
let
|
|
165
|
-
if (r &&
|
|
166
|
-
if (i &&
|
|
167
|
-
switch (
|
|
168
|
-
case
|
|
164
|
+
let f = u(n);
|
|
165
|
+
if (r && l === u(r)) return /* @__PURE__ */ v(I, { configurationName: o });
|
|
166
|
+
if (i && l === u(i)) return /* @__PURE__ */ v(L, { configurationName: o });
|
|
167
|
+
switch (l) {
|
|
168
|
+
case f: return /* @__PURE__ */ v(N, {
|
|
169
169
|
callBackError: e,
|
|
170
170
|
callBackSuccess: t,
|
|
171
171
|
configurationName: o,
|
|
172
172
|
withCustomHistory: s,
|
|
173
|
-
navigateAfterCallback:
|
|
173
|
+
navigateAfterCallback: c
|
|
174
174
|
});
|
|
175
|
-
default: return /* @__PURE__ */
|
|
175
|
+
default: return /* @__PURE__ */ v(_, { children: a });
|
|
176
176
|
}
|
|
177
|
-
}),
|
|
177
|
+
}), z = {
|
|
178
178
|
name: "",
|
|
179
179
|
data: null
|
|
180
|
-
},
|
|
181
|
-
let [i, a] =
|
|
182
|
-
return
|
|
180
|
+
}, B = ({ loadingComponent: e, children: n, configurationName: r }) => {
|
|
181
|
+
let [i, a] = g(!0), o = t.get, s = o(r);
|
|
182
|
+
return m(() => {
|
|
183
183
|
let e = !0;
|
|
184
184
|
return s && s.tryKeepExistingSessionAsync().then(() => {
|
|
185
185
|
e && a(!1);
|
|
186
186
|
}), () => {
|
|
187
187
|
e = !1;
|
|
188
188
|
};
|
|
189
|
-
}, [r]), /* @__PURE__ */
|
|
190
|
-
},
|
|
189
|
+
}, [r]), /* @__PURE__ */ v(_, { children: i ? /* @__PURE__ */ v(e, { configurationName: r }) : /* @__PURE__ */ v(_, { children: n }) });
|
|
190
|
+
}, V = ({ isLoading: e, loadingComponent: t, children: n, configurationName: r }) => e ? /* @__PURE__ */ v(t, {
|
|
191
191
|
configurationName: r,
|
|
192
192
|
children: n
|
|
193
|
-
}) : /* @__PURE__ */
|
|
193
|
+
}) : /* @__PURE__ */ v(_, { children: n }), H = 3e4, U = (e, n) => e === t.eventNames.token_acquired || e === t.eventNames.token_renewed || e === t.eventNames.loginCallbackAsync_end ? !0 : e === t.eventNames.tryKeepExistingSessionAsync_end ? n?.success === !0 : !1, W = ({ children: e, configuration: n, configurationName: i = "default", callbackSuccessComponent: a = A, authenticatingComponent: o = T, loadingComponent: s = P, loadingTimeoutComponent: l = F, serviceWorkerNotSupportedComponent: u = ee, authenticatingErrorComponent: d = w, sessionLostComponent: f = te, onSessionLost: p = null, onLogoutFromAnotherTab: h = null, onLogoutFromSameTab: _ = null, withCustomHistory: y = null, navigateAfterCallback: b = null, onEvent: x = null, getFetch: S = null, location: C = null }) => {
|
|
194
194
|
if (n && n.redirect_uri && n.silent_redirect_uri && n.redirect_uri === n.silent_redirect_uri) throw Error("redirect_uri and silent_redirect_uri must be different");
|
|
195
|
-
let E = (e = "default") => t.getOrCreate(
|
|
196
|
-
|
|
195
|
+
let E = (e = "default") => t.getOrCreate(S ?? c, C ?? new r())(n, e), [D, O] = g(z), [k, j] = g(!1), [M, N] = g(i);
|
|
196
|
+
m(() => {
|
|
197
197
|
let e = E(i).subscribeEvents((e, t) => {
|
|
198
|
-
|
|
198
|
+
x && x(i, e, t);
|
|
199
199
|
});
|
|
200
200
|
return () => {
|
|
201
201
|
E(i).removeEventSubscription(e);
|
|
202
202
|
};
|
|
203
|
-
}, [i,
|
|
203
|
+
}, [i, x]), m(() => {
|
|
204
204
|
let e = E(i).subscribeEvents((e, r) => {
|
|
205
|
-
if (
|
|
206
|
-
if (
|
|
207
|
-
|
|
205
|
+
if (U(e, r) && j(!0), e === t.eventNames.refreshTokensAsync_error || e === t.eventNames.syncTokensAsync_error) {
|
|
206
|
+
if (p != null) {
|
|
207
|
+
p();
|
|
208
208
|
return;
|
|
209
209
|
}
|
|
210
|
-
|
|
210
|
+
O({
|
|
211
211
|
name: e,
|
|
212
212
|
data: r
|
|
213
213
|
});
|
|
214
214
|
} else if (e === t.eventNames.logout_from_another_tab) {
|
|
215
|
-
if (
|
|
216
|
-
|
|
215
|
+
if (h != null) {
|
|
216
|
+
h();
|
|
217
217
|
return;
|
|
218
218
|
}
|
|
219
|
-
|
|
219
|
+
O({
|
|
220
220
|
name: e,
|
|
221
221
|
data: r
|
|
222
222
|
});
|
|
223
|
-
} else e === t.eventNames.logout_from_same_tab ?
|
|
223
|
+
} else e === t.eventNames.logout_from_same_tab ? _?.() : (e === t.eventNames.loadingTimeout_error || e === t.eventNames.loginAsync_begin || e === t.eventNames.loginCallbackAsync_end || e === t.eventNames.loginAsync_error || e === t.eventNames.loginCallbackAsync_error || e === t.eventNames.service_worker_not_supported_by_browser && n.service_worker_only === !0) && O({
|
|
224
224
|
name: e,
|
|
225
225
|
data: r
|
|
226
226
|
});
|
|
227
227
|
});
|
|
228
228
|
return queueMicrotask(() => {
|
|
229
|
-
|
|
229
|
+
N(i);
|
|
230
230
|
}), () => {
|
|
231
|
-
E(i).removeEventSubscription(e),
|
|
231
|
+
E(i).removeEventSubscription(e), O(z), j(!1);
|
|
232
232
|
};
|
|
233
|
-
}, [n, i]),
|
|
234
|
-
let e = n?.loading_timeout_ms ??
|
|
235
|
-
if (e <= 0 ||
|
|
233
|
+
}, [n, i]), m(() => {
|
|
234
|
+
let e = n?.loading_timeout_ms ?? H;
|
|
235
|
+
if (e <= 0 || k || E(i)?.tokens != null || !(D.name === "" || D.name === t.eventNames.loginAsync_begin)) return;
|
|
236
236
|
let r = setTimeout(() => {
|
|
237
237
|
E(i).publishEvent(t.eventNames.loadingTimeout_error, { timeoutMs: e });
|
|
238
238
|
}, e);
|
|
239
239
|
return () => clearTimeout(r);
|
|
240
240
|
}, [
|
|
241
|
-
|
|
242
|
-
|
|
241
|
+
D.name,
|
|
242
|
+
k,
|
|
243
243
|
i,
|
|
244
244
|
n
|
|
245
245
|
]);
|
|
246
|
-
let
|
|
247
|
-
switch (
|
|
248
|
-
case t.eventNames.service_worker_not_supported_by_browser: return /* @__PURE__ */
|
|
249
|
-
loadingComponent:
|
|
250
|
-
isLoading:
|
|
246
|
+
let I = f, L = o, W = s, G = l, K = u, q = d, J = M !== i, Y = E(i);
|
|
247
|
+
switch (D.name) {
|
|
248
|
+
case t.eventNames.service_worker_not_supported_by_browser: return /* @__PURE__ */ v(V, {
|
|
249
|
+
loadingComponent: W,
|
|
250
|
+
isLoading: J,
|
|
251
251
|
configurationName: i,
|
|
252
|
-
children: /* @__PURE__ */
|
|
252
|
+
children: /* @__PURE__ */ v(K, { configurationName: i })
|
|
253
253
|
});
|
|
254
|
-
case t.eventNames.loginAsync_begin: return /* @__PURE__ */
|
|
255
|
-
loadingComponent:
|
|
256
|
-
isLoading:
|
|
254
|
+
case t.eventNames.loginAsync_begin: return /* @__PURE__ */ v(V, {
|
|
255
|
+
loadingComponent: W,
|
|
256
|
+
isLoading: J,
|
|
257
257
|
configurationName: i,
|
|
258
|
-
children: /* @__PURE__ */
|
|
258
|
+
children: /* @__PURE__ */ v(L, { configurationName: i })
|
|
259
259
|
});
|
|
260
|
-
case t.eventNames.loadingTimeout_error: return /* @__PURE__ */
|
|
261
|
-
loadingComponent:
|
|
262
|
-
isLoading:
|
|
260
|
+
case t.eventNames.loadingTimeout_error: return /* @__PURE__ */ v(V, {
|
|
261
|
+
loadingComponent: W,
|
|
262
|
+
isLoading: J,
|
|
263
263
|
configurationName: i,
|
|
264
|
-
children: /* @__PURE__ */
|
|
264
|
+
children: /* @__PURE__ */ v(G, { configurationName: i })
|
|
265
265
|
});
|
|
266
266
|
case t.eventNames.loginAsync_error:
|
|
267
|
-
case t.eventNames.loginCallbackAsync_error: return /* @__PURE__ */
|
|
268
|
-
loadingComponent:
|
|
269
|
-
isLoading:
|
|
267
|
+
case t.eventNames.loginCallbackAsync_error: return /* @__PURE__ */ v(V, {
|
|
268
|
+
loadingComponent: W,
|
|
269
|
+
isLoading: J,
|
|
270
270
|
configurationName: i,
|
|
271
|
-
children: /* @__PURE__ */
|
|
271
|
+
children: /* @__PURE__ */ v(q, { configurationName: i })
|
|
272
272
|
});
|
|
273
273
|
case t.eventNames.refreshTokensAsync_error:
|
|
274
274
|
case t.eventNames.syncTokensAsync_error:
|
|
275
|
-
case t.eventNames.logout_from_another_tab: return /* @__PURE__ */
|
|
276
|
-
loadingComponent:
|
|
277
|
-
isLoading:
|
|
275
|
+
case t.eventNames.logout_from_another_tab: return /* @__PURE__ */ v(V, {
|
|
276
|
+
loadingComponent: W,
|
|
277
|
+
isLoading: J,
|
|
278
278
|
configurationName: i,
|
|
279
|
-
children: /* @__PURE__ */
|
|
279
|
+
children: /* @__PURE__ */ v(I, { configurationName: i })
|
|
280
280
|
});
|
|
281
|
-
default: return /* @__PURE__ */
|
|
282
|
-
loadingComponent:
|
|
283
|
-
isLoading:
|
|
281
|
+
default: return /* @__PURE__ */ v(V, {
|
|
282
|
+
loadingComponent: W,
|
|
283
|
+
isLoading: J,
|
|
284
284
|
configurationName: i,
|
|
285
|
-
children: /* @__PURE__ */
|
|
286
|
-
redirect_uri:
|
|
287
|
-
silent_redirect_uri:
|
|
288
|
-
silent_login_uri:
|
|
285
|
+
children: /* @__PURE__ */ v(R, {
|
|
286
|
+
redirect_uri: Y.configuration.redirect_uri,
|
|
287
|
+
silent_redirect_uri: Y.configuration.silent_redirect_uri,
|
|
288
|
+
silent_login_uri: Y.configuration.silent_login_uri,
|
|
289
289
|
callbackSuccessComponent: a,
|
|
290
|
-
callbackErrorComponent:
|
|
291
|
-
authenticatingComponent:
|
|
290
|
+
callbackErrorComponent: d,
|
|
291
|
+
authenticatingComponent: o,
|
|
292
292
|
configurationName: i,
|
|
293
293
|
withCustomHistory: y,
|
|
294
294
|
navigateAfterCallback: b,
|
|
295
|
-
location:
|
|
296
|
-
children: /* @__PURE__ */
|
|
297
|
-
loadingComponent:
|
|
295
|
+
location: C ?? new r(),
|
|
296
|
+
children: /* @__PURE__ */ v(B, {
|
|
297
|
+
loadingComponent: W,
|
|
298
298
|
configurationName: i,
|
|
299
299
|
children: e
|
|
300
300
|
})
|
|
301
301
|
})
|
|
302
302
|
});
|
|
303
303
|
}
|
|
304
|
-
},
|
|
304
|
+
}, G = ({ children: e, callbackPath: n = null, extras: r = null, configurationName: i = "default" }) => {
|
|
305
305
|
let a = t.getOrThrow, o = a(i);
|
|
306
|
-
return
|
|
306
|
+
return m(() => {
|
|
307
307
|
!o.tokens && !o.isLoggingOut && o.loginAsync(n, r);
|
|
308
308
|
}, [
|
|
309
309
|
i,
|
|
310
310
|
n,
|
|
311
311
|
r
|
|
312
|
-
]), o.tokens ? /* @__PURE__ */
|
|
313
|
-
},
|
|
312
|
+
]), o.tokens ? /* @__PURE__ */ v(_, { children: e }) : null;
|
|
313
|
+
}, K = (e, t = null, n = null, r = "default") => (i) => /* @__PURE__ */ v(G, {
|
|
314
314
|
callbackPath: t,
|
|
315
315
|
extras: n,
|
|
316
316
|
configurationName: r,
|
|
317
|
-
children: /* @__PURE__ */
|
|
318
|
-
}),
|
|
319
|
-
|
|
320
|
-
},
|
|
317
|
+
children: /* @__PURE__ */ v(e, { ...i })
|
|
318
|
+
}), q = /* @__PURE__ */ new Set(), J = (e) => {
|
|
319
|
+
q.has(e) || (q.add(e), console.warn(`@axa-fr/react-oidc: no OIDC configuration found for "${e}". Make sure to wrap your component tree with <OidcProvider configurationName="${e}">. Hooks are returning safe default values (issue #1679).`));
|
|
320
|
+
}, Y = "default", X = (e, t) => {
|
|
321
321
|
let n = !1, r = e(t);
|
|
322
322
|
return r && (n = r.tokens != null), n;
|
|
323
|
-
},
|
|
324
|
-
let n = t.get, [r, i] =
|
|
325
|
-
return
|
|
323
|
+
}, Z = (e = Y) => {
|
|
324
|
+
let n = t.get, [r, i] = g(() => X(n, e));
|
|
325
|
+
return m(() => {
|
|
326
326
|
let r = !0, a = n(e);
|
|
327
327
|
if (!a) {
|
|
328
|
-
|
|
328
|
+
J(e);
|
|
329
329
|
return;
|
|
330
330
|
}
|
|
331
331
|
let o = a.subscribeEvents((a, o) => {
|
|
332
|
-
(a === t.eventNames.logout_from_another_tab || a === t.eventNames.logout_from_same_tab || a === t.eventNames.token_acquired) && r && i(
|
|
332
|
+
(a === t.eventNames.logout_from_another_tab || a === t.eventNames.logout_from_same_tab || a === t.eventNames.token_acquired) && r && i(X(n, e));
|
|
333
333
|
});
|
|
334
334
|
return () => {
|
|
335
335
|
r = !1, a.removeEventSubscription(o);
|
|
@@ -337,15 +337,15 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
337
337
|
}, [e]), {
|
|
338
338
|
login: (t = void 0, r = void 0, i = !1, a = void 0) => {
|
|
339
339
|
let o = n(e);
|
|
340
|
-
return o ? o.loginAsync(t, r, !1, a, i) : (
|
|
340
|
+
return o ? o.loginAsync(t, r, !1, a, i) : (J(e), Promise.resolve());
|
|
341
341
|
},
|
|
342
342
|
logout: (t = void 0, r = void 0) => {
|
|
343
343
|
let i = n(e);
|
|
344
|
-
return i ? i.logoutAsync(t, r) : (
|
|
344
|
+
return i ? i.logoutAsync(t, r) : (J(e), Promise.resolve());
|
|
345
345
|
},
|
|
346
346
|
renewTokens: async (t = void 0) => {
|
|
347
347
|
let r = n(e);
|
|
348
|
-
if (!r) return
|
|
348
|
+
if (!r) return J(e), {
|
|
349
349
|
accessToken: null,
|
|
350
350
|
accessTokenPayload: null,
|
|
351
351
|
idToken: null,
|
|
@@ -361,12 +361,12 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
361
361
|
},
|
|
362
362
|
isAuthenticated: r
|
|
363
363
|
};
|
|
364
|
-
},
|
|
364
|
+
}, Q = {
|
|
365
365
|
accessToken: null,
|
|
366
366
|
accessTokenPayload: null
|
|
367
|
-
},
|
|
367
|
+
}, ne = (e) => {
|
|
368
368
|
let n = t.get, r = n(e);
|
|
369
|
-
if (!r) return
|
|
369
|
+
if (!r) return Q;
|
|
370
370
|
if (r.tokens) {
|
|
371
371
|
let e = r.tokens;
|
|
372
372
|
return {
|
|
@@ -375,26 +375,26 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
375
375
|
generateDemonstrationOfProofOfPossessionAsync: r.configuration.demonstrating_proof_of_possession ? (t, n) => r.generateDemonstrationOfProofOfPossessionAsync(e.accessToken, t, n) : null
|
|
376
376
|
};
|
|
377
377
|
}
|
|
378
|
-
return
|
|
378
|
+
return Q;
|
|
379
379
|
};
|
|
380
|
-
function
|
|
380
|
+
function re(e, t) {
|
|
381
381
|
return e.configuration.demonstrating_proof_of_possession ? (n, r, i = {}) => e.generateDemonstrationOfProofOfPossessionAsync(t.accessToken, n, r, i) : null;
|
|
382
382
|
}
|
|
383
|
-
var
|
|
384
|
-
let n = t.get, [r, i] =
|
|
385
|
-
return
|
|
383
|
+
var ie = (e = Y) => {
|
|
384
|
+
let n = t.get, [r, i] = g(() => ne(e));
|
|
385
|
+
return m(() => {
|
|
386
386
|
let r = !0, a = n(e);
|
|
387
387
|
if (!a) {
|
|
388
|
-
|
|
388
|
+
J(e);
|
|
389
389
|
return;
|
|
390
390
|
}
|
|
391
391
|
let o = a.subscribeEvents((e, n) => {
|
|
392
392
|
if ((e === t.eventNames.token_renewed || e === t.eventNames.token_acquired || e === t.eventNames.logout_from_another_tab || e === t.eventNames.logout_from_same_tab || e === t.eventNames.refreshTokensAsync_error || e === t.eventNames.syncTokensAsync_error) && r) {
|
|
393
393
|
let e = a.tokens;
|
|
394
|
-
i(e == null ?
|
|
394
|
+
i(e == null ? Q : {
|
|
395
395
|
accessToken: e.accessToken,
|
|
396
396
|
accessTokenPayload: e.accessTokenPayload,
|
|
397
|
-
generateDemonstrationOfProofOfPossessionAsync:
|
|
397
|
+
generateDemonstrationOfProofOfPossessionAsync: re(a, e)
|
|
398
398
|
});
|
|
399
399
|
}
|
|
400
400
|
});
|
|
@@ -405,7 +405,7 @@ var te = (e = J) => {
|
|
|
405
405
|
}, $ = {
|
|
406
406
|
idToken: null,
|
|
407
407
|
idTokenPayload: null
|
|
408
|
-
},
|
|
408
|
+
}, ae = (e) => {
|
|
409
409
|
let n = t.get, r = n(e);
|
|
410
410
|
if (!r) return $;
|
|
411
411
|
if (r.tokens) {
|
|
@@ -416,12 +416,12 @@ var te = (e = J) => {
|
|
|
416
416
|
};
|
|
417
417
|
}
|
|
418
418
|
return $;
|
|
419
|
-
},
|
|
420
|
-
let n = t.get, [r, i] =
|
|
421
|
-
return
|
|
419
|
+
}, oe = (e = Y) => {
|
|
420
|
+
let n = t.get, [r, i] = g(() => ae(e));
|
|
421
|
+
return m(() => {
|
|
422
422
|
let r = !0, a = n(e);
|
|
423
423
|
if (!a) {
|
|
424
|
-
|
|
424
|
+
J(e);
|
|
425
425
|
return;
|
|
426
426
|
}
|
|
427
427
|
let o = a.subscribeEvents((e, n) => {
|
|
@@ -437,17 +437,17 @@ var te = (e = J) => {
|
|
|
437
437
|
r = !1, a.removeEventSubscription(o);
|
|
438
438
|
};
|
|
439
439
|
}, [e]), r;
|
|
440
|
-
},
|
|
440
|
+
}, se = /* @__PURE__ */ function(e) {
|
|
441
441
|
return e.Unauthenticated = "Unauthenticated", e.Loading = "Loading user", e.Loaded = "User loaded", e.LoadingError = "Error loading user", e;
|
|
442
|
-
}({}),
|
|
443
|
-
let r = t.get(e), i = r ? r.userInfo() : null, [a, o] =
|
|
442
|
+
}({}), ce = (e = "default", n = !1) => {
|
|
443
|
+
let r = t.get(e), i = r ? r.userInfo() : null, [a, o] = g({
|
|
444
444
|
user: i,
|
|
445
445
|
status: i ? "User loaded" : "Unauthenticated"
|
|
446
|
-
}), [s, c] =
|
|
447
|
-
return
|
|
446
|
+
}), [s, c] = g(+!!i), l = h(+!!i);
|
|
447
|
+
return m(() => {
|
|
448
448
|
let r = t.get(e), i = !0;
|
|
449
449
|
if (!r) {
|
|
450
|
-
|
|
450
|
+
J(e);
|
|
451
451
|
return;
|
|
452
452
|
}
|
|
453
453
|
if (r.tokens) {
|
|
@@ -495,4 +495,4 @@ var te = (e = J) => {
|
|
|
495
495
|
};
|
|
496
496
|
};
|
|
497
497
|
//#endregion
|
|
498
|
-
export { e as OidcClient, n as OidcLocation,
|
|
498
|
+
export { e as OidcClient, n as OidcLocation, W as OidcProvider, G as OidcSecure, i as OidcStateError, a as OidcStateErrorCode, se as OidcUserStatus, o as TokenAutomaticRenewMode, s as TokenRenewMode, d as isOidcStateError, Z as useOidc, ie as useOidcAccessToken, C as useOidcFetch, oe as useOidcIdToken, ce as useOidcUser, S as withOidcFetch, K as withOidcSecure };
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@axa-fr/oidc-client`),require(`react`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@axa-fr/oidc-client`,`react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e[`react-oidc`]={},e._axa_fr_oidc_client,e.React,e.react_jsx_runtime))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var i=Object.create,a=Object.defineProperty,o=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,c=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty,u=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=s(t),c=0,u=i.length,d;c<u;c++)d=i[c],!l.call(e,d)&&d!==n&&a(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=o(t,d))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:i(c(e)),u(t||!e||!e.__esModule?a(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var d=`default`,f=(e,t,n=!1)=>async(...r)=>await t().fetchWithTokens(e,n)(...r),p=(e=null,t=d,n=!1)=>i=>a=>{let{fetch:o}=m(e||a.fetch,t,n);return(0,r.jsx)(i,{...a,fetch:o})},m=(e=null,r=d,i=!1)=>{let a=e||window.fetch,o=t.OidcClient.getOrThrow;return{fetch:(0,n.useCallback)((e,t)=>f(a,()=>o(r),i)(e,t),[a,r,i])}},h=()=>(0,r.jsx)(`div`,{className:`oidc-authenticating`,children:(0,r.jsxs)(`div`,{className:`oidc-authenticating__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-authenticating__title`,children:`Error authentication`}),(0,r.jsx)(`p`,{className:`oidc-authenticating__content`,children:`An error occurred during authentication.`})]})}),g=()=>(0,r.jsx)(`div`,{className:`oidc-authenticating`,children:(0,r.jsxs)(`div`,{className:`oidc-authenticating__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-authenticating__title`,children:`Authentication in progress`}),(0,r.jsx)(`p`,{className:`oidc-authenticating__content`,children:`You will be redirected to the login page.`})]})}),_=()=>Math.random().toString(36).slice(2,8),v=(e,t)=>(n,r)=>{if(typeof e.CustomEvent==`function`)return new e.CustomEvent(n,r);let i=r||{bubbles:!1,cancelable:!1,detail:void 0},a=t.createEvent(`CustomEvent`);return a.initCustomEvent(n,i.bubbles,i.cancelable,i.detail),a.prototype=e.Event.prototype,a},y=(e,t,n)=>({replaceState:(r,i)=>{let a=n(),o=i||e.history.state;e.history.replaceState({key:a,state:o},null,r),e.dispatchEvent(t(`popstate`))}}),b=()=>y(window,v(window,document),_),x=()=>(0,r.jsx)(`div`,{className:`oidc-callback`,children:(0,r.jsxs)(`div`,{className:`oidc-callback__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-callback__title`,children:`Authentication complete`}),(0,r.jsx)(`p`,{className:`oidc-callback__content`,children:`You will be redirected to your application.`})]})}),S=200,C=(e,t=window)=>t.location.pathname===e||e===`/`,w=({callBackError:e,callBackSuccess:i,configurationName:a,withCustomHistory:o,navigateAfterCallback:s})=>{let[c,l]=(0,n.useState)(!1);(0,n.useEffect)(()=>{let e=!0;return(async()=>{let n=t.OidcClient.getOrThrow;try{let r=n(a),{callbackPath:i}=await r.loginCallbackAsync(),c=i||`/`;if(s)try{await s(c),r.publishEvent(t.OidcClient.eventNames.loginCallbackAsync_navigated,{configurationName:a,callbackPath:c})}catch(n){r.publishEvent(t.OidcClient.eventNames.loginCallbackAsync_navigation_error,{configurationName:a,callbackPath:c,error:n}),e&&(console.warn(n),l(!0))}else (o?o():b()).replaceState(c),await new Promise(e=>{setTimeout(()=>{e()},S)}),e&&(C(c)?r.publishEvent(t.OidcClient.eventNames.loginCallbackAsync_navigated,{configurationName:a,callbackPath:c}):(r.publishEvent(t.OidcClient.eventNames.loginCallbackAsync_navigation_error,{configurationName:a,callbackPath:c,error:Error(`Navigation did not commit: expected "${c}" but found "${window.location.pathname}"`)}),l(!0)))}catch(t){e&&(console.warn(t),l(!0))}})(),()=>{e=!1}},[]);let u=e||h,d=i||x;return c?(0,r.jsx)(u,{configurationName:a}):(0,r.jsx)(d,{configurationName:a})},T=()=>(0,r.jsx)(`span`,{className:`oidc-loading`,children:`Loading`}),E=()=>(0,r.jsx)(`div`,{className:`oidc-loading-timeout`,children:(0,r.jsxs)(`div`,{className:`oidc-loading-timeout__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-loading-timeout__title`,children:`Loading timeout`}),(0,r.jsx)(`p`,{className:`oidc-loading-timeout__content`,children:`Authentication is taking longer than expected. Please try refreshing the page.`})]})}),D=()=>(0,r.jsx)(`div`,{className:`oidc-serviceworker`,children:(0,r.jsxs)(`div`,{className:`oidc-serviceworker__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-serviceworker__title`,children:`Unable to authenticate on this browser`}),(0,r.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.`})]})}),O=()=>(0,r.jsx)(`div`,{className:`oidc-session-lost`,children:(0,r.jsxs)(`div`,{className:`oidc-session-lost__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-session-lost__title`,children:`Session timed out`}),(0,r.jsx)(`p`,{className:`oidc-session-lost__content`,children:`Your session has expired. Please re-authenticate.`})]})}),k=({configurationName:e})=>((0,n.useEffect)(()=>{(async()=>{t.OidcClient.getOrThrow(e).silentLoginCallbackAsync()})().catch(e=>{console.error(`Error during silent login callback:`,e)})},[e]),null),A=({configurationName:e})=>{let i=(0,t.getParseQueryStringFromLocation)(window.location.href),a=t.OidcClient.getOrThrow,o=a(e),s=null;for(let[e,t]of Object.entries(i))e===`state`||e===`scope`||(s===null&&(s={}),s[e]=t);return(0,n.useEffect)(()=>{o.tokens||o.loginAsync(null,s,!0,i.scope)},[]),(0,r.jsx)(r.Fragment,{})},j=n.default.memo(({callbackErrorComponent:e,callbackSuccessComponent:i,redirect_uri:a,silent_redirect_uri:o,silent_login_uri:s,children:c,configurationName:l,withCustomHistory:u=null,navigateAfterCallback:d=null})=>{let[f,p]=(0,n.useState)(window?(0,t.getPath)(window.location.href):``);(0,n.useEffect)(()=>{let e=()=>p((0,t.getPath)(window.location.href));return e(),window.addEventListener(`popstate`,e,!1),()=>window.removeEventListener(`popstate`,e,!1)},[]);let m=(0,t.getPath)(a);if(o&&f===(0,t.getPath)(o))return(0,r.jsx)(k,{configurationName:l});if(s&&f===(0,t.getPath)(s))return(0,r.jsx)(A,{configurationName:l});switch(f){case m:return(0,r.jsx)(w,{callBackError:e,callBackSuccess:i,configurationName:l,withCustomHistory:u,navigateAfterCallback:d});default:return(0,r.jsx)(r.Fragment,{children:c})}}),M={name:``,data:null},N=({loadingComponent:e,children:i,configurationName:a})=>{let[o,s]=(0,n.useState)(!0),c=t.OidcClient.get,l=c(a);return(0,n.useEffect)(()=>{let e=!0;return l&&l.tryKeepExistingSessionAsync().then(()=>{e&&s(!1)}),()=>{e=!1}},[a]),(0,r.jsx)(r.Fragment,{children:o?(0,r.jsx)(e,{configurationName:a}):(0,r.jsx)(r.Fragment,{children:i})})},P=({isLoading:e,loadingComponent:t,children:n,configurationName:i})=>{let a=t;return e?(0,r.jsx)(a,{configurationName:i,children:n}):(0,r.jsx)(r.Fragment,{children:n})},F=3e4,I=(e,n)=>e===t.OidcClient.eventNames.token_acquired||e===t.OidcClient.eventNames.token_renewed||e===t.OidcClient.eventNames.loginCallbackAsync_end?!0:e===t.OidcClient.eventNames.tryKeepExistingSessionAsync_end?n?.success===!0:!1,L=({children:e,configuration:i,configurationName:a=`default`,callbackSuccessComponent:o=x,authenticatingComponent:s=g,loadingComponent:c=T,loadingTimeoutComponent:l=E,serviceWorkerNotSupportedComponent:u=D,authenticatingErrorComponent:d=h,sessionLostComponent:f=O,onSessionLost:p=null,onLogoutFromAnotherTab:m=null,onLogoutFromSameTab:_=null,withCustomHistory:v=null,navigateAfterCallback:y=null,onEvent:b=null,getFetch:S=null,location:C=null})=>{if(i&&i.redirect_uri&&i.silent_redirect_uri&&i.redirect_uri===i.silent_redirect_uri)throw Error(`redirect_uri and silent_redirect_uri must be different`);let w=(e=`default`)=>t.OidcClient.getOrCreate(S??t.getFetchDefault,C??new t.OidcLocation)(i,e),[k,A]=(0,n.useState)(M),[L,R]=(0,n.useState)(!1),[z,B]=(0,n.useState)(a);(0,n.useEffect)(()=>{let e=w(a).subscribeEvents((e,t)=>{b&&b(a,e,t)});return()=>{w(a).removeEventSubscription(e)}},[a,b]),(0,n.useEffect)(()=>{let e=w(a).subscribeEvents((e,n)=>{if(I(e,n)&&R(!0),e===t.OidcClient.eventNames.refreshTokensAsync_error||e===t.OidcClient.eventNames.syncTokensAsync_error){if(p!=null){p();return}A({name:e,data:n})}else if(e===t.OidcClient.eventNames.logout_from_another_tab){if(m!=null){m();return}A({name:e,data:n})}else e===t.OidcClient.eventNames.logout_from_same_tab?_?.():(e===t.OidcClient.eventNames.loadingTimeout_error||e===t.OidcClient.eventNames.loginAsync_begin||e===t.OidcClient.eventNames.loginCallbackAsync_end||e===t.OidcClient.eventNames.loginAsync_error||e===t.OidcClient.eventNames.loginCallbackAsync_error||e===t.OidcClient.eventNames.service_worker_not_supported_by_browser&&i.service_worker_only===!0)&&A({name:e,data:n})});return queueMicrotask(()=>{B(a)}),()=>{w(a).removeEventSubscription(e),A(M),R(!1)}},[i,a]),(0,n.useEffect)(()=>{let e=i?.loading_timeout_ms??F;if(e<=0||L||w(a)?.tokens!=null||!(k.name===``||k.name===t.OidcClient.eventNames.loginAsync_begin))return;let n=setTimeout(()=>{w(a).publishEvent(t.OidcClient.eventNames.loadingTimeout_error,{timeoutMs:e})},e);return()=>clearTimeout(n)},[k.name,L,a,i]);let V=f,H=s,U=c,W=l,G=u,K=d,q=z!==a,J=w(a);switch(k.name){case t.OidcClient.eventNames.service_worker_not_supported_by_browser:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(G,{configurationName:a})});case t.OidcClient.eventNames.loginAsync_begin:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(H,{configurationName:a})});case t.OidcClient.eventNames.loadingTimeout_error:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(W,{configurationName:a})});case t.OidcClient.eventNames.loginAsync_error:case t.OidcClient.eventNames.loginCallbackAsync_error:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(K,{configurationName:a})});case t.OidcClient.eventNames.refreshTokensAsync_error:case t.OidcClient.eventNames.syncTokensAsync_error:case t.OidcClient.eventNames.logout_from_another_tab:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(V,{configurationName:a})});default:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(j,{redirect_uri:J.configuration.redirect_uri,silent_redirect_uri:J.configuration.silent_redirect_uri,silent_login_uri:J.configuration.silent_login_uri,callbackSuccessComponent:o,callbackErrorComponent:d,authenticatingComponent:s,configurationName:a,withCustomHistory:v,navigateAfterCallback:y,location:C??new t.OidcLocation,children:(0,r.jsx)(N,{loadingComponent:U,configurationName:a,children:e})})})}},R=({children:e,callbackPath:i=null,extras:a=null,configurationName:o=`default`})=>{let s=t.OidcClient.getOrThrow,c=s(o);return(0,n.useEffect)(()=>{!c.tokens&&!c.isLoggingOut&&c.loginAsync(i,a)},[o,i,a]),c.tokens?(0,r.jsx)(r.Fragment,{children:e}):null},z=(e,t=null,n=null,i=`default`)=>a=>(0,r.jsx)(R,{callbackPath:t,extras:n,configurationName:i,children:(0,r.jsx)(e,{...a})}),B=new Set,V=e=>{B.has(e)||(B.add(e),console.warn(`@axa-fr/react-oidc: no OIDC configuration found for "${e}". Make sure to wrap your component tree with <OidcProvider configurationName="${e}">. Hooks are returning safe default values (issue #1679).`))},H=`default`,U=(e,t)=>{let n=!1,r=e(t);return r&&(n=r.tokens!=null),n},W=(e=H)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>U(r,e));return(0,n.useEffect)(()=>{let n=!0,i=r(e);if(!i){V(e);return}let o=i.subscribeEvents((i,o)=>{(i===t.OidcClient.eventNames.logout_from_another_tab||i===t.OidcClient.eventNames.logout_from_same_tab||i===t.OidcClient.eventNames.token_acquired)&&n&&a(U(r,e))});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),{login:(t=void 0,n=void 0,i=!1,a=void 0)=>{let o=r(e);return o?o.loginAsync(t,n,!1,a,i):(V(e),Promise.resolve())},logout:(t=void 0,n=void 0)=>{let i=r(e);return i?i.logoutAsync(t,n):(V(e),Promise.resolve())},renewTokens:async(t=void 0)=>{let n=r(e);if(!n)return V(e),{accessToken:null,accessTokenPayload:null,idToken:null,idTokenPayload:null};let i=await n.renewTokensAsync(t);return{accessToken:i.accessToken,accessTokenPayload:i.accessTokenPayload,idToken:i.idToken,idTokenPayload:i.idTokenPayload}},isAuthenticated:i}},G={accessToken:null,accessTokenPayload:null},K=e=>{let n=t.OidcClient.get,r=n(e);if(!r)return G;if(r.tokens){let e=r.tokens;return{accessToken:e.accessToken,accessTokenPayload:e.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:r.configuration.demonstrating_proof_of_possession?(t,n)=>r.generateDemonstrationOfProofOfPossessionAsync(e.accessToken,t,n):null}}return G};function q(e,t){return e.configuration.demonstrating_proof_of_possession?(n,r,i={})=>e.generateDemonstrationOfProofOfPossessionAsync(t.accessToken,n,r,i):null}var J=(e=H)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>K(e));return(0,n.useEffect)(()=>{let n=!0,i=r(e);if(!i){V(e);return}let o=i.subscribeEvents((e,r)=>{if((e===t.OidcClient.eventNames.token_renewed||e===t.OidcClient.eventNames.token_acquired||e===t.OidcClient.eventNames.logout_from_another_tab||e===t.OidcClient.eventNames.logout_from_same_tab||e===t.OidcClient.eventNames.refreshTokensAsync_error||e===t.OidcClient.eventNames.syncTokensAsync_error)&&n){let e=i.tokens;a(e==null?G:{accessToken:e.accessToken,accessTokenPayload:e.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:q(i,e)})}});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),i},Y={idToken:null,idTokenPayload:null},X=e=>{let n=t.OidcClient.get,r=n(e);if(!r)return Y;if(r.tokens){let e=r.tokens;return{idToken:e.idToken,idTokenPayload:e.idTokenPayload}}return Y},Z=(e=H)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>X(e));return(0,n.useEffect)(()=>{let n=!0,i=r(e);if(!i){V(e);return}let o=i.subscribeEvents((e,r)=>{if((e===t.OidcClient.eventNames.token_renewed||e===t.OidcClient.eventNames.token_acquired||e===t.OidcClient.eventNames.logout_from_another_tab||e===t.OidcClient.eventNames.logout_from_same_tab||e===t.OidcClient.eventNames.refreshTokensAsync_error||e===t.OidcClient.eventNames.syncTokensAsync_error)&&n){let e=i.tokens;a(e==null?Y:{idToken:e.idToken,idTokenPayload:e.idTokenPayload})}});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),i},Q=function(e){return e.Unauthenticated=`Unauthenticated`,e.Loading=`Loading user`,e.Loaded=`User loaded`,e.LoadingError=`Error loading user`,e}({});Object.defineProperty(e,`OidcClient`,{enumerable:!0,get:function(){return t.OidcClient}}),Object.defineProperty(e,`OidcLocation`,{enumerable:!0,get:function(){return t.OidcLocation}}),e.OidcProvider=L,e.OidcSecure=R,e.OidcUserStatus=Q,Object.defineProperty(e,`TokenAutomaticRenewMode`,{enumerable:!0,get:function(){return t.TokenAutomaticRenewMode}}),Object.defineProperty(e,`TokenRenewMode`,{enumerable:!0,get:function(){return t.TokenRenewMode}}),e.useOidc=W,e.useOidcAccessToken=J,e.useOidcFetch=m,e.useOidcIdToken=Z,e.useOidcUser=(e=`default`,r=!1)=>{let i=t.OidcClient.get(e),a=i?i.userInfo():null,[o,s]=(0,n.useState)({user:a,status:a?`User loaded`:`Unauthenticated`}),[c,l]=(0,n.useState)(+!!a),u=(0,n.useRef)(+!!a);return(0,n.useEffect)(()=>{let n=t.OidcClient.get(e),i=!0;if(!n){V(e);return}if(n.tokens){let e=c===u.current;if(e&&n.userInfo())return;u.current=c,queueMicrotask(()=>{i&&s({...o,status:`Loading user`})}),n.userInfoAsync(!e,r).then(e=>{i&&s({user:e,status:`User loaded`})}).catch(()=>s({...o,status:`Error loading user`}))}else queueMicrotask(()=>{i&&s({user:null,status:`Unauthenticated`})});let a=n.subscribeEvents(e=>{(e===t.OidcClient.eventNames.logout_from_another_tab||e===t.OidcClient.eventNames.logout_from_same_tab)&&i&&s({user:null,status:`Unauthenticated`})});return()=>{i=!1,n.removeEventSubscription(a)}},[c,e,r]),{oidcUser:o.user,oidcUserLoadingState:o.status,reloadOidcUser:()=>{l(c+1)}}},e.withOidcFetch=p,e.withOidcSecure=z});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@axa-fr/oidc-client`),require(`react`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@axa-fr/oidc-client`,`react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e[`react-oidc`]={},e._axa_fr_oidc_client,e.React,e.react_jsx_runtime))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var i=Object.create,a=Object.defineProperty,o=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,c=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty,u=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=s(t),c=0,u=i.length,d;c<u;c++)d=i[c],!l.call(e,d)&&d!==n&&a(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=o(t,d))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:i(c(e)),u(t||!e||!e.__esModule?a(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var d=`default`,f=(e,t,n=!1)=>async(...r)=>await t().fetchWithTokens(e,n)(...r),p=(e=null,t=d,n=!1)=>i=>a=>{let{fetch:o}=m(e||a.fetch,t,n);return(0,r.jsx)(i,{...a,fetch:o})},m=(e=null,r=d,i=!1)=>{let a=e||window.fetch,o=t.OidcClient.getOrThrow;return{fetch:(0,n.useCallback)((e,t)=>f(a,()=>o(r),i)(e,t),[a,r,i])}},h=()=>(0,r.jsx)(`div`,{className:`oidc-authenticating`,children:(0,r.jsxs)(`div`,{className:`oidc-authenticating__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-authenticating__title`,children:`Error authentication`}),(0,r.jsx)(`p`,{className:`oidc-authenticating__content`,children:`An error occurred during authentication.`})]})}),g=()=>(0,r.jsx)(`div`,{className:`oidc-authenticating`,children:(0,r.jsxs)(`div`,{className:`oidc-authenticating__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-authenticating__title`,children:`Authentication in progress`}),(0,r.jsx)(`p`,{className:`oidc-authenticating__content`,children:`You will be redirected to the login page.`})]})}),_=()=>Math.random().toString(36).slice(2,8),v=(e,t)=>(n,r)=>{if(typeof e.CustomEvent==`function`)return new e.CustomEvent(n,r);let i=r||{bubbles:!1,cancelable:!1,detail:void 0},a=t.createEvent(`CustomEvent`);return a.initCustomEvent(n,i.bubbles,i.cancelable,i.detail),a.prototype=e.Event.prototype,a},y=(e,t,n)=>({replaceState:(r,i)=>{let a=n(),o=i||e.history.state;e.history.replaceState({key:a,state:o},null,r),e.dispatchEvent(t(`popstate`))}}),b=()=>y(window,v(window,document),_),x=()=>(0,r.jsx)(`div`,{className:`oidc-callback`,children:(0,r.jsxs)(`div`,{className:`oidc-callback__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-callback__title`,children:`Authentication complete`}),(0,r.jsx)(`p`,{className:`oidc-callback__content`,children:`You will be redirected to your application.`})]})}),S=200,C=(e,t=window)=>t.location.pathname===e||e===`/`,w=({callBackError:e,callBackSuccess:i,configurationName:a,withCustomHistory:o,navigateAfterCallback:s})=>{let[c,l]=(0,n.useState)(!1);(0,n.useEffect)(()=>{let e=!0;return(async()=>{let n=t.OidcClient.getOrThrow;try{let r=n(a),{callbackPath:i}=await r.loginCallbackAsync(),c=i||`/`;if(s)try{await s(c),r.publishEvent(t.OidcClient.eventNames.loginCallbackAsync_navigated,{configurationName:a,callbackPath:c})}catch(n){r.publishEvent(t.OidcClient.eventNames.loginCallbackAsync_navigation_error,{configurationName:a,callbackPath:c,error:n}),e&&(console.warn(n),l(!0))}else (o?o():b()).replaceState(c),await new Promise(e=>{setTimeout(()=>{e()},S)}),e&&(C(c)?r.publishEvent(t.OidcClient.eventNames.loginCallbackAsync_navigated,{configurationName:a,callbackPath:c}):(r.publishEvent(t.OidcClient.eventNames.loginCallbackAsync_navigation_error,{configurationName:a,callbackPath:c,error:Error(`Navigation did not commit: expected "${c}" but found "${window.location.pathname}"`)}),l(!0)))}catch(t){e&&(console.warn(t),l(!0))}})(),()=>{e=!1}},[]);let u=e||h,d=i||x;return c?(0,r.jsx)(u,{configurationName:a}):(0,r.jsx)(d,{configurationName:a})},T=()=>(0,r.jsx)(`span`,{className:`oidc-loading`,children:`Loading`}),E=()=>(0,r.jsx)(`div`,{className:`oidc-loading-timeout`,children:(0,r.jsxs)(`div`,{className:`oidc-loading-timeout__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-loading-timeout__title`,children:`Loading timeout`}),(0,r.jsx)(`p`,{className:`oidc-loading-timeout__content`,children:`Authentication is taking longer than expected. Please try refreshing the page.`})]})}),D=()=>(0,r.jsx)(`div`,{className:`oidc-serviceworker`,children:(0,r.jsxs)(`div`,{className:`oidc-serviceworker__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-serviceworker__title`,children:`Unable to authenticate on this browser`}),(0,r.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.`})]})}),O=()=>(0,r.jsx)(`div`,{className:`oidc-session-lost`,children:(0,r.jsxs)(`div`,{className:`oidc-session-lost__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-session-lost__title`,children:`Session timed out`}),(0,r.jsx)(`p`,{className:`oidc-session-lost__content`,children:`Your session has expired. Please re-authenticate.`})]})}),k=({configurationName:e})=>((0,n.useEffect)(()=>{(async()=>{t.OidcClient.getOrThrow(e).silentLoginCallbackAsync()})().catch(e=>{console.error(`Error during silent login callback:`,e)})},[e]),null),A=({configurationName:e})=>{let i=(0,t.getParseQueryStringFromLocation)(window.location.href),a=t.OidcClient.getOrThrow,o=a(e),s=null;for(let[e,t]of Object.entries(i))e===`state`||e===`scope`||(s===null&&(s={}),s[e]=t);return(0,n.useEffect)(()=>{o.tokens||o.loginAsync(null,s,!0,i.scope)},[]),(0,r.jsx)(r.Fragment,{})},j=n.default.memo(({callbackErrorComponent:e,callbackSuccessComponent:i,redirect_uri:a,silent_redirect_uri:o,silent_login_uri:s,children:c,configurationName:l,withCustomHistory:u=null,navigateAfterCallback:d=null})=>{let[f,p]=(0,n.useState)(window?(0,t.getPath)(window.location.href):``);(0,n.useEffect)(()=>{let e=()=>p((0,t.getPath)(window.location.href));return e(),window.addEventListener(`popstate`,e,!1),()=>window.removeEventListener(`popstate`,e,!1)},[]);let m=(0,t.getPath)(a);if(o&&f===(0,t.getPath)(o))return(0,r.jsx)(k,{configurationName:l});if(s&&f===(0,t.getPath)(s))return(0,r.jsx)(A,{configurationName:l});switch(f){case m:return(0,r.jsx)(w,{callBackError:e,callBackSuccess:i,configurationName:l,withCustomHistory:u,navigateAfterCallback:d});default:return(0,r.jsx)(r.Fragment,{children:c})}}),M={name:``,data:null},N=({loadingComponent:e,children:i,configurationName:a})=>{let[o,s]=(0,n.useState)(!0),c=t.OidcClient.get,l=c(a);return(0,n.useEffect)(()=>{let e=!0;return l&&l.tryKeepExistingSessionAsync().then(()=>{e&&s(!1)}),()=>{e=!1}},[a]),(0,r.jsx)(r.Fragment,{children:o?(0,r.jsx)(e,{configurationName:a}):(0,r.jsx)(r.Fragment,{children:i})})},P=({isLoading:e,loadingComponent:t,children:n,configurationName:i})=>{let a=t;return e?(0,r.jsx)(a,{configurationName:i,children:n}):(0,r.jsx)(r.Fragment,{children:n})},F=3e4,I=(e,n)=>e===t.OidcClient.eventNames.token_acquired||e===t.OidcClient.eventNames.token_renewed||e===t.OidcClient.eventNames.loginCallbackAsync_end?!0:e===t.OidcClient.eventNames.tryKeepExistingSessionAsync_end?n?.success===!0:!1,L=({children:e,configuration:i,configurationName:a=`default`,callbackSuccessComponent:o=x,authenticatingComponent:s=g,loadingComponent:c=T,loadingTimeoutComponent:l=E,serviceWorkerNotSupportedComponent:u=D,authenticatingErrorComponent:d=h,sessionLostComponent:f=O,onSessionLost:p=null,onLogoutFromAnotherTab:m=null,onLogoutFromSameTab:_=null,withCustomHistory:v=null,navigateAfterCallback:y=null,onEvent:b=null,getFetch:S=null,location:C=null})=>{if(i&&i.redirect_uri&&i.silent_redirect_uri&&i.redirect_uri===i.silent_redirect_uri)throw Error(`redirect_uri and silent_redirect_uri must be different`);let w=(e=`default`)=>t.OidcClient.getOrCreate(S??t.getFetchDefault,C??new t.OidcLocation)(i,e),[k,A]=(0,n.useState)(M),[L,R]=(0,n.useState)(!1),[z,B]=(0,n.useState)(a);(0,n.useEffect)(()=>{let e=w(a).subscribeEvents((e,t)=>{b&&b(a,e,t)});return()=>{w(a).removeEventSubscription(e)}},[a,b]),(0,n.useEffect)(()=>{let e=w(a).subscribeEvents((e,n)=>{if(I(e,n)&&R(!0),e===t.OidcClient.eventNames.refreshTokensAsync_error||e===t.OidcClient.eventNames.syncTokensAsync_error){if(p!=null){p();return}A({name:e,data:n})}else if(e===t.OidcClient.eventNames.logout_from_another_tab){if(m!=null){m();return}A({name:e,data:n})}else e===t.OidcClient.eventNames.logout_from_same_tab?_?.():(e===t.OidcClient.eventNames.loadingTimeout_error||e===t.OidcClient.eventNames.loginAsync_begin||e===t.OidcClient.eventNames.loginCallbackAsync_end||e===t.OidcClient.eventNames.loginAsync_error||e===t.OidcClient.eventNames.loginCallbackAsync_error||e===t.OidcClient.eventNames.service_worker_not_supported_by_browser&&i.service_worker_only===!0)&&A({name:e,data:n})});return queueMicrotask(()=>{B(a)}),()=>{w(a).removeEventSubscription(e),A(M),R(!1)}},[i,a]),(0,n.useEffect)(()=>{let e=i?.loading_timeout_ms??F;if(e<=0||L||w(a)?.tokens!=null||!(k.name===``||k.name===t.OidcClient.eventNames.loginAsync_begin))return;let n=setTimeout(()=>{w(a).publishEvent(t.OidcClient.eventNames.loadingTimeout_error,{timeoutMs:e})},e);return()=>clearTimeout(n)},[k.name,L,a,i]);let V=f,H=s,U=c,W=l,G=u,K=d,q=z!==a,J=w(a);switch(k.name){case t.OidcClient.eventNames.service_worker_not_supported_by_browser:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(G,{configurationName:a})});case t.OidcClient.eventNames.loginAsync_begin:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(H,{configurationName:a})});case t.OidcClient.eventNames.loadingTimeout_error:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(W,{configurationName:a})});case t.OidcClient.eventNames.loginAsync_error:case t.OidcClient.eventNames.loginCallbackAsync_error:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(K,{configurationName:a})});case t.OidcClient.eventNames.refreshTokensAsync_error:case t.OidcClient.eventNames.syncTokensAsync_error:case t.OidcClient.eventNames.logout_from_another_tab:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(V,{configurationName:a})});default:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(j,{redirect_uri:J.configuration.redirect_uri,silent_redirect_uri:J.configuration.silent_redirect_uri,silent_login_uri:J.configuration.silent_login_uri,callbackSuccessComponent:o,callbackErrorComponent:d,authenticatingComponent:s,configurationName:a,withCustomHistory:v,navigateAfterCallback:y,location:C??new t.OidcLocation,children:(0,r.jsx)(N,{loadingComponent:U,configurationName:a,children:e})})})}},R=({children:e,callbackPath:i=null,extras:a=null,configurationName:o=`default`})=>{let s=t.OidcClient.getOrThrow,c=s(o);return(0,n.useEffect)(()=>{!c.tokens&&!c.isLoggingOut&&c.loginAsync(i,a)},[o,i,a]),c.tokens?(0,r.jsx)(r.Fragment,{children:e}):null},z=(e,t=null,n=null,i=`default`)=>a=>(0,r.jsx)(R,{callbackPath:t,extras:n,configurationName:i,children:(0,r.jsx)(e,{...a})}),B=new Set,V=e=>{B.has(e)||(B.add(e),console.warn(`@axa-fr/react-oidc: no OIDC configuration found for "${e}". Make sure to wrap your component tree with <OidcProvider configurationName="${e}">. Hooks are returning safe default values (issue #1679).`))},H=`default`,U=(e,t)=>{let n=!1,r=e(t);return r&&(n=r.tokens!=null),n},W=(e=H)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>U(r,e));return(0,n.useEffect)(()=>{let n=!0,i=r(e);if(!i){V(e);return}let o=i.subscribeEvents((i,o)=>{(i===t.OidcClient.eventNames.logout_from_another_tab||i===t.OidcClient.eventNames.logout_from_same_tab||i===t.OidcClient.eventNames.token_acquired)&&n&&a(U(r,e))});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),{login:(t=void 0,n=void 0,i=!1,a=void 0)=>{let o=r(e);return o?o.loginAsync(t,n,!1,a,i):(V(e),Promise.resolve())},logout:(t=void 0,n=void 0)=>{let i=r(e);return i?i.logoutAsync(t,n):(V(e),Promise.resolve())},renewTokens:async(t=void 0)=>{let n=r(e);if(!n)return V(e),{accessToken:null,accessTokenPayload:null,idToken:null,idTokenPayload:null};let i=await n.renewTokensAsync(t);return{accessToken:i.accessToken,accessTokenPayload:i.accessTokenPayload,idToken:i.idToken,idTokenPayload:i.idTokenPayload}},isAuthenticated:i}},G={accessToken:null,accessTokenPayload:null},K=e=>{let n=t.OidcClient.get,r=n(e);if(!r)return G;if(r.tokens){let e=r.tokens;return{accessToken:e.accessToken,accessTokenPayload:e.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:r.configuration.demonstrating_proof_of_possession?(t,n)=>r.generateDemonstrationOfProofOfPossessionAsync(e.accessToken,t,n):null}}return G};function q(e,t){return e.configuration.demonstrating_proof_of_possession?(n,r,i={})=>e.generateDemonstrationOfProofOfPossessionAsync(t.accessToken,n,r,i):null}var J=(e=H)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>K(e));return(0,n.useEffect)(()=>{let n=!0,i=r(e);if(!i){V(e);return}let o=i.subscribeEvents((e,r)=>{if((e===t.OidcClient.eventNames.token_renewed||e===t.OidcClient.eventNames.token_acquired||e===t.OidcClient.eventNames.logout_from_another_tab||e===t.OidcClient.eventNames.logout_from_same_tab||e===t.OidcClient.eventNames.refreshTokensAsync_error||e===t.OidcClient.eventNames.syncTokensAsync_error)&&n){let e=i.tokens;a(e==null?G:{accessToken:e.accessToken,accessTokenPayload:e.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:q(i,e)})}});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),i},Y={idToken:null,idTokenPayload:null},X=e=>{let n=t.OidcClient.get,r=n(e);if(!r)return Y;if(r.tokens){let e=r.tokens;return{idToken:e.idToken,idTokenPayload:e.idTokenPayload}}return Y},Z=(e=H)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>X(e));return(0,n.useEffect)(()=>{let n=!0,i=r(e);if(!i){V(e);return}let o=i.subscribeEvents((e,r)=>{if((e===t.OidcClient.eventNames.token_renewed||e===t.OidcClient.eventNames.token_acquired||e===t.OidcClient.eventNames.logout_from_another_tab||e===t.OidcClient.eventNames.logout_from_same_tab||e===t.OidcClient.eventNames.refreshTokensAsync_error||e===t.OidcClient.eventNames.syncTokensAsync_error)&&n){let e=i.tokens;a(e==null?Y:{idToken:e.idToken,idTokenPayload:e.idTokenPayload})}});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),i},Q=function(e){return e.Unauthenticated=`Unauthenticated`,e.Loading=`Loading user`,e.Loaded=`User loaded`,e.LoadingError=`Error loading user`,e}({});Object.defineProperty(e,`OidcClient`,{enumerable:!0,get:function(){return t.OidcClient}}),Object.defineProperty(e,`OidcLocation`,{enumerable:!0,get:function(){return t.OidcLocation}}),e.OidcProvider=L,e.OidcSecure=R,Object.defineProperty(e,`OidcStateError`,{enumerable:!0,get:function(){return t.OidcStateError}}),Object.defineProperty(e,`OidcStateErrorCode`,{enumerable:!0,get:function(){return t.OidcStateErrorCode}}),e.OidcUserStatus=Q,Object.defineProperty(e,`TokenAutomaticRenewMode`,{enumerable:!0,get:function(){return t.TokenAutomaticRenewMode}}),Object.defineProperty(e,`TokenRenewMode`,{enumerable:!0,get:function(){return t.TokenRenewMode}}),Object.defineProperty(e,`isOidcStateError`,{enumerable:!0,get:function(){return t.isOidcStateError}}),e.useOidc=W,e.useOidcAccessToken=J,e.useOidcFetch=m,e.useOidcIdToken=Z,e.useOidcUser=(e=`default`,r=!1)=>{let i=t.OidcClient.get(e),a=i?i.userInfo():null,[o,s]=(0,n.useState)({user:a,status:a?`User loaded`:`Unauthenticated`}),[c,l]=(0,n.useState)(+!!a),u=(0,n.useRef)(+!!a);return(0,n.useEffect)(()=>{let n=t.OidcClient.get(e),i=!0;if(!n){V(e);return}if(n.tokens){let e=c===u.current;if(e&&n.userInfo())return;u.current=c,queueMicrotask(()=>{i&&s({...o,status:`Loading user`})}),n.userInfoAsync(!e,r).then(e=>{i&&s({user:e,status:`User loaded`})}).catch(()=>s({...o,status:`Error loading user`}))}else queueMicrotask(()=>{i&&s({user:null,status:`Unauthenticated`})});let a=n.subscribeEvents(e=>{(e===t.OidcClient.eventNames.logout_from_another_tab||e===t.OidcClient.eventNames.logout_from_same_tab)&&i&&s({user:null,status:`Unauthenticated`})});return()=>{i=!1,n.removeEventSubscription(a)}},[c,e,r]),{oidcUser:o.user,oidcUserLoadingState:o.status,reloadOidcUser:()=>{l(c+1)}}},e.withOidcFetch=p,e.withOidcSecure=z});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axa-fr/react-oidc",
|
|
3
|
-
"version": "7.27.
|
|
3
|
+
"version": "7.27.18",
|
|
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": "7.27.
|
|
44
|
-
"@axa-fr/oidc-client-service-worker": "7.27.
|
|
43
|
+
"@axa-fr/oidc-client": "7.27.18",
|
|
44
|
+
"@axa-fr/oidc-client-service-worker": "7.27.18"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"react": "^17.0.0 || ^18.0.0 || ^19.0.0"
|
package/src/index.ts
CHANGED
|
@@ -13,8 +13,11 @@ export type {
|
|
|
13
13
|
} from '@axa-fr/oidc-client';
|
|
14
14
|
export type { OidcUserInfo } from '@axa-fr/oidc-client';
|
|
15
15
|
export {
|
|
16
|
+
isOidcStateError,
|
|
16
17
|
OidcClient,
|
|
17
18
|
OidcLocation,
|
|
19
|
+
OidcStateError,
|
|
20
|
+
OidcStateErrorCode,
|
|
18
21
|
TokenAutomaticRenewMode,
|
|
19
22
|
TokenRenewMode,
|
|
20
23
|
} from '@axa-fr/oidc-client';
|