@axa-fr/react-oidc 7.27.12 → 7.27.13
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 +1 -0
- package/dist/OidcProvider.d.ts.map +1 -1
- package/dist/core/default-component/LoadingTimeout.component.d.ts +4 -0
- package/dist/core/default-component/LoadingTimeout.component.d.ts.map +1 -0
- package/dist/core/default-component/index.d.ts +1 -0
- package/dist/core/default-component/index.d.ts.map +1 -1
- package/dist/index.js +108 -79
- package/dist/index.umd.cjs +1 -1
- package/package.json +3 -3
- package/src/OidcProvider.spec.tsx +279 -0
- package/src/OidcProvider.tsx +34 -0
- package/src/core/default-component/LoadingTimeout.component.tsx +14 -0
- package/src/core/default-component/index.ts +1 -0
package/dist/OidcProvider.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export type OidcProviderProps = {
|
|
|
10
10
|
authenticatingComponent?: ComponentType<any>;
|
|
11
11
|
authenticatingErrorComponent?: ComponentType<any>;
|
|
12
12
|
loadingComponent?: ComponentType<any>;
|
|
13
|
+
loadingTimeoutComponent?: ComponentType<any>;
|
|
13
14
|
serviceWorkerNotSupportedComponent?: ComponentType<any>;
|
|
14
15
|
configurationName?: string;
|
|
15
16
|
configuration?: OidcConfiguration;
|
|
@@ -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;
|
|
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,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;AAuCF,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CA6MjE,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LoadingTimeout.component.d.ts","sourceRoot":"","sources":["../../../src/core/default-component/LoadingTimeout.component.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,QAAA,MAAM,cAAc,EAAE,aAAa,CAAC,GAAG,CAStC,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -2,6 +2,7 @@ export { default as AuthenticateError } from './AuthenticateError.component.js';
|
|
|
2
2
|
export { default as Authenticating } from './Authenticating.component.js';
|
|
3
3
|
export { default as Callback, CallBackSuccess } from './Callback.component.js';
|
|
4
4
|
export { default as Loading } from './Loading.component.js';
|
|
5
|
+
export { default as LoadingTimeout } from './LoadingTimeout.component.js';
|
|
5
6
|
export { default as ServiceWorkerNotSupported } from './ServiceWorkerNotSupported.component.js';
|
|
6
7
|
export { default as SessionLost } from './SessionLost.component.js';
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/default-component/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAChF,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/E,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,MAAM,0CAA0C,CAAC;AAChG,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,4BAA4B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/default-component/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAChF,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/E,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,MAAM,0CAA0C,CAAC;AAChG,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,4BAA4B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -85,6 +85,18 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
85
85
|
className: "oidc-loading",
|
|
86
86
|
children: "Loading"
|
|
87
87
|
}), A = () => /* @__PURE__ */ h("div", {
|
|
88
|
+
className: "oidc-loading-timeout",
|
|
89
|
+
children: /* @__PURE__ */ g("div", {
|
|
90
|
+
className: "oidc-loading-timeout__container",
|
|
91
|
+
children: [/* @__PURE__ */ h("h1", {
|
|
92
|
+
className: "oidc-loading-timeout__title",
|
|
93
|
+
children: "Loading timeout"
|
|
94
|
+
}), /* @__PURE__ */ h("p", {
|
|
95
|
+
className: "oidc-loading-timeout__content",
|
|
96
|
+
children: "Authentication is taking longer than expected. Please try refreshing the page."
|
|
97
|
+
})]
|
|
98
|
+
})
|
|
99
|
+
}), j = () => /* @__PURE__ */ h("div", {
|
|
88
100
|
className: "oidc-serviceworker",
|
|
89
101
|
children: /* @__PURE__ */ g("div", {
|
|
90
102
|
className: "oidc-serviceworker__container",
|
|
@@ -96,7 +108,7 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
96
108
|
children: "Your browser is not secure enough to make authentication work. Try updating your browser or use a newer browser."
|
|
97
109
|
})]
|
|
98
110
|
})
|
|
99
|
-
}),
|
|
111
|
+
}), M = () => /* @__PURE__ */ h("div", {
|
|
100
112
|
className: "oidc-session-lost",
|
|
101
113
|
children: /* @__PURE__ */ g("div", {
|
|
102
114
|
className: "oidc-session-lost__container",
|
|
@@ -108,27 +120,27 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
108
120
|
children: "Your session has expired. Please re-authenticate."
|
|
109
121
|
})]
|
|
110
122
|
})
|
|
111
|
-
}),
|
|
123
|
+
}), N = ({ configurationName: e }) => (d(() => {
|
|
112
124
|
(async () => {
|
|
113
125
|
t.get(e).silentLoginCallbackAsync();
|
|
114
126
|
})().catch((e) => {
|
|
115
127
|
console.error("Error during silent login callback:", e);
|
|
116
128
|
});
|
|
117
|
-
}, [e]), null),
|
|
129
|
+
}, [e]), null), P = ({ configurationName: e }) => {
|
|
118
130
|
let n = s(window.location.href), r = t.get, i = r(e), a = null;
|
|
119
131
|
for (let [e, t] of Object.entries(n)) e === "state" || e === "scope" || (a === null && (a = {}), a[e] = t);
|
|
120
132
|
return d(() => {
|
|
121
133
|
i.tokens || i.loginAsync(null, a, !0, n.scope);
|
|
122
134
|
}, []), /* @__PURE__ */ h(m, {});
|
|
123
|
-
},
|
|
135
|
+
}, F = 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
136
|
let [l, u] = p(window ? c(window.location.href) : "");
|
|
125
137
|
d(() => {
|
|
126
138
|
let e = () => u(c(window.location.href));
|
|
127
139
|
return e(), window.addEventListener("popstate", e, !1), () => window.removeEventListener("popstate", e, !1);
|
|
128
140
|
}, []);
|
|
129
141
|
let f = c(n);
|
|
130
|
-
if (r && l === c(r)) return /* @__PURE__ */ h(
|
|
131
|
-
if (i && l === c(i)) return /* @__PURE__ */ h(
|
|
142
|
+
if (r && l === c(r)) return /* @__PURE__ */ h(N, { configurationName: o });
|
|
143
|
+
if (i && l === c(i)) return /* @__PURE__ */ h(P, { configurationName: o });
|
|
132
144
|
switch (l) {
|
|
133
145
|
case f: return /* @__PURE__ */ h(O, {
|
|
134
146
|
callBackError: e,
|
|
@@ -138,10 +150,10 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
138
150
|
});
|
|
139
151
|
default: return /* @__PURE__ */ h(m, { children: a });
|
|
140
152
|
}
|
|
141
|
-
}),
|
|
153
|
+
}), I = {
|
|
142
154
|
name: "",
|
|
143
155
|
data: null
|
|
144
|
-
},
|
|
156
|
+
}, L = ({ loadingComponent: e, children: n, configurationName: r }) => {
|
|
145
157
|
let [i, a] = p(!0), o = t.get, s = o(r);
|
|
146
158
|
return d(() => {
|
|
147
159
|
let e = !0;
|
|
@@ -151,102 +163,119 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
151
163
|
e = !1;
|
|
152
164
|
};
|
|
153
165
|
}, [r]), /* @__PURE__ */ h(m, { children: i ? /* @__PURE__ */ h(e, { configurationName: r }) : /* @__PURE__ */ h(m, { children: n }) });
|
|
154
|
-
},
|
|
166
|
+
}, R = ({ isLoading: e, loadingComponent: t, children: n, configurationName: r }) => e ? /* @__PURE__ */ h(t, {
|
|
155
167
|
configurationName: r,
|
|
156
168
|
children: n
|
|
157
|
-
}) : /* @__PURE__ */ h(m, { children: n }),
|
|
169
|
+
}) : /* @__PURE__ */ h(m, { children: n }), z = 3e4, B = ({ children: e, configuration: n, configurationName: i = "default", callbackSuccessComponent: a = D, authenticatingComponent: s = S, loadingComponent: c = k, loadingTimeoutComponent: l = A, serviceWorkerNotSupportedComponent: u = j, authenticatingErrorComponent: f = x, sessionLostComponent: m = M, onSessionLost: g = null, onLogoutFromAnotherTab: _ = null, onLogoutFromSameTab: v = null, withCustomHistory: y = null, onEvent: b = null, getFetch: C = null, location: w = null }) => {
|
|
158
170
|
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
|
|
171
|
+
let T = (e = "default") => t.getOrCreate(C ?? o, w ?? new r())(n, e), [E, O] = p(I), [N, P] = p(i);
|
|
160
172
|
d(() => {
|
|
161
|
-
let e =
|
|
162
|
-
|
|
173
|
+
let e = T(i).subscribeEvents((e, t) => {
|
|
174
|
+
b && b(i, e, t);
|
|
163
175
|
});
|
|
164
176
|
return () => {
|
|
165
|
-
|
|
177
|
+
T(i).removeEventSubscription(e);
|
|
166
178
|
};
|
|
167
|
-
}, [i,
|
|
168
|
-
let e =
|
|
179
|
+
}, [i, b]), d(() => {
|
|
180
|
+
let e = T(i).subscribeEvents((e, r) => {
|
|
169
181
|
if (e === t.eventNames.refreshTokensAsync_error || e === t.eventNames.syncTokensAsync_error) {
|
|
170
|
-
if (
|
|
171
|
-
|
|
182
|
+
if (g != null) {
|
|
183
|
+
g();
|
|
172
184
|
return;
|
|
173
185
|
}
|
|
174
|
-
|
|
186
|
+
O({
|
|
175
187
|
name: e,
|
|
176
188
|
data: r
|
|
177
189
|
});
|
|
178
190
|
} else if (e === t.eventNames.logout_from_another_tab) {
|
|
179
|
-
if (
|
|
180
|
-
|
|
191
|
+
if (_ != null) {
|
|
192
|
+
_();
|
|
181
193
|
return;
|
|
182
194
|
}
|
|
183
|
-
|
|
195
|
+
O({
|
|
184
196
|
name: e,
|
|
185
197
|
data: r
|
|
186
198
|
});
|
|
187
|
-
} else e === t.eventNames.logout_from_same_tab ?
|
|
199
|
+
} else e === t.eventNames.logout_from_same_tab ? v?.() : (e === t.eventNames.loadingTimeout_error || e === t.eventNames.loginAsync_begin || e === t.eventNames.loginCallbackAsync_end || e === t.eventNames.loginAsync_error || e === t.eventNames.loginCallbackAsync_error || e === t.eventNames.service_worker_not_supported_by_browser && n.service_worker_only === !0) && O({
|
|
188
200
|
name: e,
|
|
189
201
|
data: r
|
|
190
202
|
});
|
|
191
203
|
});
|
|
192
204
|
return queueMicrotask(() => {
|
|
193
|
-
|
|
205
|
+
P(i);
|
|
194
206
|
}), () => {
|
|
195
|
-
|
|
207
|
+
T(i).removeEventSubscription(e), O(I);
|
|
196
208
|
};
|
|
197
|
-
}, [n, i])
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
209
|
+
}, [n, i]), d(() => {
|
|
210
|
+
let e = n?.loading_timeout_ms ?? z;
|
|
211
|
+
if (e <= 0 || !(E.name === "" || E.name === t.eventNames.loginAsync_begin)) return;
|
|
212
|
+
let r = setTimeout(() => {
|
|
213
|
+
T(i).publishEvent(t.eventNames.loadingTimeout_error, { timeoutMs: e });
|
|
214
|
+
}, e);
|
|
215
|
+
return () => clearTimeout(r);
|
|
216
|
+
}, [
|
|
217
|
+
E.name,
|
|
218
|
+
i,
|
|
219
|
+
n
|
|
220
|
+
]);
|
|
221
|
+
let B = m, V = s, H = c, U = l, W = u, G = f, K = N !== i, q = T(i);
|
|
222
|
+
switch (E.name) {
|
|
223
|
+
case t.eventNames.service_worker_not_supported_by_browser: return /* @__PURE__ */ h(R, {
|
|
224
|
+
loadingComponent: H,
|
|
225
|
+
isLoading: K,
|
|
203
226
|
configurationName: i,
|
|
204
|
-
children: /* @__PURE__ */ h(
|
|
227
|
+
children: /* @__PURE__ */ h(W, { configurationName: i })
|
|
205
228
|
});
|
|
206
|
-
case t.eventNames.loginAsync_begin: return /* @__PURE__ */ h(
|
|
207
|
-
loadingComponent:
|
|
208
|
-
isLoading:
|
|
229
|
+
case t.eventNames.loginAsync_begin: return /* @__PURE__ */ h(R, {
|
|
230
|
+
loadingComponent: H,
|
|
231
|
+
isLoading: K,
|
|
209
232
|
configurationName: i,
|
|
210
|
-
children: /* @__PURE__ */ h(
|
|
233
|
+
children: /* @__PURE__ */ h(V, { configurationName: i })
|
|
234
|
+
});
|
|
235
|
+
case t.eventNames.loadingTimeout_error: return /* @__PURE__ */ h(R, {
|
|
236
|
+
loadingComponent: H,
|
|
237
|
+
isLoading: K,
|
|
238
|
+
configurationName: i,
|
|
239
|
+
children: /* @__PURE__ */ h(U, { configurationName: i })
|
|
211
240
|
});
|
|
212
241
|
case t.eventNames.loginAsync_error:
|
|
213
|
-
case t.eventNames.loginCallbackAsync_error: return /* @__PURE__ */ h(
|
|
214
|
-
loadingComponent:
|
|
215
|
-
isLoading:
|
|
242
|
+
case t.eventNames.loginCallbackAsync_error: return /* @__PURE__ */ h(R, {
|
|
243
|
+
loadingComponent: H,
|
|
244
|
+
isLoading: K,
|
|
216
245
|
configurationName: i,
|
|
217
|
-
children: /* @__PURE__ */ h(
|
|
246
|
+
children: /* @__PURE__ */ h(G, { configurationName: i })
|
|
218
247
|
});
|
|
219
248
|
case t.eventNames.refreshTokensAsync_error:
|
|
220
249
|
case t.eventNames.syncTokensAsync_error:
|
|
221
|
-
case t.eventNames.logout_from_another_tab: return /* @__PURE__ */ h(
|
|
222
|
-
loadingComponent:
|
|
223
|
-
isLoading:
|
|
250
|
+
case t.eventNames.logout_from_another_tab: return /* @__PURE__ */ h(R, {
|
|
251
|
+
loadingComponent: H,
|
|
252
|
+
isLoading: K,
|
|
224
253
|
configurationName: i,
|
|
225
|
-
children: /* @__PURE__ */ h(
|
|
254
|
+
children: /* @__PURE__ */ h(B, { configurationName: i })
|
|
226
255
|
});
|
|
227
|
-
default: return /* @__PURE__ */ h(
|
|
228
|
-
loadingComponent:
|
|
229
|
-
isLoading:
|
|
256
|
+
default: return /* @__PURE__ */ h(R, {
|
|
257
|
+
loadingComponent: H,
|
|
258
|
+
isLoading: K,
|
|
230
259
|
configurationName: i,
|
|
231
|
-
children: /* @__PURE__ */ h(
|
|
232
|
-
redirect_uri:
|
|
233
|
-
silent_redirect_uri:
|
|
234
|
-
silent_login_uri:
|
|
260
|
+
children: /* @__PURE__ */ h(F, {
|
|
261
|
+
redirect_uri: q.configuration.redirect_uri,
|
|
262
|
+
silent_redirect_uri: q.configuration.silent_redirect_uri,
|
|
263
|
+
silent_login_uri: q.configuration.silent_login_uri,
|
|
235
264
|
callbackSuccessComponent: a,
|
|
236
|
-
callbackErrorComponent:
|
|
265
|
+
callbackErrorComponent: f,
|
|
237
266
|
authenticatingComponent: s,
|
|
238
267
|
configurationName: i,
|
|
239
|
-
withCustomHistory:
|
|
240
|
-
location:
|
|
241
|
-
children: /* @__PURE__ */ h(
|
|
242
|
-
loadingComponent:
|
|
268
|
+
withCustomHistory: y,
|
|
269
|
+
location: w ?? new r(),
|
|
270
|
+
children: /* @__PURE__ */ h(L, {
|
|
271
|
+
loadingComponent: H,
|
|
243
272
|
configurationName: i,
|
|
244
273
|
children: e
|
|
245
274
|
})
|
|
246
275
|
})
|
|
247
276
|
});
|
|
248
277
|
}
|
|
249
|
-
},
|
|
278
|
+
}, V = ({ children: e, callbackPath: n = null, extras: r = null, configurationName: i = "default" }) => {
|
|
250
279
|
let a = t.get, o = a(i);
|
|
251
280
|
return d(() => {
|
|
252
281
|
o.tokens || o.loginAsync(n, r);
|
|
@@ -255,19 +284,19 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
255
284
|
n,
|
|
256
285
|
r
|
|
257
286
|
]), o.tokens ? /* @__PURE__ */ h(m, { children: e }) : null;
|
|
258
|
-
},
|
|
287
|
+
}, H = (e, t = null, n = null, r = "default") => (i) => /* @__PURE__ */ h(V, {
|
|
259
288
|
callbackPath: t,
|
|
260
289
|
extras: n,
|
|
261
290
|
configurationName: r,
|
|
262
291
|
children: /* @__PURE__ */ h(e, { ...i })
|
|
263
|
-
}),
|
|
292
|
+
}), U = "default", W = (e, t) => {
|
|
264
293
|
let n = !1;
|
|
265
294
|
return e(t) && (n = e(t).tokens != null), n;
|
|
266
|
-
},
|
|
267
|
-
let n = t.get, [r, i] = p(() =>
|
|
295
|
+
}, G = (e = U) => {
|
|
296
|
+
let n = t.get, [r, i] = p(() => W(n, e));
|
|
268
297
|
return d(() => {
|
|
269
298
|
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(
|
|
299
|
+
(a === t.eventNames.logout_from_another_tab || a === t.eventNames.logout_from_same_tab || a === t.eventNames.token_acquired) && r && i(W(n, e));
|
|
271
300
|
});
|
|
272
301
|
return () => {
|
|
273
302
|
r = !1, a.removeEventSubscription(o);
|
|
@@ -286,10 +315,10 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
286
315
|
},
|
|
287
316
|
isAuthenticated: r
|
|
288
317
|
};
|
|
289
|
-
},
|
|
318
|
+
}, K = {
|
|
290
319
|
accessToken: null,
|
|
291
320
|
accessTokenPayload: null
|
|
292
|
-
},
|
|
321
|
+
}, q = (e) => {
|
|
293
322
|
let n = t.get, r = n(e);
|
|
294
323
|
if (r.tokens) {
|
|
295
324
|
let e = r.tokens;
|
|
@@ -299,21 +328,21 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
299
328
|
generateDemonstrationOfProofOfPossessionAsync: r.configuration.demonstrating_proof_of_possession ? (t, n) => r.generateDemonstrationOfProofOfPossessionAsync(e.accessToken, t, n) : null
|
|
300
329
|
};
|
|
301
330
|
}
|
|
302
|
-
return
|
|
331
|
+
return K;
|
|
303
332
|
};
|
|
304
|
-
function
|
|
333
|
+
function J(e, t) {
|
|
305
334
|
return e.configuration.demonstrating_proof_of_possession ? (n, r, i = {}) => e.generateDemonstrationOfProofOfPossessionAsync(t.accessToken, n, r, i) : null;
|
|
306
335
|
}
|
|
307
|
-
var
|
|
308
|
-
let n = t.get, [r, i] = p(() =>
|
|
336
|
+
var Y = (e = U) => {
|
|
337
|
+
let n = t.get, [r, i] = p(() => q(e));
|
|
309
338
|
return d(() => {
|
|
310
339
|
let r = !0, a = n(e), o = a.subscribeEvents((e, n) => {
|
|
311
340
|
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
341
|
let e = a.tokens;
|
|
313
|
-
i(e == null ?
|
|
342
|
+
i(e == null ? K : {
|
|
314
343
|
accessToken: e.accessToken,
|
|
315
344
|
accessTokenPayload: e.accessTokenPayload,
|
|
316
|
-
generateDemonstrationOfProofOfPossessionAsync:
|
|
345
|
+
generateDemonstrationOfProofOfPossessionAsync: J(a, e)
|
|
317
346
|
});
|
|
318
347
|
}
|
|
319
348
|
});
|
|
@@ -321,10 +350,10 @@ var q = (e = V) => {
|
|
|
321
350
|
r = !1, a.removeEventSubscription(o);
|
|
322
351
|
};
|
|
323
352
|
}, [e]), r;
|
|
324
|
-
},
|
|
353
|
+
}, X = {
|
|
325
354
|
idToken: null,
|
|
326
355
|
idTokenPayload: null
|
|
327
|
-
},
|
|
356
|
+
}, Z = (e) => {
|
|
328
357
|
let n = t.get, r = n(e);
|
|
329
358
|
if (r.tokens) {
|
|
330
359
|
let e = r.tokens;
|
|
@@ -333,14 +362,14 @@ var q = (e = V) => {
|
|
|
333
362
|
idTokenPayload: e.idTokenPayload
|
|
334
363
|
};
|
|
335
364
|
}
|
|
336
|
-
return
|
|
337
|
-
},
|
|
338
|
-
let n = t.get, [r, i] = p(() =>
|
|
365
|
+
return X;
|
|
366
|
+
}, Q = (e = U) => {
|
|
367
|
+
let n = t.get, [r, i] = p(() => Z(e));
|
|
339
368
|
return d(() => {
|
|
340
369
|
let r = !0, a = n(e), o = a.subscribeEvents((e, n) => {
|
|
341
370
|
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
371
|
let e = a.tokens;
|
|
343
|
-
i(e == null ?
|
|
372
|
+
i(e == null ? X : {
|
|
344
373
|
idToken: e.idToken,
|
|
345
374
|
idTokenPayload: e.idTokenPayload
|
|
346
375
|
});
|
|
@@ -350,9 +379,9 @@ var q = (e = V) => {
|
|
|
350
379
|
r = !1, a.removeEventSubscription(o);
|
|
351
380
|
};
|
|
352
381
|
}, [e]), r;
|
|
353
|
-
},
|
|
382
|
+
}, $ = /* @__PURE__ */ function(e) {
|
|
354
383
|
return e.Unauthenticated = "Unauthenticated", e.Loading = "Loading user", e.Loaded = "User loaded", e.LoadingError = "Error loading user", e;
|
|
355
|
-
}({}),
|
|
384
|
+
}({}), ee = (e = "default", n = !1) => {
|
|
356
385
|
let r = t.get(e).userInfo(), [i, a] = p({
|
|
357
386
|
user: r,
|
|
358
387
|
status: r ? "User loaded" : "Unauthenticated"
|
|
@@ -404,4 +433,4 @@ var q = (e = V) => {
|
|
|
404
433
|
};
|
|
405
434
|
};
|
|
406
435
|
//#endregion
|
|
407
|
-
export { e as OidcClient, n as OidcLocation,
|
|
436
|
+
export { e as OidcClient, n as OidcLocation, B as OidcProvider, V as OidcSecure, $ as OidcUserStatus, i as TokenAutomaticRenewMode, a as TokenRenewMode, G as useOidc, Y as useOidcAccessToken, b as useOidcFetch, Q as useOidcIdToken, ee as useOidcUser, y as withOidcFetch, H 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=({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?`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=P});
|
|
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-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.`})]})}),T=()=>(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.`})]})}),E=()=>(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.`})]})}),D=({configurationName:e})=>((0,n.useEffect)(()=>{(async()=>{t.OidcClient.get(e).silentLoginCallbackAsync()})().catch(e=>{console.error(`Error during silent login callback:`,e)})},[e]),null),O=({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,{})},k=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)(D,{configurationName:l});if(s&&d===(0,t.getPath)(s))return(0,r.jsx)(O,{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})}}),A={name:``,data:null},j=({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})})},M=({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})},N=3e4,P=({children:e,configuration:i,configurationName:a=`default`,callbackSuccessComponent:o=x,authenticatingComponent:s=g,loadingComponent:c=C,loadingTimeoutComponent:l=w,serviceWorkerNotSupportedComponent:u=T,authenticatingErrorComponent:d=h,sessionLostComponent:f=E,onSessionLost:p=null,onLogoutFromAnotherTab:m=null,onLogoutFromSameTab:_=null,withCustomHistory:v=null,onEvent:y=null,getFetch:b=null,location:S=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 D=(e=`default`)=>t.OidcClient.getOrCreate(b??t.getFetchDefault,S??new t.OidcLocation)(i,e),[O,P]=(0,n.useState)(A),[F,I]=(0,n.useState)(a);(0,n.useEffect)(()=>{let e=D(a).subscribeEvents((e,t)=>{y&&y(a,e,t)});return()=>{D(a).removeEventSubscription(e)}},[a,y]),(0,n.useEffect)(()=>{let e=D(a).subscribeEvents((e,n)=>{if(e===t.OidcClient.eventNames.refreshTokensAsync_error||e===t.OidcClient.eventNames.syncTokensAsync_error){if(p!=null){p();return}P({name:e,data:n})}else if(e===t.OidcClient.eventNames.logout_from_another_tab){if(m!=null){m();return}P({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)&&P({name:e,data:n})});return queueMicrotask(()=>{I(a)}),()=>{D(a).removeEventSubscription(e),P(A)}},[i,a]),(0,n.useEffect)(()=>{let e=i?.loading_timeout_ms??N;if(e<=0||!(O.name===``||O.name===t.OidcClient.eventNames.loginAsync_begin))return;let n=setTimeout(()=>{D(a).publishEvent(t.OidcClient.eventNames.loadingTimeout_error,{timeoutMs:e})},e);return()=>clearTimeout(n)},[O.name,a,i]);let L=f,R=s,z=c,B=l,V=u,H=d,U=F!==a,W=D(a);switch(O.name){case t.OidcClient.eventNames.service_worker_not_supported_by_browser:return(0,r.jsx)(M,{loadingComponent:z,isLoading:U,configurationName:a,children:(0,r.jsx)(V,{configurationName:a})});case t.OidcClient.eventNames.loginAsync_begin:return(0,r.jsx)(M,{loadingComponent:z,isLoading:U,configurationName:a,children:(0,r.jsx)(R,{configurationName:a})});case t.OidcClient.eventNames.loadingTimeout_error:return(0,r.jsx)(M,{loadingComponent:z,isLoading:U,configurationName:a,children:(0,r.jsx)(B,{configurationName:a})});case t.OidcClient.eventNames.loginAsync_error:case t.OidcClient.eventNames.loginCallbackAsync_error:return(0,r.jsx)(M,{loadingComponent:z,isLoading:U,configurationName:a,children:(0,r.jsx)(H,{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)(M,{loadingComponent:z,isLoading:U,configurationName:a,children:(0,r.jsx)(L,{configurationName:a})});default:return(0,r.jsx)(M,{loadingComponent:z,isLoading:U,configurationName:a,children:(0,r.jsx)(k,{redirect_uri:W.configuration.redirect_uri,silent_redirect_uri:W.configuration.silent_redirect_uri,silent_login_uri:W.configuration.silent_login_uri,callbackSuccessComponent:o,callbackErrorComponent:d,authenticatingComponent:s,configurationName:a,withCustomHistory:v,location:S??new t.OidcLocation,children:(0,r.jsx)(j,{loadingComponent:z,configurationName:a,children:e})})})}},F=({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},I=(e,t=null,n=null,i=`default`)=>a=>(0,r.jsx)(F,{callbackPath:t,extras:n,configurationName:i,children:(0,r.jsx)(e,{...a})}),L=`default`,R=(e,t)=>{let n=!1;return e(t)&&(n=e(t).tokens!=null),n},z=(e=L)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>R(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(R(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}},B={accessToken:null,accessTokenPayload:null},V=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 B};function H(e,t){return e.configuration.demonstrating_proof_of_possession?(n,r,i={})=>e.generateDemonstrationOfProofOfPossessionAsync(t.accessToken,n,r,i):null}var U=(e=L)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>V(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?B:{accessToken:e.accessToken,accessTokenPayload:e.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:H(i,e)})}});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),i},W={idToken:null,idTokenPayload:null},G=e=>{let n=t.OidcClient.get,r=n(e);if(r.tokens){let e=r.tokens;return{idToken:e.idToken,idTokenPayload:e.idTokenPayload}}return W},K=(e=L)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>G(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?W:{idToken:e.idToken,idTokenPayload:e.idTokenPayload})}});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),i},q=function(e){return e.Unauthenticated=`Unauthenticated`,e.Loading=`Loading user`,e.Loaded=`User loaded`,e.LoadingError=`Error loading user`,e}({});Object.defineProperty(e,`OidcClient`,{enumerable:!0,get:function(){return t.OidcClient}}),Object.defineProperty(e,`OidcLocation`,{enumerable:!0,get:function(){return t.OidcLocation}}),e.OidcProvider=P,e.OidcSecure=F,e.OidcUserStatus=q,Object.defineProperty(e,`TokenAutomaticRenewMode`,{enumerable:!0,get:function(){return t.TokenAutomaticRenewMode}}),Object.defineProperty(e,`TokenRenewMode`,{enumerable:!0,get:function(){return t.TokenRenewMode}}),e.useOidc=z,e.useOidcAccessToken=U,e.useOidcFetch=m,e.useOidcIdToken=K,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=I});
|
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.13",
|
|
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.13",
|
|
44
|
+
"@axa-fr/oidc-client-service-worker": "7.27.13"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"react": "^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { act, render, screen } from '@testing-library/react';
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
let mockEventSubscribers: Array<{ id: string; func: (name: string, data: any) => void }> = [];
|
|
5
|
+
const mockPublishEvent = vi.fn((eventName, data) => {
|
|
6
|
+
mockEventSubscribers.forEach(sub => sub.func(eventName, data));
|
|
7
|
+
});
|
|
8
|
+
const mockSubscribeEvents = vi.fn(func => {
|
|
9
|
+
const id = Math.random().toString();
|
|
10
|
+
mockEventSubscribers.push({ id, func });
|
|
11
|
+
return id;
|
|
12
|
+
});
|
|
13
|
+
const mockRemoveEventSubscription = vi.fn(id => {
|
|
14
|
+
mockEventSubscribers = mockEventSubscribers.filter(e => e.id !== id);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
vi.mock('@axa-fr/oidc-client', () => ({
|
|
18
|
+
OidcClient: {
|
|
19
|
+
getOrCreate: vi.fn(() => () => ({
|
|
20
|
+
subscribeEvents: mockSubscribeEvents,
|
|
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
|
+
})),
|
|
41
|
+
eventNames: {
|
|
42
|
+
service_worker_not_supported_by_browser: 'service_worker_not_supported_by_browser',
|
|
43
|
+
token_acquired: 'token_acquired',
|
|
44
|
+
logout_from_another_tab: 'logout_from_another_tab',
|
|
45
|
+
logout_from_same_tab: 'logout_from_same_tab',
|
|
46
|
+
token_renewed: 'token_renewed',
|
|
47
|
+
token_timer: 'token_timer',
|
|
48
|
+
loginAsync_begin: 'loginAsync_begin',
|
|
49
|
+
loginAsync_error: 'loginAsync_error',
|
|
50
|
+
loginCallbackAsync_begin: 'loginCallbackAsync_begin',
|
|
51
|
+
loginCallbackAsync_end: 'loginCallbackAsync_end',
|
|
52
|
+
loginCallbackAsync_error: 'loginCallbackAsync_error',
|
|
53
|
+
refreshTokensAsync_begin: 'refreshTokensAsync_begin',
|
|
54
|
+
refreshTokensAsync: 'refreshTokensAsync',
|
|
55
|
+
refreshTokensAsync_end: 'refreshTokensAsync_end',
|
|
56
|
+
refreshTokensAsync_error: 'refreshTokensAsync_error',
|
|
57
|
+
refreshTokensAsync_silent_error: 'refreshTokensAsync_silent_error',
|
|
58
|
+
tryKeepExistingSessionAsync_begin: 'tryKeepExistingSessionAsync_begin',
|
|
59
|
+
tryKeepExistingSessionAsync_end: 'tryKeepExistingSessionAsync_end',
|
|
60
|
+
tryKeepExistingSessionAsync_error: 'tryKeepExistingSessionAsync_error',
|
|
61
|
+
silentLoginAsync_begin: 'silentLoginAsync_begin',
|
|
62
|
+
silentLoginAsync: 'silentLoginAsync',
|
|
63
|
+
silentLoginAsync_end: 'silentLoginAsync_end',
|
|
64
|
+
silentLoginAsync_error: 'silentLoginAsync_error',
|
|
65
|
+
syncTokensAsync_begin: 'syncTokensAsync_begin',
|
|
66
|
+
syncTokensAsync_lock_not_available: 'syncTokensAsync_lock_not_available',
|
|
67
|
+
syncTokensAsync_end: 'syncTokensAsync_end',
|
|
68
|
+
syncTokensAsync_error: 'syncTokensAsync_error',
|
|
69
|
+
tokensInvalidAndWaitingActionsToRefresh: 'tokensInvalidAndWaitingActionsToRefresh',
|
|
70
|
+
loadingTimeout_error: 'loadingTimeout_error',
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
OidcLocation: class {
|
|
74
|
+
getCurrentHref() {
|
|
75
|
+
return 'http://localhost/';
|
|
76
|
+
}
|
|
77
|
+
getPath() {
|
|
78
|
+
return '/';
|
|
79
|
+
}
|
|
80
|
+
open() {}
|
|
81
|
+
reload() {}
|
|
82
|
+
getOrigin() {
|
|
83
|
+
return 'http://localhost';
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
getFetchDefault: vi.fn(() => fetch),
|
|
87
|
+
}));
|
|
88
|
+
|
|
89
|
+
vi.mock('./core/routes/OidcRoutes.js', () => ({
|
|
90
|
+
default: ({ children }: any) => <div data-testid="oidc-routes">{children}</div>,
|
|
91
|
+
}));
|
|
92
|
+
|
|
93
|
+
import { OidcProvider } from './OidcProvider';
|
|
94
|
+
|
|
95
|
+
describe('OidcProvider loading timeout', () => {
|
|
96
|
+
beforeEach(() => {
|
|
97
|
+
vi.useFakeTimers();
|
|
98
|
+
vi.clearAllMocks();
|
|
99
|
+
mockEventSubscribers = [];
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
afterEach(() => {
|
|
103
|
+
vi.useRealTimers();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const baseConfiguration = {
|
|
107
|
+
client_id: 'test-client',
|
|
108
|
+
redirect_uri: 'http://localhost/callback',
|
|
109
|
+
silent_redirect_uri: 'http://localhost/silent-callback',
|
|
110
|
+
scope: 'openid',
|
|
111
|
+
authority: 'http://localhost/authority',
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
it('should fire loadingTimeout_error when stuck in initial loading state', async () => {
|
|
115
|
+
render(
|
|
116
|
+
<OidcProvider
|
|
117
|
+
configuration={{ ...baseConfiguration, loading_timeout_ms: 100 }}
|
|
118
|
+
configurationName="default"
|
|
119
|
+
>
|
|
120
|
+
<div>App</div>
|
|
121
|
+
</OidcProvider>,
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
act(() => {
|
|
125
|
+
vi.advanceTimersByTime(100);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
expect(mockPublishEvent).toHaveBeenCalledWith('loadingTimeout_error', { timeoutMs: 100 });
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('should fire loadingTimeout_error when stuck in loginAsync_begin state', async () => {
|
|
132
|
+
render(
|
|
133
|
+
<OidcProvider
|
|
134
|
+
configuration={{ ...baseConfiguration, loading_timeout_ms: 200 }}
|
|
135
|
+
configurationName="default"
|
|
136
|
+
>
|
|
137
|
+
<div>App</div>
|
|
138
|
+
</OidcProvider>,
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
// Simulate loginAsync_begin event
|
|
142
|
+
act(() => {
|
|
143
|
+
mockEventSubscribers.forEach(sub => sub.func('loginAsync_begin', {}));
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// Reset to track timeout event specifically
|
|
147
|
+
mockPublishEvent.mockClear();
|
|
148
|
+
|
|
149
|
+
act(() => {
|
|
150
|
+
vi.advanceTimersByTime(200);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
expect(mockPublishEvent).toHaveBeenCalledWith('loadingTimeout_error', { timeoutMs: 200 });
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('should render loadingTimeoutComponent when loadingTimeout_error is triggered', async () => {
|
|
157
|
+
const CustomTimeoutComponent = () => <div data-testid="custom-timeout">Timeout!</div>;
|
|
158
|
+
|
|
159
|
+
render(
|
|
160
|
+
<OidcProvider
|
|
161
|
+
configuration={{ ...baseConfiguration, loading_timeout_ms: 50 }}
|
|
162
|
+
configurationName="default"
|
|
163
|
+
loadingTimeoutComponent={CustomTimeoutComponent}
|
|
164
|
+
>
|
|
165
|
+
<div>App</div>
|
|
166
|
+
</OidcProvider>,
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
await act(async () => {
|
|
170
|
+
vi.advanceTimersByTime(50);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
expect(screen.getByTestId('custom-timeout')).toBeTruthy();
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('should NOT fire loadingTimeout_error when loading_timeout_ms is 0 (disabled)', async () => {
|
|
177
|
+
render(
|
|
178
|
+
<OidcProvider
|
|
179
|
+
configuration={{ ...baseConfiguration, loading_timeout_ms: 0 }}
|
|
180
|
+
configurationName="default"
|
|
181
|
+
>
|
|
182
|
+
<div>App</div>
|
|
183
|
+
</OidcProvider>,
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
act(() => {
|
|
187
|
+
vi.advanceTimersByTime(60_000);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
expect(mockPublishEvent).not.toHaveBeenCalledWith('loadingTimeout_error', expect.anything());
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('should NOT fire loadingTimeout_error when loading_timeout_ms is negative (disabled)', async () => {
|
|
194
|
+
render(
|
|
195
|
+
<OidcProvider
|
|
196
|
+
configuration={{ ...baseConfiguration, loading_timeout_ms: -1 }}
|
|
197
|
+
configurationName="default"
|
|
198
|
+
>
|
|
199
|
+
<div>App</div>
|
|
200
|
+
</OidcProvider>,
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
act(() => {
|
|
204
|
+
vi.advanceTimersByTime(60_000);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
expect(mockPublishEvent).not.toHaveBeenCalledWith('loadingTimeout_error', expect.anything());
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('should NOT fire loadingTimeout_error if provider leaves loading state before deadline', async () => {
|
|
211
|
+
render(
|
|
212
|
+
<OidcProvider
|
|
213
|
+
configuration={{ ...baseConfiguration, loading_timeout_ms: 500 }}
|
|
214
|
+
configurationName="default"
|
|
215
|
+
>
|
|
216
|
+
<div>App</div>
|
|
217
|
+
</OidcProvider>,
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
// Advance partway
|
|
221
|
+
act(() => {
|
|
222
|
+
vi.advanceTimersByTime(200);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// Simulate successful callback (leaving loading state)
|
|
226
|
+
act(() => {
|
|
227
|
+
mockEventSubscribers.forEach(sub => sub.func('loginCallbackAsync_end', {}));
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
mockPublishEvent.mockClear();
|
|
231
|
+
|
|
232
|
+
// Advance past original timeout
|
|
233
|
+
act(() => {
|
|
234
|
+
vi.advanceTimersByTime(500);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
expect(mockPublishEvent).not.toHaveBeenCalledWith('loadingTimeout_error', expect.anything());
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it('should use default timeout of 30000ms when loading_timeout_ms is not configured', async () => {
|
|
241
|
+
render(
|
|
242
|
+
<OidcProvider configuration={baseConfiguration} configurationName="default">
|
|
243
|
+
<div>App</div>
|
|
244
|
+
</OidcProvider>,
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
act(() => {
|
|
248
|
+
vi.advanceTimersByTime(29_999);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
expect(mockPublishEvent).not.toHaveBeenCalledWith('loadingTimeout_error', expect.anything());
|
|
252
|
+
|
|
253
|
+
act(() => {
|
|
254
|
+
vi.advanceTimersByTime(1);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
expect(mockPublishEvent).toHaveBeenCalledWith('loadingTimeout_error', { timeoutMs: 30_000 });
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('should propagate loadingTimeout_error through onEvent callback', async () => {
|
|
261
|
+
const onEvent = vi.fn();
|
|
262
|
+
|
|
263
|
+
render(
|
|
264
|
+
<OidcProvider
|
|
265
|
+
configuration={{ ...baseConfiguration, loading_timeout_ms: 100 }}
|
|
266
|
+
configurationName="default"
|
|
267
|
+
onEvent={onEvent}
|
|
268
|
+
>
|
|
269
|
+
<div>App</div>
|
|
270
|
+
</OidcProvider>,
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
act(() => {
|
|
274
|
+
vi.advanceTimersByTime(100);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
expect(onEvent).toHaveBeenCalledWith('default', 'loadingTimeout_error', { timeoutMs: 100 });
|
|
278
|
+
});
|
|
279
|
+
});
|
package/src/OidcProvider.tsx
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
Authenticating,
|
|
14
14
|
CallBackSuccess,
|
|
15
15
|
Loading,
|
|
16
|
+
LoadingTimeout,
|
|
16
17
|
SessionLost,
|
|
17
18
|
} from './core/default-component/index.js';
|
|
18
19
|
import ServiceWorkerNotSupported from './core/default-component/ServiceWorkerNotSupported.component.js';
|
|
@@ -31,6 +32,7 @@ export type OidcProviderProps = {
|
|
|
31
32
|
authenticatingComponent?: ComponentType<any>;
|
|
32
33
|
authenticatingErrorComponent?: ComponentType<any>;
|
|
33
34
|
loadingComponent?: ComponentType<any>;
|
|
35
|
+
loadingTimeoutComponent?: ComponentType<any>;
|
|
34
36
|
serviceWorkerNotSupportedComponent?: ComponentType<any>;
|
|
35
37
|
configurationName?: string;
|
|
36
38
|
configuration?: OidcConfiguration;
|
|
@@ -84,6 +86,8 @@ const Switch = ({ isLoading, loadingComponent, children, configurationName }) =>
|
|
|
84
86
|
return <>{children}</>;
|
|
85
87
|
};
|
|
86
88
|
|
|
89
|
+
const DEFAULT_LOADING_TIMEOUT_MS = 30_000;
|
|
90
|
+
|
|
87
91
|
export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
|
|
88
92
|
children,
|
|
89
93
|
configuration,
|
|
@@ -91,6 +95,7 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
|
|
|
91
95
|
callbackSuccessComponent = CallBackSuccess,
|
|
92
96
|
authenticatingComponent = Authenticating,
|
|
93
97
|
loadingComponent = Loading,
|
|
98
|
+
loadingTimeoutComponent = LoadingTimeout,
|
|
94
99
|
serviceWorkerNotSupportedComponent = ServiceWorkerNotSupported,
|
|
95
100
|
authenticatingErrorComponent = AuthenticatingError,
|
|
96
101
|
sessionLostComponent = SessionLost,
|
|
@@ -155,6 +160,8 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
|
|
|
155
160
|
onLogoutFromSameTab();
|
|
156
161
|
}
|
|
157
162
|
// setEvent({name, data});
|
|
163
|
+
} else if (name === OidcClient.eventNames.loadingTimeout_error) {
|
|
164
|
+
setEvent({ name, data });
|
|
158
165
|
} else if (
|
|
159
166
|
name === OidcClient.eventNames.loginAsync_begin ||
|
|
160
167
|
name === OidcClient.eventNames.loginCallbackAsync_end ||
|
|
@@ -181,9 +188,26 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
|
|
|
181
188
|
};
|
|
182
189
|
}, [configuration, configurationName]);
|
|
183
190
|
|
|
191
|
+
useEffect(() => {
|
|
192
|
+
const timeoutMs = configuration?.loading_timeout_ms ?? DEFAULT_LOADING_TIMEOUT_MS;
|
|
193
|
+
if (timeoutMs <= 0) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const isStuck = event.name === '' || event.name === OidcClient.eventNames.loginAsync_begin;
|
|
197
|
+
if (!isStuck) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const timeoutId = setTimeout(() => {
|
|
201
|
+
const oidcInstance = getOidc(configurationName);
|
|
202
|
+
oidcInstance.publishEvent(OidcClient.eventNames.loadingTimeout_error, { timeoutMs });
|
|
203
|
+
}, timeoutMs);
|
|
204
|
+
return () => clearTimeout(timeoutId);
|
|
205
|
+
}, [event.name, configurationName, configuration]);
|
|
206
|
+
|
|
184
207
|
const SessionLostComponent = sessionLostComponent;
|
|
185
208
|
const AuthenticatingComponent = authenticatingComponent;
|
|
186
209
|
const LoadingComponent = loadingComponent;
|
|
210
|
+
const LoadingTimeoutComponent = loadingTimeoutComponent;
|
|
187
211
|
const ServiceWorkerNotSupportedComponent = serviceWorkerNotSupportedComponent;
|
|
188
212
|
const AuthenticatingErrorComponent = authenticatingErrorComponent;
|
|
189
213
|
|
|
@@ -211,6 +235,16 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
|
|
|
211
235
|
<AuthenticatingComponent configurationName={configurationName} />
|
|
212
236
|
</Switch>
|
|
213
237
|
);
|
|
238
|
+
case OidcClient.eventNames.loadingTimeout_error:
|
|
239
|
+
return (
|
|
240
|
+
<Switch
|
|
241
|
+
loadingComponent={LoadingComponent}
|
|
242
|
+
isLoading={isLoading}
|
|
243
|
+
configurationName={configurationName}
|
|
244
|
+
>
|
|
245
|
+
<LoadingTimeoutComponent configurationName={configurationName} />
|
|
246
|
+
</Switch>
|
|
247
|
+
);
|
|
214
248
|
case OidcClient.eventNames.loginAsync_error:
|
|
215
249
|
case OidcClient.eventNames.loginCallbackAsync_error:
|
|
216
250
|
return (
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
|
|
3
|
+
const LoadingTimeout: ComponentType<any> = () => (
|
|
4
|
+
<div className="oidc-loading-timeout">
|
|
5
|
+
<div className="oidc-loading-timeout__container">
|
|
6
|
+
<h1 className="oidc-loading-timeout__title">Loading timeout</h1>
|
|
7
|
+
<p className="oidc-loading-timeout__content">
|
|
8
|
+
Authentication is taking longer than expected. Please try refreshing the page.
|
|
9
|
+
</p>
|
|
10
|
+
</div>
|
|
11
|
+
</div>
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
export default LoadingTimeout;
|
|
@@ -2,5 +2,6 @@ export { default as AuthenticateError } from './AuthenticateError.component.js';
|
|
|
2
2
|
export { default as Authenticating } from './Authenticating.component.js';
|
|
3
3
|
export { default as Callback, CallBackSuccess } from './Callback.component.js';
|
|
4
4
|
export { default as Loading } from './Loading.component.js';
|
|
5
|
+
export { default as LoadingTimeout } from './LoadingTimeout.component.js';
|
|
5
6
|
export { default as ServiceWorkerNotSupported } from './ServiceWorkerNotSupported.component.js';
|
|
6
7
|
export { default as SessionLost } from './SessionLost.component.js';
|