@axa-fr/react-oidc 7.27.2 → 7.27.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/OidcProvider.d.ts.map +1 -1
- package/dist/index.js +404 -426
- package/dist/index.umd.cjs +1 -1
- package/package.json +16 -16
- package/src/OidcProvider.tsx +0 -4
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @axa-fr/react-oidc
|
|
2
2
|
|
|
3
3
|
[](https://github.com/AxaFrance/react-oidc/actions/workflows/npm-publish.yml)
|
|
4
|
-
[](https://www.npmjs.com/package/@axa-fr/react-oidc)
|
|
5
5
|
|
|
6
6
|
**@axa-fr/oidc-client** the lightest and securest library to manage authentication with OpenID Connect (OIDC) and OAuth2 protocol. It is compatible with all OIDC providers.
|
|
7
7
|
**@axa-fr/oidc-client** is a pure javascript library. It works with any JavaScript framework or library.
|
|
@@ -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,CA+KjE,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,429 +1,407 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
},
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
},
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
const s = e.tokens;
|
|
304
|
-
return {
|
|
305
|
-
accessToken: s.accessToken,
|
|
306
|
-
accessTokenPayload: s.accessTokenPayload,
|
|
307
|
-
generateDemonstrationOfProofOfPossessionAsync: e.configuration.demonstrating_proof_of_possession ? (o, r) => e.generateDemonstrationOfProofOfPossessionAsync(s.accessToken, o, r) : null
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
return Y;
|
|
1
|
+
import { OidcClient as e, OidcClient as t, OidcLocation as n, OidcLocation as r, TokenAutomaticRenewMode as i, TokenRenewMode as a, getFetchDefault as o, getParseQueryStringFromLocation as s, getPath as c } from "@axa-fr/oidc-client";
|
|
2
|
+
import l, { useCallback as u, useEffect as d, useRef as f, useState as p } from "react";
|
|
3
|
+
import { Fragment as m, jsx as h, jsxs as g } from "react/jsx-runtime";
|
|
4
|
+
//#region src/FetchToken.tsx
|
|
5
|
+
var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithTokens(e, n)(...r), y = (e = null, t = _, n = !1) => (r) => (i) => {
|
|
6
|
+
let { fetch: a } = b(e || i.fetch, t, n);
|
|
7
|
+
return /* @__PURE__ */ h(r, {
|
|
8
|
+
...i,
|
|
9
|
+
fetch: a
|
|
10
|
+
});
|
|
11
|
+
}, b = (e = null, n = _, r = !1) => {
|
|
12
|
+
let i = e || window.fetch, a = t.get;
|
|
13
|
+
return { fetch: u((e, t) => v(i, () => a(n), r)(e, t), [
|
|
14
|
+
i,
|
|
15
|
+
n,
|
|
16
|
+
r
|
|
17
|
+
]) };
|
|
18
|
+
}, x = () => /* @__PURE__ */ h("div", {
|
|
19
|
+
className: "oidc-authenticating",
|
|
20
|
+
children: /* @__PURE__ */ g("div", {
|
|
21
|
+
className: "oidc-authenticating__container",
|
|
22
|
+
children: [/* @__PURE__ */ h("h1", {
|
|
23
|
+
className: "oidc-authenticating__title",
|
|
24
|
+
children: "Error authentication"
|
|
25
|
+
}), /* @__PURE__ */ h("p", {
|
|
26
|
+
className: "oidc-authenticating__content",
|
|
27
|
+
children: "An error occurred during authentication."
|
|
28
|
+
})]
|
|
29
|
+
})
|
|
30
|
+
}), S = () => /* @__PURE__ */ h("div", {
|
|
31
|
+
className: "oidc-authenticating",
|
|
32
|
+
children: /* @__PURE__ */ g("div", {
|
|
33
|
+
className: "oidc-authenticating__container",
|
|
34
|
+
children: [/* @__PURE__ */ h("h1", {
|
|
35
|
+
className: "oidc-authenticating__title",
|
|
36
|
+
children: "Authentication in progress"
|
|
37
|
+
}), /* @__PURE__ */ h("p", {
|
|
38
|
+
className: "oidc-authenticating__content",
|
|
39
|
+
children: "You will be redirected to the login page."
|
|
40
|
+
})]
|
|
41
|
+
})
|
|
42
|
+
}), C = () => Math.random().toString(36).slice(2, 8), w = (e, t) => (n, r) => {
|
|
43
|
+
if (typeof e.CustomEvent == "function") return new e.CustomEvent(n, r);
|
|
44
|
+
let i = r || {
|
|
45
|
+
bubbles: !1,
|
|
46
|
+
cancelable: !1,
|
|
47
|
+
detail: void 0
|
|
48
|
+
}, a = t.createEvent("CustomEvent");
|
|
49
|
+
return a.initCustomEvent(n, i.bubbles, i.cancelable, i.detail), a.prototype = e.Event.prototype, a;
|
|
50
|
+
}, T = (e, t, n) => ({ replaceState: (r, i) => {
|
|
51
|
+
let a = n(), o = i || e.history.state;
|
|
52
|
+
e.history.replaceState({
|
|
53
|
+
key: a,
|
|
54
|
+
state: o
|
|
55
|
+
}, null, r), e.dispatchEvent(t("popstate"));
|
|
56
|
+
} }), E = () => T(window, w(window, document), C), D = () => /* @__PURE__ */ h("div", {
|
|
57
|
+
className: "oidc-callback",
|
|
58
|
+
children: /* @__PURE__ */ g("div", {
|
|
59
|
+
className: "oidc-callback__container",
|
|
60
|
+
children: [/* @__PURE__ */ h("h1", {
|
|
61
|
+
className: "oidc-callback__title",
|
|
62
|
+
children: "Authentication complete"
|
|
63
|
+
}), /* @__PURE__ */ h("p", {
|
|
64
|
+
className: "oidc-callback__content",
|
|
65
|
+
children: "You will be redirected to your application."
|
|
66
|
+
})]
|
|
67
|
+
})
|
|
68
|
+
}), O = ({ callBackError: e, callBackSuccess: n, configurationName: r, withCustomHistory: i }) => {
|
|
69
|
+
let [a, o] = p(!1);
|
|
70
|
+
return d(() => {
|
|
71
|
+
let e = !0;
|
|
72
|
+
return (async () => {
|
|
73
|
+
let n = t.get;
|
|
74
|
+
try {
|
|
75
|
+
let { callbackPath: e } = await n(r).loginCallbackAsync();
|
|
76
|
+
(i ? i() : E()).replaceState(e || "/");
|
|
77
|
+
} catch (t) {
|
|
78
|
+
e && (console.warn(t), o(!0));
|
|
79
|
+
}
|
|
80
|
+
})(), () => {
|
|
81
|
+
e = !1;
|
|
82
|
+
};
|
|
83
|
+
}, []), h(a ? e || x : n || D, { configurationName: r });
|
|
84
|
+
}, k = () => /* @__PURE__ */ h("span", {
|
|
85
|
+
className: "oidc-loading",
|
|
86
|
+
children: "Loading"
|
|
87
|
+
}), A = () => /* @__PURE__ */ h("div", {
|
|
88
|
+
className: "oidc-serviceworker",
|
|
89
|
+
children: /* @__PURE__ */ g("div", {
|
|
90
|
+
className: "oidc-serviceworker__container",
|
|
91
|
+
children: [/* @__PURE__ */ h("h1", {
|
|
92
|
+
className: "oidc-serviceworker__title",
|
|
93
|
+
children: "Unable to authenticate on this browser"
|
|
94
|
+
}), /* @__PURE__ */ h("p", {
|
|
95
|
+
className: "oidc-serviceworker__content",
|
|
96
|
+
children: "Your browser is not secure enough to make authentication work. Try updating your browser or use a newer browser."
|
|
97
|
+
})]
|
|
98
|
+
})
|
|
99
|
+
}), j = () => /* @__PURE__ */ h("div", {
|
|
100
|
+
className: "oidc-session-lost",
|
|
101
|
+
children: /* @__PURE__ */ g("div", {
|
|
102
|
+
className: "oidc-session-lost__container",
|
|
103
|
+
children: [/* @__PURE__ */ h("h1", {
|
|
104
|
+
className: "oidc-session-lost__title",
|
|
105
|
+
children: "Session timed out"
|
|
106
|
+
}), /* @__PURE__ */ h("p", {
|
|
107
|
+
className: "oidc-session-lost__content",
|
|
108
|
+
children: "Your session has expired. Please re-authenticate."
|
|
109
|
+
})]
|
|
110
|
+
})
|
|
111
|
+
}), M = ({ configurationName: e }) => (d(() => {
|
|
112
|
+
(async () => {
|
|
113
|
+
t.get(e).silentLoginCallbackAsync();
|
|
114
|
+
})().catch((e) => {
|
|
115
|
+
console.error("Error during silent login callback:", e);
|
|
116
|
+
});
|
|
117
|
+
}, [e]), null), N = ({ configurationName: e }) => {
|
|
118
|
+
let n = s(window.location.href), r = t.get, i = r(e), a = null;
|
|
119
|
+
for (let [e, t] of Object.entries(n)) e === "state" || e === "scope" || (a === null && (a = {}), a[e] = t);
|
|
120
|
+
return d(() => {
|
|
121
|
+
i.tokens || i.loginAsync(null, a, !0, n.scope);
|
|
122
|
+
}, []), /* @__PURE__ */ h(m, {});
|
|
123
|
+
}, P = l.memo(({ callbackErrorComponent: e, callbackSuccessComponent: t, redirect_uri: n, silent_redirect_uri: r, silent_login_uri: i, children: a, configurationName: o, withCustomHistory: s = null }) => {
|
|
124
|
+
let [l, u] = p(window ? c(window.location.href) : "");
|
|
125
|
+
d(() => {
|
|
126
|
+
let e = () => u(c(window.location.href));
|
|
127
|
+
return e(), window.addEventListener("popstate", e, !1), () => window.removeEventListener("popstate", e, !1);
|
|
128
|
+
}, []);
|
|
129
|
+
let f = c(n);
|
|
130
|
+
if (r && l === c(r)) return /* @__PURE__ */ h(M, { configurationName: o });
|
|
131
|
+
if (i && l === c(i)) return /* @__PURE__ */ h(N, { configurationName: o });
|
|
132
|
+
switch (l) {
|
|
133
|
+
case f: return /* @__PURE__ */ h(O, {
|
|
134
|
+
callBackError: e,
|
|
135
|
+
callBackSuccess: t,
|
|
136
|
+
configurationName: o,
|
|
137
|
+
withCustomHistory: s
|
|
138
|
+
});
|
|
139
|
+
default: return /* @__PURE__ */ h(m, { children: a });
|
|
140
|
+
}
|
|
141
|
+
}), F = {
|
|
142
|
+
name: "",
|
|
143
|
+
data: null
|
|
144
|
+
}, I = ({ loadingComponent: e, children: n, configurationName: r }) => {
|
|
145
|
+
let [i, a] = p(!0), o = t.get, s = o(r);
|
|
146
|
+
return d(() => {
|
|
147
|
+
let e = !0;
|
|
148
|
+
return s && s.tryKeepExistingSessionAsync().then(() => {
|
|
149
|
+
e && a(!1);
|
|
150
|
+
}), () => {
|
|
151
|
+
e = !1;
|
|
152
|
+
};
|
|
153
|
+
}, [r]), /* @__PURE__ */ h(m, { children: i ? /* @__PURE__ */ h(e, { configurationName: r }) : /* @__PURE__ */ h(m, { children: n }) });
|
|
154
|
+
}, L = ({ isLoading: e, loadingComponent: t, children: n, configurationName: r }) => e ? /* @__PURE__ */ h(t, {
|
|
155
|
+
configurationName: r,
|
|
156
|
+
children: n
|
|
157
|
+
}) : /* @__PURE__ */ h(m, { children: n }), R = ({ children: e, configuration: n, configurationName: i = "default", callbackSuccessComponent: a = D, authenticatingComponent: s = S, loadingComponent: c = k, serviceWorkerNotSupportedComponent: l = A, authenticatingErrorComponent: u = x, sessionLostComponent: f = j, onSessionLost: m = null, onLogoutFromAnotherTab: g = null, onLogoutFromSameTab: _ = null, withCustomHistory: v = null, onEvent: y = null, getFetch: b = null, location: C = null }) => {
|
|
158
|
+
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");
|
|
159
|
+
let w = (e = "default") => t.getOrCreate(b ?? o, C ?? new r())(n, e), [T, E] = p(F), [O, M] = p(i);
|
|
160
|
+
d(() => {
|
|
161
|
+
let e = w(i).subscribeEvents((e, t) => {
|
|
162
|
+
y && y(i, e, t);
|
|
163
|
+
});
|
|
164
|
+
return () => {
|
|
165
|
+
w(i).removeEventSubscription(e);
|
|
166
|
+
};
|
|
167
|
+
}, [i, y]), d(() => {
|
|
168
|
+
let e = w(i).subscribeEvents((e, r) => {
|
|
169
|
+
if (e === t.eventNames.refreshTokensAsync_error || e === t.eventNames.syncTokensAsync_error) {
|
|
170
|
+
if (m != null) {
|
|
171
|
+
m();
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
E({
|
|
175
|
+
name: e,
|
|
176
|
+
data: r
|
|
177
|
+
});
|
|
178
|
+
} else if (e === t.eventNames.logout_from_another_tab) {
|
|
179
|
+
if (g != null) {
|
|
180
|
+
g();
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
E({
|
|
184
|
+
name: e,
|
|
185
|
+
data: r
|
|
186
|
+
});
|
|
187
|
+
} else e === t.eventNames.logout_from_same_tab ? _?.() : (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) && E({
|
|
188
|
+
name: e,
|
|
189
|
+
data: r
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
return queueMicrotask(() => {
|
|
193
|
+
M(i);
|
|
194
|
+
}), () => {
|
|
195
|
+
w(i).removeEventSubscription(e), E(F);
|
|
196
|
+
};
|
|
197
|
+
}, [n, i]);
|
|
198
|
+
let N = f, R = s, z = c, B = l, V = u, H = O !== i, U = w(i);
|
|
199
|
+
switch (T.name) {
|
|
200
|
+
case t.eventNames.service_worker_not_supported_by_browser: return /* @__PURE__ */ h(L, {
|
|
201
|
+
loadingComponent: z,
|
|
202
|
+
isLoading: H,
|
|
203
|
+
configurationName: i,
|
|
204
|
+
children: /* @__PURE__ */ h(B, { configurationName: i })
|
|
205
|
+
});
|
|
206
|
+
case t.eventNames.loginAsync_begin: return /* @__PURE__ */ h(L, {
|
|
207
|
+
loadingComponent: z,
|
|
208
|
+
isLoading: H,
|
|
209
|
+
configurationName: i,
|
|
210
|
+
children: /* @__PURE__ */ h(R, { configurationName: i })
|
|
211
|
+
});
|
|
212
|
+
case t.eventNames.loginAsync_error:
|
|
213
|
+
case t.eventNames.loginCallbackAsync_error: return /* @__PURE__ */ h(L, {
|
|
214
|
+
loadingComponent: z,
|
|
215
|
+
isLoading: H,
|
|
216
|
+
configurationName: i,
|
|
217
|
+
children: /* @__PURE__ */ h(V, { configurationName: i })
|
|
218
|
+
});
|
|
219
|
+
case t.eventNames.refreshTokensAsync_error:
|
|
220
|
+
case t.eventNames.syncTokensAsync_error:
|
|
221
|
+
case t.eventNames.logout_from_another_tab: return /* @__PURE__ */ h(L, {
|
|
222
|
+
loadingComponent: z,
|
|
223
|
+
isLoading: H,
|
|
224
|
+
configurationName: i,
|
|
225
|
+
children: /* @__PURE__ */ h(N, { configurationName: i })
|
|
226
|
+
});
|
|
227
|
+
default: return /* @__PURE__ */ h(L, {
|
|
228
|
+
loadingComponent: z,
|
|
229
|
+
isLoading: H,
|
|
230
|
+
configurationName: i,
|
|
231
|
+
children: /* @__PURE__ */ h(P, {
|
|
232
|
+
redirect_uri: U.configuration.redirect_uri,
|
|
233
|
+
silent_redirect_uri: U.configuration.silent_redirect_uri,
|
|
234
|
+
silent_login_uri: U.configuration.silent_login_uri,
|
|
235
|
+
callbackSuccessComponent: a,
|
|
236
|
+
callbackErrorComponent: u,
|
|
237
|
+
authenticatingComponent: s,
|
|
238
|
+
configurationName: i,
|
|
239
|
+
withCustomHistory: v,
|
|
240
|
+
location: C ?? new r(),
|
|
241
|
+
children: /* @__PURE__ */ h(I, {
|
|
242
|
+
loadingComponent: z,
|
|
243
|
+
configurationName: i,
|
|
244
|
+
children: e
|
|
245
|
+
})
|
|
246
|
+
})
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
}, z = ({ children: e, callbackPath: n = null, extras: r = null, configurationName: i = "default" }) => {
|
|
250
|
+
let a = t.get, o = a(i);
|
|
251
|
+
return d(() => {
|
|
252
|
+
o.tokens || o.loginAsync(n, r);
|
|
253
|
+
}, [
|
|
254
|
+
i,
|
|
255
|
+
n,
|
|
256
|
+
r
|
|
257
|
+
]), o.tokens ? /* @__PURE__ */ h(m, { children: e }) : null;
|
|
258
|
+
}, B = (e, t = null, n = null, r = "default") => (i) => /* @__PURE__ */ h(z, {
|
|
259
|
+
callbackPath: t,
|
|
260
|
+
extras: n,
|
|
261
|
+
configurationName: r,
|
|
262
|
+
children: /* @__PURE__ */ h(e, { ...i })
|
|
263
|
+
}), V = "default", H = (e, t) => {
|
|
264
|
+
let n = !1;
|
|
265
|
+
return e(t) && (n = e(t).tokens != null), n;
|
|
266
|
+
}, U = (e = V) => {
|
|
267
|
+
let n = t.get, [r, i] = p(() => H(n, e));
|
|
268
|
+
return d(() => {
|
|
269
|
+
let r = !0, a = n(e), o = a.subscribeEvents((a, o) => {
|
|
270
|
+
(a === t.eventNames.logout_from_another_tab || a === t.eventNames.logout_from_same_tab || a === t.eventNames.token_acquired) && r && i(H(n, e));
|
|
271
|
+
});
|
|
272
|
+
return () => {
|
|
273
|
+
r = !1, a.removeEventSubscription(o);
|
|
274
|
+
};
|
|
275
|
+
}, [e]), {
|
|
276
|
+
login: (t = void 0, r = void 0, i = !1, a = void 0) => n(e).loginAsync(t, r, !1, a, i),
|
|
277
|
+
logout: (t = void 0, r = void 0) => n(e).logoutAsync(t, r),
|
|
278
|
+
renewTokens: async (t = void 0) => {
|
|
279
|
+
let r = await n(e).renewTokensAsync(t);
|
|
280
|
+
return {
|
|
281
|
+
accessToken: r.accessToken,
|
|
282
|
+
accessTokenPayload: r.accessTokenPayload,
|
|
283
|
+
idToken: r.idToken,
|
|
284
|
+
idTokenPayload: r.idTokenPayload
|
|
285
|
+
};
|
|
286
|
+
},
|
|
287
|
+
isAuthenticated: r
|
|
288
|
+
};
|
|
289
|
+
}, W = {
|
|
290
|
+
accessToken: null,
|
|
291
|
+
accessTokenPayload: null
|
|
292
|
+
}, G = (e) => {
|
|
293
|
+
let n = t.get, r = n(e);
|
|
294
|
+
if (r.tokens) {
|
|
295
|
+
let e = r.tokens;
|
|
296
|
+
return {
|
|
297
|
+
accessToken: e.accessToken,
|
|
298
|
+
accessTokenPayload: e.accessTokenPayload,
|
|
299
|
+
generateDemonstrationOfProofOfPossessionAsync: r.configuration.demonstrating_proof_of_possession ? (t, n) => r.generateDemonstrationOfProofOfPossessionAsync(e.accessToken, t, n) : null
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
return W;
|
|
311
303
|
};
|
|
312
|
-
function
|
|
313
|
-
|
|
304
|
+
function K(e, t) {
|
|
305
|
+
return e.configuration.demonstrating_proof_of_possession ? (n, r, i = {}) => e.generateDemonstrationOfProofOfPossessionAsync(t.accessToken, n, r, i) : null;
|
|
314
306
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
},
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
};
|
|
414
|
-
export {
|
|
415
|
-
Me as OidcClient,
|
|
416
|
-
Fe as OidcLocation,
|
|
417
|
-
Oe as OidcProvider,
|
|
418
|
-
fe as OidcSecure,
|
|
419
|
-
ge as OidcUserStatus,
|
|
420
|
-
qe as TokenAutomaticRenewMode,
|
|
421
|
-
De as TokenRenewMode,
|
|
422
|
-
Se as useOidc,
|
|
423
|
-
Pe as useOidcAccessToken,
|
|
424
|
-
te as useOidcFetch,
|
|
425
|
-
Le as useOidcIdToken,
|
|
426
|
-
Ne as useOidcUser,
|
|
427
|
-
Ae as withOidcFetch,
|
|
428
|
-
Ee as withOidcSecure
|
|
307
|
+
var q = (e = V) => {
|
|
308
|
+
let n = t.get, [r, i] = p(() => G(e));
|
|
309
|
+
return d(() => {
|
|
310
|
+
let r = !0, a = n(e), o = a.subscribeEvents((e, n) => {
|
|
311
|
+
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) {
|
|
312
|
+
let e = a.tokens;
|
|
313
|
+
i(e == null ? W : {
|
|
314
|
+
accessToken: e.accessToken,
|
|
315
|
+
accessTokenPayload: e.accessTokenPayload,
|
|
316
|
+
generateDemonstrationOfProofOfPossessionAsync: K(a, e)
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
return () => {
|
|
321
|
+
r = !1, a.removeEventSubscription(o);
|
|
322
|
+
};
|
|
323
|
+
}, [e]), r;
|
|
324
|
+
}, J = {
|
|
325
|
+
idToken: null,
|
|
326
|
+
idTokenPayload: null
|
|
327
|
+
}, Y = (e) => {
|
|
328
|
+
let n = t.get, r = n(e);
|
|
329
|
+
if (r.tokens) {
|
|
330
|
+
let e = r.tokens;
|
|
331
|
+
return {
|
|
332
|
+
idToken: e.idToken,
|
|
333
|
+
idTokenPayload: e.idTokenPayload
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
return J;
|
|
337
|
+
}, X = (e = V) => {
|
|
338
|
+
let n = t.get, [r, i] = p(() => Y(e));
|
|
339
|
+
return d(() => {
|
|
340
|
+
let r = !0, a = n(e), o = a.subscribeEvents((e, n) => {
|
|
341
|
+
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) {
|
|
342
|
+
let e = a.tokens;
|
|
343
|
+
i(e == null ? J : {
|
|
344
|
+
idToken: e.idToken,
|
|
345
|
+
idTokenPayload: e.idTokenPayload
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
return () => {
|
|
350
|
+
r = !1, a.removeEventSubscription(o);
|
|
351
|
+
};
|
|
352
|
+
}, [e]), r;
|
|
353
|
+
}, Z = /* @__PURE__ */ function(e) {
|
|
354
|
+
return e.Unauthenticated = "Unauthenticated", e.Loading = "Loading user", e.Loaded = "User loaded", e.LoadingError = "Error loading user", e;
|
|
355
|
+
}({}), Q = (e = "default", n = !1) => {
|
|
356
|
+
let r = t.get(e).userInfo(), [i, a] = p({
|
|
357
|
+
user: r,
|
|
358
|
+
status: r ? Z.Loaded : Z.Unauthenticated
|
|
359
|
+
}), [o, s] = p(+!!r), c = f(+!!r);
|
|
360
|
+
return d(() => {
|
|
361
|
+
let r = t.get(e), s = !0;
|
|
362
|
+
if (r && r.tokens) {
|
|
363
|
+
let e = o === c.current;
|
|
364
|
+
if (e && r.userInfo()) return;
|
|
365
|
+
c.current = o, queueMicrotask(() => {
|
|
366
|
+
s && a({
|
|
367
|
+
...i,
|
|
368
|
+
status: Z.Loading
|
|
369
|
+
});
|
|
370
|
+
}), r.userInfoAsync(!e, n).then((e) => {
|
|
371
|
+
s && a({
|
|
372
|
+
user: e,
|
|
373
|
+
status: Z.Loaded
|
|
374
|
+
});
|
|
375
|
+
}).catch(() => a({
|
|
376
|
+
...i,
|
|
377
|
+
status: Z.LoadingError
|
|
378
|
+
}));
|
|
379
|
+
} else queueMicrotask(() => {
|
|
380
|
+
s && a({
|
|
381
|
+
user: null,
|
|
382
|
+
status: Z.Unauthenticated
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
let l = r.subscribeEvents((e) => {
|
|
386
|
+
(e === t.eventNames.logout_from_another_tab || e === t.eventNames.logout_from_same_tab) && s && a({
|
|
387
|
+
user: null,
|
|
388
|
+
status: Z.Unauthenticated
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
return () => {
|
|
392
|
+
s = !1, r.removeEventSubscription(l);
|
|
393
|
+
};
|
|
394
|
+
}, [
|
|
395
|
+
o,
|
|
396
|
+
e,
|
|
397
|
+
n
|
|
398
|
+
]), {
|
|
399
|
+
oidcUser: i.user,
|
|
400
|
+
oidcUserLoadingState: i.status,
|
|
401
|
+
reloadOidcUser: () => {
|
|
402
|
+
s(o + 1);
|
|
403
|
+
}
|
|
404
|
+
};
|
|
429
405
|
};
|
|
406
|
+
//#endregion
|
|
407
|
+
export { e as OidcClient, n as OidcLocation, R as OidcProvider, z as OidcSecure, Z as OidcUserStatus, i as TokenAutomaticRenewMode, a as TokenRenewMode, U as useOidc, q as useOidcAccessToken, b as useOidcFetch, X as useOidcIdToken, Q as useOidcUser, y as withOidcFetch, B as withOidcSecure };
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(f,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("react/jsx-runtime"),require("@axa-fr/oidc-client"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@axa-fr/oidc-client","react"],c):(f=typeof globalThis<"u"?globalThis:f||self,c(f["react-oidc"]={},f.jsxRuntime,f.oidcClient,f.React))})(this,(function(f,c,s,d){"use strict";const N="default",z=(t,n,e=!1)=>async(...o)=>await n().fetchWithTokens(t,e)(...o),K=(t=null,n=N,e=!1)=>o=>r=>{const{fetch:i}=F(t||r.fetch,n,e);return c.jsx(o,{...r,fetch:i})},F=(t=null,n=N,e=!1)=>{const o=t||window.fetch,r=s.OidcClient.get;return{fetch:d.useCallback((u,a)=>z(o,()=>r(n),e)(u,a),[o,n,e])}},I=()=>c.jsx("div",{className:"oidc-authenticating",children:c.jsxs("div",{className:"oidc-authenticating__container",children:[c.jsx("h1",{className:"oidc-authenticating__title",children:"Error authentication"}),c.jsx("p",{className:"oidc-authenticating__content",children:"An error occurred during authentication."})]})}),$=()=>c.jsx("div",{className:"oidc-authenticating",children:c.jsxs("div",{className:"oidc-authenticating__container",children:[c.jsx("h1",{className:"oidc-authenticating__title",children:"Authentication in progress"}),c.jsx("p",{className:"oidc-authenticating__content",children:"You will be redirected to the login page."})]})}),G=()=>Math.random().toString(36).slice(2,8),H=(t,n)=>(e,o)=>{if(typeof t.CustomEvent=="function")return new t.CustomEvent(e,o);const r=o||{bubbles:!1,cancelable:!1,detail:void 0},i=n.createEvent("CustomEvent");return i.initCustomEvent(e,r.bubbles,r.cancelable,r.detail),i.prototype=t.Event.prototype,i},Q=(t,n,e)=>({replaceState:(o,r)=>{const i=e(),u=r||t.history.state;t.history.replaceState({key:i,state:u},null,o),t.dispatchEvent(n("popstate"))}}),J=()=>Q(window,H(window,document),G),m=()=>c.jsx("div",{className:"oidc-callback",children:c.jsxs("div",{className:"oidc-callback__container",children:[c.jsx("h1",{className:"oidc-callback__title",children:"Authentication complete"}),c.jsx("p",{className:"oidc-callback__content",children:"You will be redirected to your application."})]})}),V=({callBackError:t,callBackSuccess:n,configurationName:e,withCustomHistory:o})=>{const[r,i]=d.useState(!1);d.useEffect(()=>{let l=!0;return(async()=>{const k=s.OidcClient.get;try{const{callbackPath:O}=await k(e).loginCallbackAsync();(o?o():J()).replaceState(O||"/")}catch(O){l&&(console.warn(O),i(!0))}})(),()=>{l=!1}},[]);const u=t||I,a=n||m;return r?c.jsx(u,{configurationName:e}):c.jsx(a,{configurationName:e})},X=()=>c.jsx("span",{className:"oidc-loading",children:"Loading"}),Z=()=>c.jsx("div",{className:"oidc-serviceworker",children:c.jsxs("div",{className:"oidc-serviceworker__container",children:[c.jsx("h1",{className:"oidc-serviceworker__title",children:"Unable to authenticate on this browser"}),c.jsx("p",{className:"oidc-serviceworker__content",children:"Your browser is not secure enough to make authentication work. Try updating your browser or use a newer browser."})]})}),x=()=>c.jsx("div",{className:"oidc-session-lost",children:c.jsxs("div",{className:"oidc-session-lost__container",children:[c.jsx("h1",{className:"oidc-session-lost__title",children:"Session timed out"}),c.jsx("p",{className:"oidc-session-lost__content",children:"Your session has expired. Please re-authenticate."})]})}),R=({configurationName:t})=>(d.useEffect(()=>{(async()=>{s.OidcClient.get(t).silentLoginCallbackAsync()})().catch(e=>{console.error("Error during silent login callback:",e)})},[t]),null),ee=({configurationName:t})=>{const n=s.getParseQueryStringFromLocation(window.location.href),e=s.OidcClient.get,o=e(t);let r=null;for(const[i,u]of Object.entries(n))i==="state"||i==="scope"||(r===null&&(r={}),r[i]=u);return d.useEffect(()=>{o.tokens||o.loginAsync(null,r,!0,n.scope)},[]),c.jsx(c.Fragment,{})},te=({callbackErrorComponent:t,callbackSuccessComponent:n,redirect_uri:e,silent_redirect_uri:o,silent_login_uri:r,children:i,configurationName:u,withCustomHistory:a=null})=>{const l=window?s.getPath(window.location.href):"",[h,k]=d.useState(l);d.useEffect(()=>{const y=()=>k(s.getPath(window.location.href));return y(),window.addEventListener("popstate",y,!1),()=>window.removeEventListener("popstate",y,!1)},[]);const O=s.getPath(e);return o&&h===s.getPath(o)?c.jsx(R,{configurationName:u}):r&&h===s.getPath(r)?c.jsx(ee,{configurationName:u}):h===O?c.jsx(V,{callBackError:t,callBackSuccess:n,configurationName:u,withCustomHistory:a}):c.jsx(c.Fragment,{children:i})},se=d.memo(te),M={name:"",data:null},ne=({loadingComponent:t,children:n,configurationName:e})=>{const[o,r]=d.useState(!0),i=s.OidcClient.get,u=i(e);d.useEffect(()=>{let l=!0;return u&&u.tryKeepExistingSessionAsync().then(()=>{l&&r(!1)}),()=>{l=!1}},[e]);const a=t;return c.jsx(c.Fragment,{children:o?c.jsx(a,{configurationName:e}):c.jsx(c.Fragment,{children:n})})},p=({isLoading:t,loadingComponent:n,children:e,configurationName:o})=>{const r=n;return t?c.jsx(r,{configurationName:o,children:e}):c.jsx(c.Fragment,{children:e})},ce=({children:t,configuration:n,configurationName:e="default",callbackSuccessComponent:o=m,authenticatingComponent:r=$,loadingComponent:i=X,serviceWorkerNotSupportedComponent:u=Z,authenticatingErrorComponent:a=I,sessionLostComponent:l=x,onSessionLost:h=null,onLogoutFromAnotherTab:k=null,onLogoutFromSameTab:O=null,withCustomHistory:y=null,onEvent:v=null,getFetch:S=null,location:Y=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=(C="default")=>s.OidcClient.getOrCreate(S??s.getFetchDefault,Y??new s.OidcLocation)(n,C),[fe,T]=d.useState(M),[ke,B]=d.useState(e);d.useEffect(()=>{const L=w(e).subscribeEvents((_,g)=>{v&&v(e,_,g)});return()=>{w(e).removeEventSubscription(L)}},[e,v]),d.useEffect(()=>{const L=w(e).subscribeEvents((_,g)=>{if(_===s.OidcClient.eventNames.refreshTokensAsync_error||_===s.OidcClient.eventNames.syncTokensAsync_error){if(h!=null){h();return}T({name:_,data:g})}else if(_===s.OidcClient.eventNames.logout_from_another_tab){if(k!=null){k();return}T({name:_,data:g})}else _===s.OidcClient.eventNames.logout_from_same_tab?O?.():_===s.OidcClient.eventNames.loginAsync_begin||_===s.OidcClient.eventNames.loginCallbackAsync_end||_===s.OidcClient.eventNames.loginAsync_error||_===s.OidcClient.eventNames.loginCallbackAsync_error?T({name:_,data:g}):_===s.OidcClient.eventNames.service_worker_not_supported_by_browser&&n.service_worker_only===!0&&T({name:_,data:g})});return queueMicrotask(()=>{B(e)}),()=>{w(e).removeEventSubscription(L),T(M)}},[n,e]),d.useEffect(()=>{B(e)},[e]);const _e=l,Oe=r,b=i,ve=u,ye=a,A=ke!==e,P=w(e);switch(fe.name){case s.OidcClient.eventNames.service_worker_not_supported_by_browser:return c.jsx(p,{loadingComponent:b,isLoading:A,configurationName:e,children:c.jsx(ve,{configurationName:e})});case s.OidcClient.eventNames.loginAsync_begin:return c.jsx(p,{loadingComponent:b,isLoading:A,configurationName:e,children:c.jsx(Oe,{configurationName:e})});case s.OidcClient.eventNames.loginAsync_error:case s.OidcClient.eventNames.loginCallbackAsync_error:return c.jsx(p,{loadingComponent:b,isLoading:A,configurationName:e,children:c.jsx(ye,{configurationName:e})});case s.OidcClient.eventNames.refreshTokensAsync_error:case s.OidcClient.eventNames.syncTokensAsync_error:case s.OidcClient.eventNames.logout_from_another_tab:return c.jsx(p,{loadingComponent:b,isLoading:A,configurationName:e,children:c.jsx(_e,{configurationName:e})});default:return c.jsx(p,{loadingComponent:b,isLoading:A,configurationName:e,children:c.jsx(se,{redirect_uri:P.configuration.redirect_uri,silent_redirect_uri:P.configuration.silent_redirect_uri,silent_login_uri:P.configuration.silent_login_uri,callbackSuccessComponent:o,callbackErrorComponent:a,authenticatingComponent:r,configurationName:e,withCustomHistory:y,location:Y??new s.OidcLocation,children:c.jsx(ne,{loadingComponent:b,configurationName:e,children:t})})})}},U=({children:t,callbackPath:n=null,extras:e=null,configurationName:o="default"})=>{const r=s.OidcClient.get,i=r(o);return d.useEffect(()=>{i.tokens||i.loginAsync(n,e)},[o,n,e]),i.tokens?c.jsx(c.Fragment,{children:t}):null},oe=(t,n=null,e=null,o="default")=>r=>c.jsx(U,{callbackPath:n,extras:e,configurationName:o,children:c.jsx(t,{...r})}),E="default",q=(t,n)=>{let e=!1;return t(n)&&(e=t(n).tokens!=null),e},re=(t=E)=>{const n=s.OidcClient.get,[e,o]=d.useState(()=>q(n,t));return d.useEffect(()=>{let a=!0;const l=n(t),h=l.subscribeEvents((k,O)=>{(k===s.OidcClient.eventNames.logout_from_another_tab||k===s.OidcClient.eventNames.logout_from_same_tab||k===s.OidcClient.eventNames.token_acquired)&&a&&o(q(n,t))});return()=>{a=!1,l.removeEventSubscription(h)}},[t]),{login:(a=void 0,l=void 0,h=!1,k=void 0)=>n(t).loginAsync(a,l,!1,k,h),logout:(a=void 0,l=void 0)=>n(t).logoutAsync(a,l),renewTokens:async(a=void 0)=>{const l=await n(t).renewTokensAsync(a);return{accessToken:l.accessToken,accessTokenPayload:l.accessTokenPayload,idToken:l.idToken,idTokenPayload:l.idTokenPayload}},isAuthenticated:e}},D={accessToken:null,accessTokenPayload:null},ie=t=>{const n=s.OidcClient.get,e=n(t);if(e.tokens){const o=e.tokens;return{accessToken:o.accessToken,accessTokenPayload:o.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:e.configuration.demonstrating_proof_of_possession?(r,i)=>e.generateDemonstrationOfProofOfPossessionAsync(o.accessToken,r,i):null}}return D};function ae(t,n){return t.configuration.demonstrating_proof_of_possession?(e,o,r={})=>t.generateDemonstrationOfProofOfPossessionAsync(n.accessToken,e,o,r):null}const le=(t=E)=>{const n=s.OidcClient.get,[e,o]=d.useState(()=>ie(t));return d.useEffect(()=>{let r=!0;const i=n(t),u=i.subscribeEvents((a,l)=>{if((a===s.OidcClient.eventNames.token_renewed||a===s.OidcClient.eventNames.token_acquired||a===s.OidcClient.eventNames.logout_from_another_tab||a===s.OidcClient.eventNames.logout_from_same_tab||a===s.OidcClient.eventNames.refreshTokensAsync_error||a===s.OidcClient.eventNames.syncTokensAsync_error)&&r){const h=i.tokens;o(h!=null?{accessToken:h.accessToken,accessTokenPayload:h.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:ae(i,h)}:D)}});return()=>{r=!1,i.removeEventSubscription(u)}},[t]),e},W={idToken:null,idTokenPayload:null},de=t=>{const n=s.OidcClient.get,e=n(t);if(e.tokens){const o=e.tokens;return{idToken:o.idToken,idTokenPayload:o.idTokenPayload}}return W},ue=(t=E)=>{const n=s.OidcClient.get,[e,o]=d.useState(()=>de(t));return d.useEffect(()=>{let r=!0;const i=n(t),u=i.subscribeEvents((a,l)=>{if((a===s.OidcClient.eventNames.token_renewed||a===s.OidcClient.eventNames.token_acquired||a===s.OidcClient.eventNames.logout_from_another_tab||a===s.OidcClient.eventNames.logout_from_same_tab||a===s.OidcClient.eventNames.refreshTokensAsync_error||a===s.OidcClient.eventNames.syncTokensAsync_error)&&r){const h=i.tokens;o(h!=null?{idToken:h.idToken,idTokenPayload:h.idTokenPayload}:W)}});return()=>{r=!1,i.removeEventSubscription(u)}},[t]),e};var j=(t=>(t.Unauthenticated="Unauthenticated",t.Loading="Loading user",t.Loaded="User loaded",t.LoadingError="Error loading user",t))(j||{});const he=(t="default",n=!1)=>{const o=s.OidcClient.get(t).userInfo(),[r,i]=d.useState({user:o,status:o?"User loaded":"Unauthenticated"}),[u,a]=d.useState(o?1:0),l=d.useRef(o?1:0);d.useEffect(()=>{const k=s.OidcClient.get(t);let O=!0;if(k&&k.tokens){const v=u===l.current;if(v&&k.userInfo())return;l.current=u,queueMicrotask(()=>{O&&i({...r,status:"Loading user"})}),k.userInfoAsync(!v,n).then(S=>{O&&i({user:S,status:"User loaded"})}).catch(()=>i({...r,status:"Error loading user"}))}else queueMicrotask(()=>{O&&i({user:null,status:"Unauthenticated"})});const y=k.subscribeEvents(v=>{(v===s.OidcClient.eventNames.logout_from_another_tab||v===s.OidcClient.eventNames.logout_from_same_tab)&&O&&i({user:null,status:"Unauthenticated"})});return()=>{O=!1,k.removeEventSubscription(y)}},[u,t,n]);const h=()=>{a(u+1)};return{oidcUser:r.user,oidcUserLoadingState:r.status,reloadOidcUser:h}};Object.defineProperty(f,"OidcClient",{enumerable:!0,get:()=>s.OidcClient}),Object.defineProperty(f,"OidcLocation",{enumerable:!0,get:()=>s.OidcLocation}),Object.defineProperty(f,"TokenAutomaticRenewMode",{enumerable:!0,get:()=>s.TokenAutomaticRenewMode}),Object.defineProperty(f,"TokenRenewMode",{enumerable:!0,get:()=>s.TokenRenewMode}),f.OidcProvider=ce,f.OidcSecure=U,f.OidcUserStatus=j,f.useOidc=re,f.useOidcAccessToken=le,f.useOidcFetch=F,f.useOidcIdToken=ue,f.useOidcUser=he,f.withOidcFetch=K,f.withOidcSecure=oe,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}));
|
|
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.get;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=({callBackError:e,callBackSuccess:i,configurationName:a,withCustomHistory:o})=>{let[s,c]=(0,n.useState)(!1);(0,n.useEffect)(()=>{let e=!0;return(async()=>{let n=t.OidcClient.get;try{let{callbackPath:e}=await n(a).loginCallbackAsync();(o?o():b()).replaceState(e||`/`)}catch(t){e&&(console.warn(t),c(!0))}})(),()=>{e=!1}},[]);let l=e||h,u=i||x;return s?(0,r.jsx)(l,{configurationName:a}):(0,r.jsx)(u,{configurationName:a})},C=()=>(0,r.jsx)(`span`,{className:`oidc-loading`,children:`Loading`}),w=()=>(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.`})]})}),T=()=>(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.`})]})}),E=({configurationName:e})=>((0,n.useEffect)(()=>{(async()=>{t.OidcClient.get(e).silentLoginCallbackAsync()})().catch(e=>{console.error(`Error during silent login callback:`,e)})},[e]),null),D=({configurationName:e})=>{let i=(0,t.getParseQueryStringFromLocation)(window.location.href),a=t.OidcClient.get,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,{})},O=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})=>{let[d,f]=(0,n.useState)(window?(0,t.getPath)(window.location.href):``);(0,n.useEffect)(()=>{let e=()=>f((0,t.getPath)(window.location.href));return e(),window.addEventListener(`popstate`,e,!1),()=>window.removeEventListener(`popstate`,e,!1)},[]);let p=(0,t.getPath)(a);if(o&&d===(0,t.getPath)(o))return(0,r.jsx)(E,{configurationName:l});if(s&&d===(0,t.getPath)(s))return(0,r.jsx)(D,{configurationName:l});switch(d){case p:return(0,r.jsx)(S,{callBackError:e,callBackSuccess:i,configurationName:l,withCustomHistory:u});default:return(0,r.jsx)(r.Fragment,{children:c})}}),k={name:``,data:null},A=({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})})},j=({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})},M=({children:e,configuration:i,configurationName:a=`default`,callbackSuccessComponent:o=x,authenticatingComponent:s=g,loadingComponent:c=C,serviceWorkerNotSupportedComponent:l=w,authenticatingErrorComponent:u=h,sessionLostComponent:d=T,onSessionLost:f=null,onLogoutFromAnotherTab:p=null,onLogoutFromSameTab:m=null,withCustomHistory:_=null,onEvent:v=null,getFetch:y=null,location:b=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 S=(e=`default`)=>t.OidcClient.getOrCreate(y??t.getFetchDefault,b??new t.OidcLocation)(i,e),[E,D]=(0,n.useState)(k),[M,N]=(0,n.useState)(a);(0,n.useEffect)(()=>{let e=S(a).subscribeEvents((e,t)=>{v&&v(a,e,t)});return()=>{S(a).removeEventSubscription(e)}},[a,v]),(0,n.useEffect)(()=>{let e=S(a).subscribeEvents((e,n)=>{if(e===t.OidcClient.eventNames.refreshTokensAsync_error||e===t.OidcClient.eventNames.syncTokensAsync_error){if(f!=null){f();return}D({name:e,data:n})}else if(e===t.OidcClient.eventNames.logout_from_another_tab){if(p!=null){p();return}D({name:e,data:n})}else e===t.OidcClient.eventNames.logout_from_same_tab?m?.():(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)&&D({name:e,data:n})});return queueMicrotask(()=>{N(a)}),()=>{S(a).removeEventSubscription(e),D(k)}},[i,a]);let P=d,F=s,I=c,L=l,R=u,z=M!==a,B=S(a);switch(E.name){case t.OidcClient.eventNames.service_worker_not_supported_by_browser:return(0,r.jsx)(j,{loadingComponent:I,isLoading:z,configurationName:a,children:(0,r.jsx)(L,{configurationName:a})});case t.OidcClient.eventNames.loginAsync_begin:return(0,r.jsx)(j,{loadingComponent:I,isLoading:z,configurationName:a,children:(0,r.jsx)(F,{configurationName:a})});case t.OidcClient.eventNames.loginAsync_error:case t.OidcClient.eventNames.loginCallbackAsync_error:return(0,r.jsx)(j,{loadingComponent:I,isLoading:z,configurationName:a,children:(0,r.jsx)(R,{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)(j,{loadingComponent:I,isLoading:z,configurationName:a,children:(0,r.jsx)(P,{configurationName:a})});default:return(0,r.jsx)(j,{loadingComponent:I,isLoading:z,configurationName:a,children:(0,r.jsx)(O,{redirect_uri:B.configuration.redirect_uri,silent_redirect_uri:B.configuration.silent_redirect_uri,silent_login_uri:B.configuration.silent_login_uri,callbackSuccessComponent:o,callbackErrorComponent:u,authenticatingComponent:s,configurationName:a,withCustomHistory:_,location:b??new t.OidcLocation,children:(0,r.jsx)(A,{loadingComponent:I,configurationName:a,children:e})})})}},N=({children:e,callbackPath:i=null,extras:a=null,configurationName:o=`default`})=>{let s=t.OidcClient.get,c=s(o);return(0,n.useEffect)(()=>{c.tokens||c.loginAsync(i,a)},[o,i,a]),c.tokens?(0,r.jsx)(r.Fragment,{children:e}):null},P=(e,t=null,n=null,i=`default`)=>a=>(0,r.jsx)(N,{callbackPath:t,extras:n,configurationName:i,children:(0,r.jsx)(e,{...a})}),F=`default`,I=(e,t)=>{let n=!1;return e(t)&&(n=e(t).tokens!=null),n},L=(e=F)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>I(r,e));return(0,n.useEffect)(()=>{let n=!0,i=r(e),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(I(r,e))});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),{login:(t=void 0,n=void 0,i=!1,a=void 0)=>r(e).loginAsync(t,n,!1,a,i),logout:(t=void 0,n=void 0)=>r(e).logoutAsync(t,n),renewTokens:async(t=void 0)=>{let n=await r(e).renewTokensAsync(t);return{accessToken:n.accessToken,accessTokenPayload:n.accessTokenPayload,idToken:n.idToken,idTokenPayload:n.idTokenPayload}},isAuthenticated:i}},R={accessToken:null,accessTokenPayload:null},z=e=>{let n=t.OidcClient.get,r=n(e);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 R};function B(e,t){return e.configuration.demonstrating_proof_of_possession?(n,r,i={})=>e.generateDemonstrationOfProofOfPossessionAsync(t.accessToken,n,r,i):null}var V=(e=F)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>z(e));return(0,n.useEffect)(()=>{let n=!0,i=r(e),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?R:{accessToken:e.accessToken,accessTokenPayload:e.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:B(i,e)})}});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),i},H={idToken:null,idTokenPayload:null},U=e=>{let n=t.OidcClient.get,r=n(e);if(r.tokens){let e=r.tokens;return{idToken:e.idToken,idTokenPayload:e.idTokenPayload}}return H},W=(e=F)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>U(e));return(0,n.useEffect)(()=>{let n=!0,i=r(e),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?H:{idToken:e.idToken,idTokenPayload:e.idTokenPayload})}});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),i},G=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=M,e.OidcSecure=N,e.OidcUserStatus=G,Object.defineProperty(e,`TokenAutomaticRenewMode`,{enumerable:!0,get:function(){return t.TokenAutomaticRenewMode}}),Object.defineProperty(e,`TokenRenewMode`,{enumerable:!0,get:function(){return t.TokenRenewMode}}),e.useOidc=L,e.useOidcAccessToken=V,e.useOidcFetch=m,e.useOidcIdToken=W,e.useOidcUser=(e=`default`,r=!1)=>{let i=t.OidcClient.get(e).userInfo(),[a,o]=(0,n.useState)({user:i,status:i?G.Loaded:G.Unauthenticated}),[s,c]=(0,n.useState)(+!!i),l=(0,n.useRef)(+!!i);return(0,n.useEffect)(()=>{let n=t.OidcClient.get(e),i=!0;if(n&&n.tokens){let e=s===l.current;if(e&&n.userInfo())return;l.current=s,queueMicrotask(()=>{i&&o({...a,status:G.Loading})}),n.userInfoAsync(!e,r).then(e=>{i&&o({user:e,status:G.Loaded})}).catch(()=>o({...a,status:G.LoadingError}))}else queueMicrotask(()=>{i&&o({user:null,status:G.Unauthenticated})});let c=n.subscribeEvents(e=>{(e===t.OidcClient.eventNames.logout_from_another_tab||e===t.OidcClient.eventNames.logout_from_same_tab)&&i&&o({user:null,status:G.Unauthenticated})});return()=>{i=!1,n.removeEventSubscription(c)}},[s,e,r]),{oidcUser:a.user,oidcUserLoadingState:a.status,reloadOidcUser:()=>{c(s+1)}}},e.withOidcFetch=p,e.withOidcSecure=P});
|
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.4",
|
|
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
|
|
44
|
-
"@axa-fr/oidc-client": "7.27.
|
|
43
|
+
"@axa-fr/oidc-client": "7.27.4",
|
|
44
|
+
"@axa-fr/oidc-client-service-worker": "7.27.4"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"react": "^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
@@ -50,21 +50,21 @@
|
|
|
50
50
|
"@testing-library/jest-dom": "6.9.1",
|
|
51
51
|
"@testing-library/react": "16.3.2",
|
|
52
52
|
"@testing-library/user-event": "14.6.1",
|
|
53
|
-
"@types/react": "19.2.
|
|
54
|
-
"@vitejs/plugin-react": "
|
|
55
|
-
"@vitest/coverage-v8": "4.
|
|
56
|
-
"cpy": "
|
|
57
|
-
"cpy-cli": "^
|
|
53
|
+
"@types/react": "19.2.14",
|
|
54
|
+
"@vitejs/plugin-react": "6.0.1",
|
|
55
|
+
"@vitest/coverage-v8": "4.1.5",
|
|
56
|
+
"cpy": "13.2.1",
|
|
57
|
+
"cpy-cli": "^7.0.0",
|
|
58
58
|
"cross-env": "^10.1.0",
|
|
59
|
-
"jsdom": "
|
|
60
|
-
"msw": "2.
|
|
61
|
-
"react": "^19.2.
|
|
62
|
-
"react-dom": "^19.2.
|
|
63
|
-
"rimraf": "6.1.
|
|
64
|
-
"typescript": "
|
|
65
|
-
"vite": "
|
|
59
|
+
"jsdom": "29.0.2",
|
|
60
|
+
"msw": "2.13.6",
|
|
61
|
+
"react": "^19.2.5",
|
|
62
|
+
"react-dom": "^19.2.5",
|
|
63
|
+
"rimraf": "6.1.3",
|
|
64
|
+
"typescript": "6.0.3",
|
|
65
|
+
"vite": "8.0.10",
|
|
66
66
|
"vite-plugin-dts": "4.5.4",
|
|
67
|
-
"vitest": "4.
|
|
67
|
+
"vitest": "4.1.5"
|
|
68
68
|
},
|
|
69
69
|
"license": "MIT",
|
|
70
70
|
"publishConfig": {
|
package/src/OidcProvider.tsx
CHANGED
|
@@ -181,10 +181,6 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
|
|
|
181
181
|
};
|
|
182
182
|
}, [configuration, configurationName]);
|
|
183
183
|
|
|
184
|
-
useEffect(() => {
|
|
185
|
-
setConfigurationName(configurationName);
|
|
186
|
-
}, [configurationName]);
|
|
187
|
-
|
|
188
184
|
const SessionLostComponent = sessionLostComponent;
|
|
189
185
|
const AuthenticatingComponent = authenticatingComponent;
|
|
190
186
|
const LoadingComponent = loadingComponent;
|