@axa-fr/react-oidc 7.27.14 → 7.27.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/OidcProvider.d.ts.map +1 -1
- package/dist/index.js +52 -51
- package/dist/index.umd.cjs +1 -1
- package/package.json +3 -3
- package/src/OidcProvider.spec.tsx +143 -22
- package/src/OidcProvider.tsx +40 -3
|
@@ -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;AAYlF,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,uBAAuB,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAC7C,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,qBAAqB,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE,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;
|
|
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;AAYlF,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,uBAAuB,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAC7C,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,qBAAqB,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE,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;AA+DF,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CA4NjE,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -190,9 +190,9 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
190
190
|
}, B = ({ isLoading: e, loadingComponent: t, children: n, configurationName: r }) => e ? /* @__PURE__ */ h(t, {
|
|
191
191
|
configurationName: r,
|
|
192
192
|
children: n
|
|
193
|
-
}) : /* @__PURE__ */ h(m, { children: n }), V = 3e4, H = ({ children: e, configuration: n, configurationName: i = "default", callbackSuccessComponent: a = D, authenticatingComponent: s = S, loadingComponent: c = j, loadingTimeoutComponent: l = M, serviceWorkerNotSupportedComponent: u = N, authenticatingErrorComponent: f = x, sessionLostComponent: m = P, onSessionLost: g = null, onLogoutFromAnotherTab: _ = null, onLogoutFromSameTab: v = null, withCustomHistory: y = null, navigateAfterCallback: b = null, onEvent: C = null, getFetch: w = null, location: T = null }) => {
|
|
193
|
+
}) : /* @__PURE__ */ h(m, { children: n }), V = 3e4, H = (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, U = ({ children: e, configuration: n, configurationName: i = "default", callbackSuccessComponent: a = D, authenticatingComponent: s = S, loadingComponent: c = j, loadingTimeoutComponent: l = M, serviceWorkerNotSupportedComponent: u = N, authenticatingErrorComponent: f = x, sessionLostComponent: m = P, onSessionLost: g = null, onLogoutFromAnotherTab: _ = null, onLogoutFromSameTab: v = null, withCustomHistory: y = null, navigateAfterCallback: b = null, onEvent: C = null, getFetch: w = null, location: T = 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(w ?? o, T ?? new r())(n, e), [O, k] = p(R), [A, F] = p(i);
|
|
195
|
+
let E = (e = "default") => t.getOrCreate(w ?? o, T ?? new r())(n, e), [O, k] = p(R), [A, F] = p(!1), [I, U] = p(i);
|
|
196
196
|
d(() => {
|
|
197
197
|
let e = E(i).subscribeEvents((e, t) => {
|
|
198
198
|
C && C(i, e, t);
|
|
@@ -202,7 +202,7 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
202
202
|
};
|
|
203
203
|
}, [i, C]), d(() => {
|
|
204
204
|
let e = E(i).subscribeEvents((e, r) => {
|
|
205
|
-
if (e === t.eventNames.refreshTokensAsync_error || e === t.eventNames.syncTokensAsync_error) {
|
|
205
|
+
if (H(e, r) && F(!0), e === t.eventNames.refreshTokensAsync_error || e === t.eventNames.syncTokensAsync_error) {
|
|
206
206
|
if (g != null) {
|
|
207
207
|
g();
|
|
208
208
|
return;
|
|
@@ -226,65 +226,66 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
226
226
|
});
|
|
227
227
|
});
|
|
228
228
|
return queueMicrotask(() => {
|
|
229
|
-
|
|
229
|
+
U(i);
|
|
230
230
|
}), () => {
|
|
231
|
-
E(i).removeEventSubscription(e), k(R);
|
|
231
|
+
E(i).removeEventSubscription(e), k(R), F(!1);
|
|
232
232
|
};
|
|
233
233
|
}, [n, i]), d(() => {
|
|
234
234
|
let e = n?.loading_timeout_ms ?? V;
|
|
235
|
-
if (e <= 0 || !(O.name === "" || O.name === t.eventNames.loginAsync_begin)) return;
|
|
235
|
+
if (e <= 0 || A || E(i)?.tokens != null || !(O.name === "" || O.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
241
|
O.name,
|
|
242
|
+
A,
|
|
242
243
|
i,
|
|
243
244
|
n
|
|
244
245
|
]);
|
|
245
|
-
let
|
|
246
|
+
let W = m, G = s, K = c, q = l, J = u, Y = f, X = I !== i, Z = E(i);
|
|
246
247
|
switch (O.name) {
|
|
247
248
|
case t.eventNames.service_worker_not_supported_by_browser: return /* @__PURE__ */ h(B, {
|
|
248
|
-
loadingComponent:
|
|
249
|
-
isLoading:
|
|
249
|
+
loadingComponent: K,
|
|
250
|
+
isLoading: X,
|
|
250
251
|
configurationName: i,
|
|
251
|
-
children: /* @__PURE__ */ h(
|
|
252
|
+
children: /* @__PURE__ */ h(J, { configurationName: i })
|
|
252
253
|
});
|
|
253
254
|
case t.eventNames.loginAsync_begin: return /* @__PURE__ */ h(B, {
|
|
254
|
-
loadingComponent:
|
|
255
|
-
isLoading:
|
|
255
|
+
loadingComponent: K,
|
|
256
|
+
isLoading: X,
|
|
256
257
|
configurationName: i,
|
|
257
|
-
children: /* @__PURE__ */ h(
|
|
258
|
+
children: /* @__PURE__ */ h(G, { configurationName: i })
|
|
258
259
|
});
|
|
259
260
|
case t.eventNames.loadingTimeout_error: return /* @__PURE__ */ h(B, {
|
|
260
|
-
loadingComponent:
|
|
261
|
-
isLoading:
|
|
261
|
+
loadingComponent: K,
|
|
262
|
+
isLoading: X,
|
|
262
263
|
configurationName: i,
|
|
263
|
-
children: /* @__PURE__ */ h(
|
|
264
|
+
children: /* @__PURE__ */ h(q, { configurationName: i })
|
|
264
265
|
});
|
|
265
266
|
case t.eventNames.loginAsync_error:
|
|
266
267
|
case t.eventNames.loginCallbackAsync_error: return /* @__PURE__ */ h(B, {
|
|
267
|
-
loadingComponent:
|
|
268
|
-
isLoading:
|
|
268
|
+
loadingComponent: K,
|
|
269
|
+
isLoading: X,
|
|
269
270
|
configurationName: i,
|
|
270
|
-
children: /* @__PURE__ */ h(
|
|
271
|
+
children: /* @__PURE__ */ h(Y, { configurationName: i })
|
|
271
272
|
});
|
|
272
273
|
case t.eventNames.refreshTokensAsync_error:
|
|
273
274
|
case t.eventNames.syncTokensAsync_error:
|
|
274
275
|
case t.eventNames.logout_from_another_tab: return /* @__PURE__ */ h(B, {
|
|
275
|
-
loadingComponent:
|
|
276
|
-
isLoading:
|
|
276
|
+
loadingComponent: K,
|
|
277
|
+
isLoading: X,
|
|
277
278
|
configurationName: i,
|
|
278
|
-
children: /* @__PURE__ */ h(
|
|
279
|
+
children: /* @__PURE__ */ h(W, { configurationName: i })
|
|
279
280
|
});
|
|
280
281
|
default: return /* @__PURE__ */ h(B, {
|
|
281
|
-
loadingComponent:
|
|
282
|
-
isLoading:
|
|
282
|
+
loadingComponent: K,
|
|
283
|
+
isLoading: X,
|
|
283
284
|
configurationName: i,
|
|
284
285
|
children: /* @__PURE__ */ h(L, {
|
|
285
|
-
redirect_uri:
|
|
286
|
-
silent_redirect_uri:
|
|
287
|
-
silent_login_uri:
|
|
286
|
+
redirect_uri: Z.configuration.redirect_uri,
|
|
287
|
+
silent_redirect_uri: Z.configuration.silent_redirect_uri,
|
|
288
|
+
silent_login_uri: Z.configuration.silent_login_uri,
|
|
288
289
|
callbackSuccessComponent: a,
|
|
289
290
|
callbackErrorComponent: f,
|
|
290
291
|
authenticatingComponent: s,
|
|
@@ -293,14 +294,14 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
293
294
|
navigateAfterCallback: b,
|
|
294
295
|
location: T ?? new r(),
|
|
295
296
|
children: /* @__PURE__ */ h(z, {
|
|
296
|
-
loadingComponent:
|
|
297
|
+
loadingComponent: K,
|
|
297
298
|
configurationName: i,
|
|
298
299
|
children: e
|
|
299
300
|
})
|
|
300
301
|
})
|
|
301
302
|
});
|
|
302
303
|
}
|
|
303
|
-
},
|
|
304
|
+
}, W = ({ children: e, callbackPath: n = null, extras: r = null, configurationName: i = "default" }) => {
|
|
304
305
|
let a = t.get, o = a(i);
|
|
305
306
|
return d(() => {
|
|
306
307
|
o.tokens || o.loginAsync(n, r);
|
|
@@ -309,19 +310,19 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
309
310
|
n,
|
|
310
311
|
r
|
|
311
312
|
]), o.tokens ? /* @__PURE__ */ h(m, { children: e }) : null;
|
|
312
|
-
},
|
|
313
|
+
}, G = (e, t = null, n = null, r = "default") => (i) => /* @__PURE__ */ h(W, {
|
|
313
314
|
callbackPath: t,
|
|
314
315
|
extras: n,
|
|
315
316
|
configurationName: r,
|
|
316
317
|
children: /* @__PURE__ */ h(e, { ...i })
|
|
317
|
-
}),
|
|
318
|
+
}), K = "default", q = (e, t) => {
|
|
318
319
|
let n = !1;
|
|
319
320
|
return e(t) && (n = e(t).tokens != null), n;
|
|
320
|
-
},
|
|
321
|
-
let n = t.get, [r, i] = p(() =>
|
|
321
|
+
}, J = (e = K) => {
|
|
322
|
+
let n = t.get, [r, i] = p(() => q(n, e));
|
|
322
323
|
return d(() => {
|
|
323
324
|
let r = !0, a = n(e), o = a.subscribeEvents((a, o) => {
|
|
324
|
-
(a === t.eventNames.logout_from_another_tab || a === t.eventNames.logout_from_same_tab || a === t.eventNames.token_acquired) && r && i(
|
|
325
|
+
(a === t.eventNames.logout_from_another_tab || a === t.eventNames.logout_from_same_tab || a === t.eventNames.token_acquired) && r && i(q(n, e));
|
|
325
326
|
});
|
|
326
327
|
return () => {
|
|
327
328
|
r = !1, a.removeEventSubscription(o);
|
|
@@ -340,10 +341,10 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
340
341
|
},
|
|
341
342
|
isAuthenticated: r
|
|
342
343
|
};
|
|
343
|
-
},
|
|
344
|
+
}, Y = {
|
|
344
345
|
accessToken: null,
|
|
345
346
|
accessTokenPayload: null
|
|
346
|
-
},
|
|
347
|
+
}, X = (e) => {
|
|
347
348
|
let n = t.get, r = n(e);
|
|
348
349
|
if (r.tokens) {
|
|
349
350
|
let e = r.tokens;
|
|
@@ -353,21 +354,21 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
353
354
|
generateDemonstrationOfProofOfPossessionAsync: r.configuration.demonstrating_proof_of_possession ? (t, n) => r.generateDemonstrationOfProofOfPossessionAsync(e.accessToken, t, n) : null
|
|
354
355
|
};
|
|
355
356
|
}
|
|
356
|
-
return
|
|
357
|
+
return Y;
|
|
357
358
|
};
|
|
358
|
-
function
|
|
359
|
+
function Z(e, t) {
|
|
359
360
|
return e.configuration.demonstrating_proof_of_possession ? (n, r, i = {}) => e.generateDemonstrationOfProofOfPossessionAsync(t.accessToken, n, r, i) : null;
|
|
360
361
|
}
|
|
361
|
-
var
|
|
362
|
-
let n = t.get, [r, i] = p(() =>
|
|
362
|
+
var Q = (e = K) => {
|
|
363
|
+
let n = t.get, [r, i] = p(() => X(e));
|
|
363
364
|
return d(() => {
|
|
364
365
|
let r = !0, a = n(e), o = a.subscribeEvents((e, n) => {
|
|
365
366
|
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) {
|
|
366
367
|
let e = a.tokens;
|
|
367
|
-
i(e == null ?
|
|
368
|
+
i(e == null ? Y : {
|
|
368
369
|
accessToken: e.accessToken,
|
|
369
370
|
accessTokenPayload: e.accessTokenPayload,
|
|
370
|
-
generateDemonstrationOfProofOfPossessionAsync:
|
|
371
|
+
generateDemonstrationOfProofOfPossessionAsync: Z(a, e)
|
|
371
372
|
});
|
|
372
373
|
}
|
|
373
374
|
});
|
|
@@ -375,10 +376,10 @@ var Z = (e = G) => {
|
|
|
375
376
|
r = !1, a.removeEventSubscription(o);
|
|
376
377
|
};
|
|
377
378
|
}, [e]), r;
|
|
378
|
-
},
|
|
379
|
+
}, $ = {
|
|
379
380
|
idToken: null,
|
|
380
381
|
idTokenPayload: null
|
|
381
|
-
},
|
|
382
|
+
}, ee = (e) => {
|
|
382
383
|
let n = t.get, r = n(e);
|
|
383
384
|
if (r.tokens) {
|
|
384
385
|
let e = r.tokens;
|
|
@@ -387,14 +388,14 @@ var Z = (e = G) => {
|
|
|
387
388
|
idTokenPayload: e.idTokenPayload
|
|
388
389
|
};
|
|
389
390
|
}
|
|
390
|
-
return
|
|
391
|
-
},
|
|
392
|
-
let n = t.get, [r, i] = p(() =>
|
|
391
|
+
return $;
|
|
392
|
+
}, te = (e = K) => {
|
|
393
|
+
let n = t.get, [r, i] = p(() => ee(e));
|
|
393
394
|
return d(() => {
|
|
394
395
|
let r = !0, a = n(e), o = a.subscribeEvents((e, n) => {
|
|
395
396
|
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) {
|
|
396
397
|
let e = a.tokens;
|
|
397
|
-
i(e == null ?
|
|
398
|
+
i(e == null ? $ : {
|
|
398
399
|
idToken: e.idToken,
|
|
399
400
|
idTokenPayload: e.idTokenPayload
|
|
400
401
|
});
|
|
@@ -404,9 +405,9 @@ var Z = (e = G) => {
|
|
|
404
405
|
r = !1, a.removeEventSubscription(o);
|
|
405
406
|
};
|
|
406
407
|
}, [e]), r;
|
|
407
|
-
},
|
|
408
|
+
}, ne = /* @__PURE__ */ function(e) {
|
|
408
409
|
return e.Unauthenticated = "Unauthenticated", e.Loading = "Loading user", e.Loaded = "User loaded", e.LoadingError = "Error loading user", e;
|
|
409
|
-
}({}),
|
|
410
|
+
}({}), re = (e = "default", n = !1) => {
|
|
410
411
|
let r = t.get(e).userInfo(), [i, a] = p({
|
|
411
412
|
user: r,
|
|
412
413
|
status: r ? "User loaded" : "Unauthenticated"
|
|
@@ -458,4 +459,4 @@ var Z = (e = G) => {
|
|
|
458
459
|
};
|
|
459
460
|
};
|
|
460
461
|
//#endregion
|
|
461
|
-
export { e as OidcClient, n as OidcLocation,
|
|
462
|
+
export { e as OidcClient, n as OidcLocation, U as OidcProvider, W as OidcSecure, ne as OidcUserStatus, i as TokenAutomaticRenewMode, a as TokenRenewMode, J as useOidc, Q as useOidcAccessToken, b as useOidcFetch, te as useOidcIdToken, re as useOidcUser, y as withOidcFetch, G 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.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=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.get;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.get(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.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,{})},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=({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),[I,L]=(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(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(()=>{L(a)}),()=>{w(a).removeEventSubscription(e),A(M)}},[i,a]),(0,n.useEffect)(()=>{let e=i?.loading_timeout_ms??F;if(e<=0||!(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,a,i]);let R=f,z=s,B=c,V=l,H=u,U=d,W=I!==a,G=w(a);switch(k.name){case t.OidcClient.eventNames.service_worker_not_supported_by_browser:return(0,r.jsx)(P,{loadingComponent:B,isLoading:W,configurationName:a,children:(0,r.jsx)(H,{configurationName:a})});case t.OidcClient.eventNames.loginAsync_begin:return(0,r.jsx)(P,{loadingComponent:B,isLoading:W,configurationName:a,children:(0,r.jsx)(z,{configurationName:a})});case t.OidcClient.eventNames.loadingTimeout_error:return(0,r.jsx)(P,{loadingComponent:B,isLoading:W,configurationName:a,children:(0,r.jsx)(V,{configurationName:a})});case t.OidcClient.eventNames.loginAsync_error:case t.OidcClient.eventNames.loginCallbackAsync_error:return(0,r.jsx)(P,{loadingComponent:B,isLoading:W,configurationName:a,children:(0,r.jsx)(U,{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:B,isLoading:W,configurationName:a,children:(0,r.jsx)(R,{configurationName:a})});default:return(0,r.jsx)(P,{loadingComponent:B,isLoading:W,configurationName:a,children:(0,r.jsx)(j,{redirect_uri:G.configuration.redirect_uri,silent_redirect_uri:G.configuration.silent_redirect_uri,silent_login_uri:G.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:B,configurationName:a,children:e})})})}},L=({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},R=(e,t=null,n=null,i=`default`)=>a=>(0,r.jsx)(L,{callbackPath:t,extras:n,configurationName:i,children:(0,r.jsx)(e,{...a})}),z=`default`,B=(e,t)=>{let n=!1;return e(t)&&(n=e(t).tokens!=null),n},V=(e=z)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>B(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(B(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}},H={accessToken:null,accessTokenPayload:null},U=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 H};function W(e,t){return e.configuration.demonstrating_proof_of_possession?(n,r,i={})=>e.generateDemonstrationOfProofOfPossessionAsync(t.accessToken,n,r,i):null}var G=(e=z)=>{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:{accessToken:e.accessToken,accessTokenPayload:e.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:W(i,e)})}});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),i},K={idToken:null,idTokenPayload:null},q=e=>{let n=t.OidcClient.get,r=n(e);if(r.tokens){let e=r.tokens;return{idToken:e.idToken,idTokenPayload:e.idTokenPayload}}return K},J=(e=z)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>q(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?K:{idToken:e.idToken,idTokenPayload:e.idTokenPayload})}});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),i},Y=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=I,e.OidcSecure=L,e.OidcUserStatus=Y,Object.defineProperty(e,`TokenAutomaticRenewMode`,{enumerable:!0,get:function(){return t.TokenAutomaticRenewMode}}),Object.defineProperty(e,`TokenRenewMode`,{enumerable:!0,get:function(){return t.TokenRenewMode}}),e.useOidc=V,e.useOidcAccessToken=G,e.useOidcFetch=m,e.useOidcIdToken=J,e.useOidcUser=(e=`default`,r=!1)=>{let i=t.OidcClient.get(e).userInfo(),[a,o]=(0,n.useState)({user:i,status:i?`User loaded`:`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:`Loading user`})}),n.userInfoAsync(!e,r).then(e=>{i&&o({user:e,status:`User loaded`})}).catch(()=>o({...a,status:`Error loading user`}))}else queueMicrotask(()=>{i&&o({user:null,status:`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:`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=R});
|
|
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=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.get;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.get(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.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,{})},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.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},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=`default`,V=(e,t)=>{let n=!1;return e(t)&&(n=e(t).tokens!=null),n},H=(e=B)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>V(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(V(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}},U={accessToken:null,accessTokenPayload:null},W=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 U};function G(e,t){return e.configuration.demonstrating_proof_of_possession?(n,r,i={})=>e.generateDemonstrationOfProofOfPossessionAsync(t.accessToken,n,r,i):null}var K=(e=B)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>W(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?U:{accessToken:e.accessToken,accessTokenPayload:e.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:G(i,e)})}});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),i},q={idToken:null,idTokenPayload:null},J=e=>{let n=t.OidcClient.get,r=n(e);if(r.tokens){let e=r.tokens;return{idToken:e.idToken,idTokenPayload:e.idTokenPayload}}return q},Y=(e=B)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>J(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?q:{idToken:e.idToken,idTokenPayload:e.idTokenPayload})}});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),i},X=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=X,Object.defineProperty(e,`TokenAutomaticRenewMode`,{enumerable:!0,get:function(){return t.TokenAutomaticRenewMode}}),Object.defineProperty(e,`TokenRenewMode`,{enumerable:!0,get:function(){return t.TokenRenewMode}}),e.useOidc=H,e.useOidcAccessToken=K,e.useOidcFetch=m,e.useOidcIdToken=Y,e.useOidcUser=(e=`default`,r=!1)=>{let i=t.OidcClient.get(e).userInfo(),[a,o]=(0,n.useState)({user:i,status:i?`User loaded`:`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:`Loading user`})}),n.userInfoAsync(!e,r).then(e=>{i&&o({user:e,status:`User loaded`})}).catch(()=>o({...a,status:`Error loading user`}))}else queueMicrotask(()=>{i&&o({user:null,status:`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:`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=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.15",
|
|
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.15",
|
|
44
|
+
"@axa-fr/oidc-client-service-worker": "7.27.15"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"react": "^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
@@ -14,30 +14,30 @@ const mockRemoveEventSubscription = vi.fn(id => {
|
|
|
14
14
|
mockEventSubscribers = mockEventSubscribers.filter(e => e.id !== id);
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
+
const mockOidcInstance: {
|
|
18
|
+
subscribeEvents: typeof mockSubscribeEvents;
|
|
19
|
+
removeEventSubscription: typeof mockRemoveEventSubscription;
|
|
20
|
+
publishEvent: typeof mockPublishEvent;
|
|
21
|
+
configuration: Record<string, string>;
|
|
22
|
+
tryKeepExistingSessionAsync: ReturnType<typeof vi.fn>;
|
|
23
|
+
tokens: unknown;
|
|
24
|
+
} = {
|
|
25
|
+
subscribeEvents: mockSubscribeEvents,
|
|
26
|
+
removeEventSubscription: mockRemoveEventSubscription,
|
|
27
|
+
publishEvent: mockPublishEvent,
|
|
28
|
+
configuration: {
|
|
29
|
+
redirect_uri: 'http://localhost/callback',
|
|
30
|
+
silent_redirect_uri: 'http://localhost/silent-callback',
|
|
31
|
+
silent_login_uri: 'http://localhost/silent-login',
|
|
32
|
+
},
|
|
33
|
+
tryKeepExistingSessionAsync: vi.fn().mockResolvedValue(true),
|
|
34
|
+
tokens: null,
|
|
35
|
+
};
|
|
36
|
+
|
|
17
37
|
vi.mock('@axa-fr/oidc-client', () => ({
|
|
18
38
|
OidcClient: {
|
|
19
|
-
getOrCreate: vi.fn(() => () =>
|
|
20
|
-
|
|
21
|
-
removeEventSubscription: mockRemoveEventSubscription,
|
|
22
|
-
publishEvent: mockPublishEvent,
|
|
23
|
-
configuration: {
|
|
24
|
-
redirect_uri: 'http://localhost/callback',
|
|
25
|
-
silent_redirect_uri: 'http://localhost/silent-callback',
|
|
26
|
-
silent_login_uri: 'http://localhost/silent-login',
|
|
27
|
-
},
|
|
28
|
-
tryKeepExistingSessionAsync: vi.fn().mockResolvedValue(true),
|
|
29
|
-
})),
|
|
30
|
-
get: vi.fn(() => ({
|
|
31
|
-
subscribeEvents: mockSubscribeEvents,
|
|
32
|
-
removeEventSubscription: mockRemoveEventSubscription,
|
|
33
|
-
publishEvent: mockPublishEvent,
|
|
34
|
-
configuration: {
|
|
35
|
-
redirect_uri: 'http://localhost/callback',
|
|
36
|
-
silent_redirect_uri: 'http://localhost/silent-callback',
|
|
37
|
-
silent_login_uri: 'http://localhost/silent-login',
|
|
38
|
-
},
|
|
39
|
-
tryKeepExistingSessionAsync: vi.fn().mockResolvedValue(true),
|
|
40
|
-
})),
|
|
39
|
+
getOrCreate: vi.fn(() => () => mockOidcInstance),
|
|
40
|
+
get: vi.fn(() => mockOidcInstance),
|
|
41
41
|
eventNames: {
|
|
42
42
|
service_worker_not_supported_by_browser: 'service_worker_not_supported_by_browser',
|
|
43
43
|
token_acquired: 'token_acquired',
|
|
@@ -97,6 +97,7 @@ describe('OidcProvider loading timeout', () => {
|
|
|
97
97
|
vi.useFakeTimers();
|
|
98
98
|
vi.clearAllMocks();
|
|
99
99
|
mockEventSubscribers = [];
|
|
100
|
+
mockOidcInstance.tokens = null;
|
|
100
101
|
});
|
|
101
102
|
|
|
102
103
|
afterEach(() => {
|
|
@@ -257,6 +258,126 @@ describe('OidcProvider loading timeout', () => {
|
|
|
257
258
|
expect(mockPublishEvent).toHaveBeenCalledWith('loadingTimeout_error', { timeoutMs: 30_000 });
|
|
258
259
|
});
|
|
259
260
|
|
|
261
|
+
it('should NOT fire loadingTimeout_error after a silent session restore when authenticated', async () => {
|
|
262
|
+
render(
|
|
263
|
+
<OidcProvider
|
|
264
|
+
configuration={{ ...baseConfiguration, loading_timeout_ms: 500 }}
|
|
265
|
+
configurationName="default"
|
|
266
|
+
>
|
|
267
|
+
<div>App</div>
|
|
268
|
+
</OidcProvider>,
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
act(() => {
|
|
272
|
+
vi.advanceTimersByTime(100);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
// Simulate a successful silent session restore (no loginCallbackAsync_end is emitted).
|
|
276
|
+
act(() => {
|
|
277
|
+
mockEventSubscribers.forEach(sub =>
|
|
278
|
+
sub.func('tryKeepExistingSessionAsync_end', { success: true }),
|
|
279
|
+
);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
mockPublishEvent.mockClear();
|
|
283
|
+
|
|
284
|
+
act(() => {
|
|
285
|
+
vi.advanceTimersByTime(10_000);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
expect(mockPublishEvent).not.toHaveBeenCalledWith('loadingTimeout_error', expect.anything());
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it('should still fire loadingTimeout_error when silent session restore reports no existing session', async () => {
|
|
292
|
+
render(
|
|
293
|
+
<OidcProvider
|
|
294
|
+
configuration={{ ...baseConfiguration, loading_timeout_ms: 300 }}
|
|
295
|
+
configurationName="default"
|
|
296
|
+
>
|
|
297
|
+
<div>App</div>
|
|
298
|
+
</OidcProvider>,
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
act(() => {
|
|
302
|
+
mockEventSubscribers.forEach(sub =>
|
|
303
|
+
sub.func('tryKeepExistingSessionAsync_end', { success: false }),
|
|
304
|
+
);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
mockPublishEvent.mockClear();
|
|
308
|
+
|
|
309
|
+
act(() => {
|
|
310
|
+
vi.advanceTimersByTime(300);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
expect(mockPublishEvent).toHaveBeenCalledWith('loadingTimeout_error', { timeoutMs: 300 });
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it('should NOT fire loadingTimeout_error when token_acquired fires before the deadline', async () => {
|
|
317
|
+
render(
|
|
318
|
+
<OidcProvider
|
|
319
|
+
configuration={{ ...baseConfiguration, loading_timeout_ms: 400 }}
|
|
320
|
+
configurationName="default"
|
|
321
|
+
>
|
|
322
|
+
<div>App</div>
|
|
323
|
+
</OidcProvider>,
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
act(() => {
|
|
327
|
+
mockEventSubscribers.forEach(sub => sub.func('token_acquired', {}));
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
mockPublishEvent.mockClear();
|
|
331
|
+
|
|
332
|
+
act(() => {
|
|
333
|
+
vi.advanceTimersByTime(10_000);
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
expect(mockPublishEvent).not.toHaveBeenCalledWith('loadingTimeout_error', expect.anything());
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it('should NOT fire loadingTimeout_error when token_renewed fires before the deadline', async () => {
|
|
340
|
+
render(
|
|
341
|
+
<OidcProvider
|
|
342
|
+
configuration={{ ...baseConfiguration, loading_timeout_ms: 400 }}
|
|
343
|
+
configurationName="default"
|
|
344
|
+
>
|
|
345
|
+
<div>App</div>
|
|
346
|
+
</OidcProvider>,
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
act(() => {
|
|
350
|
+
mockEventSubscribers.forEach(sub => sub.func('token_renewed', {}));
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
mockPublishEvent.mockClear();
|
|
354
|
+
|
|
355
|
+
act(() => {
|
|
356
|
+
vi.advanceTimersByTime(10_000);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
expect(mockPublishEvent).not.toHaveBeenCalledWith('loadingTimeout_error', expect.anything());
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it('should NOT arm the watchdog when the OIDC client mounts already authenticated', async () => {
|
|
363
|
+
mockOidcInstance.tokens = { accessToken: 'existing-token' };
|
|
364
|
+
|
|
365
|
+
render(
|
|
366
|
+
<OidcProvider
|
|
367
|
+
configuration={{ ...baseConfiguration, loading_timeout_ms: 100 }}
|
|
368
|
+
configurationName="default"
|
|
369
|
+
>
|
|
370
|
+
<div>App</div>
|
|
371
|
+
</OidcProvider>,
|
|
372
|
+
);
|
|
373
|
+
|
|
374
|
+
act(() => {
|
|
375
|
+
vi.advanceTimersByTime(60_000);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
expect(mockPublishEvent).not.toHaveBeenCalledWith('loadingTimeout_error', expect.anything());
|
|
379
|
+
});
|
|
380
|
+
|
|
260
381
|
it('should propagate loadingTimeout_error through onEvent callback', async () => {
|
|
261
382
|
const onEvent = vi.fn();
|
|
262
383
|
|
package/src/OidcProvider.tsx
CHANGED
|
@@ -89,6 +89,30 @@ const Switch = ({ isLoading, loadingComponent, children, configurationName }) =>
|
|
|
89
89
|
|
|
90
90
|
const DEFAULT_LOADING_TIMEOUT_MS = 30_000;
|
|
91
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Returns true when an event signals that the OIDC client has reached an
|
|
94
|
+
* authenticated, idle state and the loading watchdog should be disarmed.
|
|
95
|
+
*
|
|
96
|
+
* The default `event.name === ''` state in {@link OidcProvider} is overloaded:
|
|
97
|
+
* it represents both "not started yet" and "done and idle". A silent session
|
|
98
|
+
* restore via `tryKeepExistingSessionAsync` does not emit
|
|
99
|
+
* `loginCallbackAsync_end`, so without these explicit ready signals the
|
|
100
|
+
* watchdog would fire against a fully authenticated app.
|
|
101
|
+
*/
|
|
102
|
+
const isReadySignal = (name: string, data: unknown): boolean => {
|
|
103
|
+
if (
|
|
104
|
+
name === OidcClient.eventNames.token_acquired ||
|
|
105
|
+
name === OidcClient.eventNames.token_renewed ||
|
|
106
|
+
name === OidcClient.eventNames.loginCallbackAsync_end
|
|
107
|
+
) {
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
if (name === OidcClient.eventNames.tryKeepExistingSessionAsync_end) {
|
|
111
|
+
return (data as { success?: boolean } | null)?.success === true;
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
};
|
|
115
|
+
|
|
92
116
|
export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
|
|
93
117
|
children,
|
|
94
118
|
configuration,
|
|
@@ -124,6 +148,7 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
|
|
|
124
148
|
|
|
125
149
|
const loading = false;
|
|
126
150
|
const [event, setEvent] = useState(defaultEventState);
|
|
151
|
+
const [isAuthenticatedAndIdle, setIsAuthenticatedAndIdle] = useState<boolean>(false);
|
|
127
152
|
const [currentConfigurationName, setConfigurationName] = useState(configurationName);
|
|
128
153
|
|
|
129
154
|
useEffect(() => {
|
|
@@ -142,6 +167,9 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
|
|
|
142
167
|
useEffect(() => {
|
|
143
168
|
const oidc = getOidc(configurationName);
|
|
144
169
|
const newSubscriptionId = oidc.subscribeEvents((name, data) => {
|
|
170
|
+
if (isReadySignal(name, data)) {
|
|
171
|
+
setIsAuthenticatedAndIdle(true);
|
|
172
|
+
}
|
|
145
173
|
if (
|
|
146
174
|
name === OidcClient.eventNames.refreshTokensAsync_error ||
|
|
147
175
|
name === OidcClient.eventNames.syncTokensAsync_error
|
|
@@ -187,6 +215,7 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
|
|
|
187
215
|
const previousOidc = getOidc(configurationName);
|
|
188
216
|
previousOidc.removeEventSubscription(newSubscriptionId);
|
|
189
217
|
setEvent(defaultEventState);
|
|
218
|
+
setIsAuthenticatedAndIdle(false);
|
|
190
219
|
};
|
|
191
220
|
}, [configuration, configurationName]);
|
|
192
221
|
|
|
@@ -195,16 +224,24 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
|
|
|
195
224
|
if (timeoutMs <= 0) {
|
|
196
225
|
return;
|
|
197
226
|
}
|
|
227
|
+
if (isAuthenticatedAndIdle) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const oidcInstance = getOidc(configurationName);
|
|
231
|
+
if (oidcInstance?.tokens != null) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
198
234
|
const isStuck = event.name === '' || event.name === OidcClient.eventNames.loginAsync_begin;
|
|
199
235
|
if (!isStuck) {
|
|
200
236
|
return;
|
|
201
237
|
}
|
|
202
238
|
const timeoutId = setTimeout(() => {
|
|
203
|
-
|
|
204
|
-
|
|
239
|
+
getOidc(configurationName).publishEvent(OidcClient.eventNames.loadingTimeout_error, {
|
|
240
|
+
timeoutMs,
|
|
241
|
+
});
|
|
205
242
|
}, timeoutMs);
|
|
206
243
|
return () => clearTimeout(timeoutId);
|
|
207
|
-
}, [event.name, configurationName, configuration]);
|
|
244
|
+
}, [event.name, isAuthenticatedAndIdle, configurationName, configuration]);
|
|
208
245
|
|
|
209
246
|
const SessionLostComponent = sessionLostComponent;
|
|
210
247
|
const AuthenticatingComponent = authenticatingComponent;
|