@axa-fr/react-oidc 7.22.18 → 7.22.19

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.
Files changed (39) hide show
  1. package/README.md +87 -114
  2. package/bin/copy-service-worker-files.mjs +24 -17
  3. package/dist/FetchToken.d.ts.map +1 -1
  4. package/dist/OidcProvider.d.ts +1 -1
  5. package/dist/OidcProvider.d.ts.map +1 -1
  6. package/dist/OidcSecure.d.ts.map +1 -1
  7. package/dist/OidcTrustedDomains.js +13 -10
  8. package/dist/ReactOidc.d.ts.map +1 -1
  9. package/dist/User.d.ts.map +1 -1
  10. package/dist/core/default-component/Authenticating.component.d.ts.map +1 -1
  11. package/dist/core/default-component/Callback.component.d.ts.map +1 -1
  12. package/dist/core/default-component/Loading.component.d.ts.map +1 -1
  13. package/dist/core/default-component/ServiceWorkerNotSupported.component.d.ts.map +1 -1
  14. package/dist/core/default-component/SilentCallback.component.d.ts +5 -2
  15. package/dist/core/default-component/SilentCallback.component.d.ts.map +1 -1
  16. package/dist/core/routes/OidcRoutes.d.ts.map +1 -1
  17. package/dist/core/routes/withRouter.d.ts.map +1 -1
  18. package/dist/index.d.ts +2 -2
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +165 -72
  21. package/dist/index.umd.cjs +1 -1
  22. package/package.json +3 -3
  23. package/src/FetchToken.tsx +36 -13
  24. package/src/OidcProvider.tsx +222 -176
  25. package/src/OidcSecure.tsx +34 -23
  26. package/src/ReactOidc.tsx +181 -142
  27. package/src/User.ts +60 -50
  28. package/src/core/default-component/Authenticating.component.tsx +1 -1
  29. package/src/core/default-component/Callback.component.tsx +18 -11
  30. package/src/core/default-component/Loading.component.tsx +1 -5
  31. package/src/core/default-component/ServiceWorkerNotSupported.component.tsx +5 -2
  32. package/src/core/default-component/SessionLost.component.tsx +1 -1
  33. package/src/core/default-component/SilentCallback.component.tsx +17 -11
  34. package/src/core/default-component/SilentLogin.component.tsx +18 -18
  35. package/src/core/routes/OidcRoutes.spec.tsx +2 -2
  36. package/src/core/routes/OidcRoutes.tsx +12 -5
  37. package/src/core/routes/withRouter.spec.tsx +5 -6
  38. package/src/core/routes/withRouter.tsx +21 -19
  39. package/src/index.ts +8 -3
package/src/ReactOidc.tsx CHANGED
@@ -1,179 +1,218 @@
1
- import { StringMap, OidcClient, Tokens } from '@axa-fr/oidc-client';
1
+ import { OidcClient, StringMap, Tokens } from '@axa-fr/oidc-client';
2
2
  import { useEffect, useState } from 'react';
3
3
 
4
4
  const defaultConfigurationName = 'default';
5
5
 
6
6
  type GetOidcFn = {
7
- (configurationName?: string): any;
8
- }
7
+ (configurationName?: string): any;
8
+ };
9
9
 
10
10
  const defaultIsAuthenticated = (getOidc: GetOidcFn, configurationName: string) => {
11
- let isAuthenticated = false;
12
- const oidc = getOidc(configurationName);
13
- if (oidc) {
14
- isAuthenticated = getOidc(configurationName).tokens != null;
15
- }
16
- return isAuthenticated;
11
+ let isAuthenticated = false;
12
+ const oidc = getOidc(configurationName);
13
+ if (oidc) {
14
+ isAuthenticated = getOidc(configurationName).tokens != null;
15
+ }
16
+ return isAuthenticated;
17
17
  };
18
18
 
19
19
  export const useOidc = (configurationName = defaultConfigurationName) => {
20
- const getOidc = OidcClient.get;
21
- const [isAuthenticated, setIsAuthenticated] = useState<boolean>(defaultIsAuthenticated(getOidc, configurationName));
22
-
23
- useEffect(() => {
24
- let isMounted = true;
25
- const oidc = getOidc(configurationName);
26
- setIsAuthenticated(defaultIsAuthenticated(getOidc, configurationName));
27
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
28
- const newSubscriptionId = oidc.subscribeEvents((name: string, data: any) => {
29
- if (name === OidcClient.eventNames.logout_from_another_tab || name === OidcClient.eventNames.logout_from_same_tab || name === OidcClient.eventNames.token_aquired) {
30
- if (isMounted) {
31
- setIsAuthenticated(defaultIsAuthenticated(getOidc, configurationName));
32
- }
33
- }
34
- });
35
- return () => {
36
- isMounted = false;
37
- oidc.removeEventSubscription(newSubscriptionId);
38
- };
39
- // eslint-disable-next-line react-hooks/exhaustive-deps
40
- }, [configurationName]);
41
-
42
- const login = (callbackPath:string | undefined = undefined, extras:StringMap = null, silentLoginOnly = false) => {
43
- return getOidc(configurationName).loginAsync(callbackPath, extras, false, undefined, silentLoginOnly);
44
- };
45
- const logout = (callbackPath: string | null | undefined = undefined, extras:StringMap = null) => {
46
- return getOidc(configurationName).logoutAsync(callbackPath, extras);
20
+ const getOidc = OidcClient.get;
21
+ const [isAuthenticated, setIsAuthenticated] = useState<boolean>(
22
+ defaultIsAuthenticated(getOidc, configurationName),
23
+ );
24
+
25
+ useEffect(() => {
26
+ let isMounted = true;
27
+ const oidc = getOidc(configurationName);
28
+ setIsAuthenticated(defaultIsAuthenticated(getOidc, configurationName));
29
+
30
+ const newSubscriptionId = oidc.subscribeEvents((name: string, data: any) => {
31
+ if (
32
+ name === OidcClient.eventNames.logout_from_another_tab ||
33
+ name === OidcClient.eventNames.logout_from_same_tab ||
34
+ name === OidcClient.eventNames.token_aquired
35
+ ) {
36
+ if (isMounted) {
37
+ setIsAuthenticated(defaultIsAuthenticated(getOidc, configurationName));
38
+ }
39
+ }
40
+ });
41
+ return () => {
42
+ isMounted = false;
43
+ oidc.removeEventSubscription(newSubscriptionId);
47
44
  };
48
- const renewTokens = async (extras: StringMap = null) : Promise<OidcAccessToken | OidcIdToken> => {
49
- const tokens = await getOidc(configurationName).renewTokensAsync(extras);
50
-
51
- return {
52
- // @ts-ignore
53
- accessToken: tokens.accessToken,
54
- // @ts-ignore
55
- accessTokenPayload: tokens.accessTokenPayload,
56
- // @ts-ignore
57
- idToken: tokens.idToken,
58
- // @ts-ignore
59
- idTokenPayload: tokens.idTokenPayload,
60
- };
45
+ }, [configurationName]);
46
+
47
+ const login = (
48
+ callbackPath: string | undefined = undefined,
49
+ extras: StringMap = null,
50
+ silentLoginOnly = false,
51
+ ) => {
52
+ return getOidc(configurationName).loginAsync(
53
+ callbackPath,
54
+ extras,
55
+ false,
56
+ undefined,
57
+ silentLoginOnly,
58
+ );
59
+ };
60
+ const logout = (
61
+ callbackPath: string | null | undefined = undefined,
62
+ extras: StringMap = null,
63
+ ) => {
64
+ return getOidc(configurationName).logoutAsync(callbackPath, extras);
65
+ };
66
+ const renewTokens = async (extras: StringMap = null): Promise<OidcAccessToken | OidcIdToken> => {
67
+ const tokens = await getOidc(configurationName).renewTokensAsync(extras);
68
+
69
+ return {
70
+ // @ts-ignore
71
+ accessToken: tokens.accessToken,
72
+ // @ts-ignore
73
+ accessTokenPayload: tokens.accessTokenPayload,
74
+ // @ts-ignore
75
+ idToken: tokens.idToken,
76
+ // @ts-ignore
77
+ idTokenPayload: tokens.idTokenPayload,
61
78
  };
62
- return { login, logout, renewTokens, isAuthenticated };
79
+ };
80
+ return { login, logout, renewTokens, isAuthenticated };
63
81
  };
64
82
 
65
83
  const accessTokenInitialState = { accessToken: null, accessTokenPayload: null };
66
84
 
67
85
  const initTokens = (configurationName: string) => {
68
- const getOidc = OidcClient.get;
69
- const oidc = getOidc(configurationName);
70
- if (oidc.tokens) {
71
- const tokens = oidc.tokens;
72
- return {
73
- accessToken: tokens.accessToken,
74
- accessTokenPayload: tokens.accessTokenPayload,
75
- generateDemonstrationOfProofOfPossessionAsync: oidc.configuration.demonstrating_proof_of_possession ? (url:string, method:string) => oidc.generateDemonstrationOfProofOfPossessionAsync(tokens.accessToken, url, method) : null,
76
- };
77
- }
78
- return accessTokenInitialState;
86
+ const getOidc = OidcClient.get;
87
+ const oidc = getOidc(configurationName);
88
+ if (oidc.tokens) {
89
+ const tokens = oidc.tokens;
90
+ return {
91
+ accessToken: tokens.accessToken,
92
+ accessTokenPayload: tokens.accessTokenPayload,
93
+ generateDemonstrationOfProofOfPossessionAsync: oidc.configuration
94
+ .demonstrating_proof_of_possession
95
+ ? (url: string, method: string) =>
96
+ oidc.generateDemonstrationOfProofOfPossessionAsync(tokens.accessToken, url, method)
97
+ : null,
98
+ };
99
+ }
100
+ return accessTokenInitialState;
79
101
  };
80
102
 
81
103
  export type OidcAccessToken = {
82
- accessToken?: any;
83
- accessTokenPayload?: any;
84
- generateDemonstrationOfProofOfPossessionAsync?: any;
85
- }
104
+ accessToken?: any;
105
+ accessTokenPayload?: any;
106
+ generateDemonstrationOfProofOfPossessionAsync?: any;
107
+ };
86
108
 
87
109
  function getGenerateDemonstrationOfProofOfPossessionAsync(oidc: OidcClient, tokens: Tokens) {
88
- return oidc.configuration.demonstrating_proof_of_possession ? (url: string, method: string, extras:StringMap={}) => oidc.generateDemonstrationOfProofOfPossessionAsync(tokens.accessToken, url, method, extras) : null;
110
+ return oidc.configuration.demonstrating_proof_of_possession
111
+ ? (url: string, method: string, extras: StringMap = {}) =>
112
+ oidc.generateDemonstrationOfProofOfPossessionAsync(tokens.accessToken, url, method, extras)
113
+ : null;
89
114
  }
90
115
 
91
116
  export const useOidcAccessToken = (configurationName = defaultConfigurationName) => {
92
- const getOidc = OidcClient.get;
93
- const [state, setAccessToken] = useState<OidcAccessToken>(initTokens(configurationName));
94
-
95
- useEffect(() => {
96
- let isMounted = true;
97
- const oidc = getOidc(configurationName);
98
- if (oidc.tokens) {
99
- const tokens = oidc.tokens;
100
- setAccessToken({ accessToken: tokens.accessToken, accessTokenPayload: tokens.accessTokenPayload });
101
- }
102
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
103
- const newSubscriptionId = oidc.subscribeEvents((name: string, data: any) => {
104
- if (name === OidcClient.eventNames.token_renewed ||
105
- name === OidcClient.eventNames.token_aquired ||
106
- name === OidcClient.eventNames.logout_from_another_tab ||
107
- name === OidcClient.eventNames.logout_from_same_tab ||
108
- name === OidcClient.eventNames.refreshTokensAsync_error ||
109
- name === OidcClient.eventNames.syncTokensAsync_error) {
110
- if (isMounted) {
111
- const tokens = oidc.tokens;
112
- setAccessToken(tokens != null ? {
113
- accessToken: tokens.accessToken,
114
- accessTokenPayload: tokens.accessTokenPayload ,
115
- generateDemonstrationOfProofOfPossessionAsync: getGenerateDemonstrationOfProofOfPossessionAsync(oidc, tokens),
116
- } : accessTokenInitialState);
117
+ const getOidc = OidcClient.get;
118
+ const [state, setAccessToken] = useState<OidcAccessToken>(initTokens(configurationName));
119
+
120
+ useEffect(() => {
121
+ let isMounted = true;
122
+ const oidc = getOidc(configurationName);
123
+ if (oidc.tokens) {
124
+ const tokens = oidc.tokens;
125
+ setAccessToken({
126
+ accessToken: tokens.accessToken,
127
+ accessTokenPayload: tokens.accessTokenPayload,
128
+ });
129
+ }
130
+
131
+ const newSubscriptionId = oidc.subscribeEvents((name: string, data: any) => {
132
+ if (
133
+ name === OidcClient.eventNames.token_renewed ||
134
+ name === OidcClient.eventNames.token_aquired ||
135
+ name === OidcClient.eventNames.logout_from_another_tab ||
136
+ name === OidcClient.eventNames.logout_from_same_tab ||
137
+ name === OidcClient.eventNames.refreshTokensAsync_error ||
138
+ name === OidcClient.eventNames.syncTokensAsync_error
139
+ ) {
140
+ if (isMounted) {
141
+ const tokens = oidc.tokens;
142
+ setAccessToken(
143
+ tokens != null
144
+ ? {
145
+ accessToken: tokens.accessToken,
146
+ accessTokenPayload: tokens.accessTokenPayload,
147
+ generateDemonstrationOfProofOfPossessionAsync:
148
+ getGenerateDemonstrationOfProofOfPossessionAsync(oidc, tokens),
117
149
  }
118
- }
119
- });
120
- return () => {
121
- isMounted = false;
122
- oidc.removeEventSubscription(newSubscriptionId);
123
- };
124
- // eslint-disable-next-line react-hooks/exhaustive-deps
125
- }, [configurationName]);
126
- return state;
150
+ : accessTokenInitialState,
151
+ );
152
+ }
153
+ }
154
+ });
155
+ return () => {
156
+ isMounted = false;
157
+ oidc.removeEventSubscription(newSubscriptionId);
158
+ };
159
+ }, [configurationName]);
160
+ return state;
127
161
  };
128
162
 
129
- const idTokenInitialState = { idToken: null, idTokenPayload: null};
163
+ const idTokenInitialState = { idToken: null, idTokenPayload: null };
130
164
 
131
165
  const initIdToken = (configurationName: string) => {
132
- const getOidc = OidcClient.get;
133
- const oidc = getOidc(configurationName);
134
-
135
- if (oidc.tokens) {
136
- const tokens = oidc.tokens;
137
- return { idToken: tokens.idToken, idTokenPayload: tokens.idTokenPayload };
138
- }
139
- return idTokenInitialState;
166
+ const getOidc = OidcClient.get;
167
+ const oidc = getOidc(configurationName);
168
+
169
+ if (oidc.tokens) {
170
+ const tokens = oidc.tokens;
171
+ return { idToken: tokens.idToken, idTokenPayload: tokens.idTokenPayload };
172
+ }
173
+ return idTokenInitialState;
140
174
  };
141
175
 
142
176
  export type OidcIdToken = {
143
- idToken?: any;
144
- idTokenPayload?: any;
145
- }
177
+ idToken?: any;
178
+ idTokenPayload?: any;
179
+ };
146
180
 
147
181
  export const useOidcIdToken = (configurationName = defaultConfigurationName) => {
148
- const getOidc = OidcClient.get;
149
- const [state, setIDToken] = useState<OidcIdToken>(initIdToken(configurationName));
150
-
151
- useEffect(() => {
152
- let isMounted = true;
153
- const oidc = getOidc(configurationName);
154
- if (oidc.tokens) {
155
- const tokens = oidc.tokens;
156
- setIDToken({ idToken: tokens.idToken, idTokenPayload: tokens.idTokenPayload });
182
+ const getOidc = OidcClient.get;
183
+ const [state, setIDToken] = useState<OidcIdToken>(initIdToken(configurationName));
184
+
185
+ useEffect(() => {
186
+ let isMounted = true;
187
+ const oidc = getOidc(configurationName);
188
+ if (oidc.tokens) {
189
+ const tokens = oidc.tokens;
190
+ setIDToken({ idToken: tokens.idToken, idTokenPayload: tokens.idTokenPayload });
191
+ }
192
+
193
+ const newSubscriptionId = oidc.subscribeEvents((name: string, data: any) => {
194
+ if (
195
+ name === OidcClient.eventNames.token_renewed ||
196
+ name === OidcClient.eventNames.token_aquired ||
197
+ name === OidcClient.eventNames.logout_from_another_tab ||
198
+ name === OidcClient.eventNames.logout_from_same_tab ||
199
+ name === OidcClient.eventNames.refreshTokensAsync_error ||
200
+ name === OidcClient.eventNames.syncTokensAsync_error
201
+ ) {
202
+ if (isMounted) {
203
+ const tokens = oidc.tokens;
204
+ setIDToken(
205
+ tokens != null
206
+ ? { idToken: tokens.idToken, idTokenPayload: tokens.idTokenPayload }
207
+ : idTokenInitialState,
208
+ );
157
209
  }
158
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
159
- const newSubscriptionId = oidc.subscribeEvents((name: string, data: any) => {
160
- if (name === OidcClient.eventNames.token_renewed ||
161
- name === OidcClient.eventNames.token_aquired ||
162
- name === OidcClient.eventNames.logout_from_another_tab ||
163
- name === OidcClient.eventNames.logout_from_same_tab ||
164
- name === OidcClient.eventNames.refreshTokensAsync_error ||
165
- name === OidcClient.eventNames.syncTokensAsync_error) {
166
- if (isMounted) {
167
- const tokens = oidc.tokens;
168
- setIDToken(tokens != null ? { idToken: tokens.idToken, idTokenPayload: tokens.idTokenPayload } : idTokenInitialState);
169
- }
170
- }
171
- });
172
- return () => {
173
- isMounted = false;
174
- oidc.removeEventSubscription(newSubscriptionId);
175
- };
176
- // eslint-disable-next-line react-hooks/exhaustive-deps
177
- }, [configurationName]);
178
- return state;
210
+ }
211
+ });
212
+ return () => {
213
+ isMounted = false;
214
+ oidc.removeEventSubscription(newSubscriptionId);
215
+ };
216
+ }, [configurationName]);
217
+ return state;
179
218
  };
package/src/User.ts CHANGED
@@ -1,62 +1,72 @@
1
- import { type OidcUserInfo, OidcClient } from '@axa-fr/oidc-client';
1
+ import { OidcClient, type OidcUserInfo } from '@axa-fr/oidc-client';
2
2
  import { useEffect, useState } from 'react';
3
3
 
4
4
  export enum OidcUserStatus {
5
- Unauthenticated= 'Unauthenticated',
6
- Loading = 'Loading user',
7
- Loaded = 'User loaded',
8
- LoadingError = 'Error loading user'
5
+ Unauthenticated = 'Unauthenticated',
6
+ Loading = 'Loading user',
7
+ Loaded = 'User loaded',
8
+ LoadingError = 'Error loading user',
9
9
  }
10
10
 
11
11
  export type OidcUser<T extends OidcUserInfo = OidcUserInfo> = {
12
- user: T | null;
13
- status: OidcUserStatus;
14
- }
12
+ user: T | null;
13
+ status: OidcUserStatus;
14
+ };
15
+
16
+ export const useOidcUser = <T extends OidcUserInfo = OidcUserInfo>(
17
+ configurationName = 'default',
18
+ demonstrating_proof_of_possession = false,
19
+ ) => {
20
+ const oidc = OidcClient.get(configurationName);
21
+ const user = oidc.userInfo<T>();
22
+ const [oidcUser, setOidcUser] = useState<OidcUser<T>>({
23
+ user: user,
24
+ status: user ? OidcUserStatus.Loaded : OidcUserStatus.Unauthenticated,
25
+ });
26
+ const [oidcUserId, setOidcUserId] = useState<number>(user ? 1 : 0);
27
+ const [oidcPreviousUserId, setPreviousOidcUserId] = useState<number>(user ? 1 : 0);
15
28
 
16
- export const useOidcUser = <T extends OidcUserInfo = OidcUserInfo>(configurationName = 'default', demonstrating_proof_of_possession=false) => {
29
+ useEffect(() => {
17
30
  const oidc = OidcClient.get(configurationName);
18
- const user = oidc.userInfo<T>();
19
- const [oidcUser, setOidcUser] = useState<OidcUser<T>>({ user: user, status: user ? OidcUserStatus.Loaded : OidcUserStatus.Unauthenticated });
20
- const [oidcUserId, setOidcUserId] = useState<number>(user ? 1 : 0);
21
- const [oidcPreviousUserId, setPreviousOidcUserId] = useState<number>(user ? 1 : 0);
22
-
23
- useEffect(() => {
24
- const oidc = OidcClient.get(configurationName);
25
- let isMounted = true;
26
- if (oidc && oidc.tokens) {
27
- const isCache = oidcUserId === oidcPreviousUserId;
28
- if(isCache && oidc.userInfo<T>()) {
29
- return;
30
- }
31
- setOidcUser({ ...oidcUser, status: OidcUserStatus.Loading });
32
- oidc.userInfoAsync(!isCache, demonstrating_proof_of_possession)
33
- .then((info) => {
34
- if (isMounted) {
35
- // @ts-ignore
36
- setOidcUser({ user: info, status: OidcUserStatus.Loaded });
37
- }
38
- })
39
- .catch(() => setOidcUser({ ...oidcUser, status: OidcUserStatus.LoadingError }));
40
- setPreviousOidcUserId(oidcUserId);
41
- } else {
42
- setOidcUser({ user: null, status: OidcUserStatus.Unauthenticated });
31
+ let isMounted = true;
32
+ if (oidc && oidc.tokens) {
33
+ const isCache = oidcUserId === oidcPreviousUserId;
34
+ if (isCache && oidc.userInfo<T>()) {
35
+ return;
36
+ }
37
+ setOidcUser({ ...oidcUser, status: OidcUserStatus.Loading });
38
+ oidc
39
+ .userInfoAsync(!isCache, demonstrating_proof_of_possession)
40
+ .then(info => {
41
+ if (isMounted) {
42
+ // @ts-ignore
43
+ setOidcUser({ user: info, status: OidcUserStatus.Loaded });
44
+ }
45
+ })
46
+ .catch(() => setOidcUser({ ...oidcUser, status: OidcUserStatus.LoadingError }));
47
+ setPreviousOidcUserId(oidcUserId);
48
+ } else {
49
+ setOidcUser({ user: null, status: OidcUserStatus.Unauthenticated });
50
+ }
51
+ const newSubscriptionId = oidc.subscribeEvents((name: string) => {
52
+ if (
53
+ name === OidcClient.eventNames.logout_from_another_tab ||
54
+ name === OidcClient.eventNames.logout_from_same_tab
55
+ ) {
56
+ if (isMounted) {
57
+ setOidcUser({ user: null, status: OidcUserStatus.Unauthenticated });
43
58
  }
44
- const newSubscriptionId = oidc.subscribeEvents((name: string) => {
45
- if (name === OidcClient.eventNames.logout_from_another_tab || name === OidcClient.eventNames.logout_from_same_tab) {
46
- if (isMounted) {
47
- setOidcUser({ user: null, status: OidcUserStatus.Unauthenticated });
48
- }
49
- }
50
- });
51
- return () => {
52
- isMounted = false;
53
- oidc.removeEventSubscription(newSubscriptionId);
54
- };
55
- }, [oidcUserId]);
56
-
57
- const reloadOidcUser = () => {
58
- setOidcUserId(oidcUserId+1);
59
+ }
60
+ });
61
+ return () => {
62
+ isMounted = false;
63
+ oidc.removeEventSubscription(newSubscriptionId);
59
64
  };
65
+ }, [oidcUserId]);
66
+
67
+ const reloadOidcUser = () => {
68
+ setOidcUserId(oidcUserId + 1);
69
+ };
60
70
 
61
- return { oidcUser: oidcUser.user, oidcUserLoadingState: oidcUser.status, reloadOidcUser };
71
+ return { oidcUser: oidcUser.user, oidcUserLoadingState: oidcUser.status, reloadOidcUser };
62
72
  };
@@ -1,6 +1,6 @@
1
1
  import { ComponentType } from 'react';
2
2
 
3
- const Authenticating : ComponentType<any> = () => (
3
+ const Authenticating: ComponentType<any> = () => (
4
4
  <div className="oidc-authenticating">
5
5
  <div className="oidc-authenticating__container">
6
6
  <h1 className="oidc-authenticating__title">Authentication in progress</h1>
@@ -4,14 +4,21 @@ import { ComponentType, useEffect, useState } from 'react';
4
4
  import { getCustomHistory } from '../routes/withRouter.js';
5
5
  import AuthenticatingError from './AuthenticateError.component.js';
6
6
 
7
- export const CallBackSuccess: ComponentType<any> = () => (<div className="oidc-callback">
8
- <div className="oidc-callback__container">
9
- <h1 className="oidc-callback__title">Authentication complete</h1>
10
- <p className="oidc-callback__content">You will be redirected to your application.</p>
7
+ export const CallBackSuccess: ComponentType<any> = () => (
8
+ <div className="oidc-callback">
9
+ <div className="oidc-callback__container">
10
+ <h1 className="oidc-callback__title">Authentication complete</h1>
11
+ <p className="oidc-callback__content">You will be redirected to your application.</p>
12
+ </div>
11
13
  </div>
12
- </div>);
14
+ );
13
15
 
14
- const CallbackManager: ComponentType<any> = ({ callBackError, callBackSuccess, configurationName, withCustomHistory }) => {
16
+ const CallbackManager: ComponentType<any> = ({
17
+ callBackError,
18
+ callBackSuccess,
19
+ configurationName,
20
+ withCustomHistory,
21
+ }) => {
15
22
  const [isError, setIsError] = useState(false);
16
23
  useEffect(() => {
17
24
  let isMounted = true;
@@ -19,13 +26,13 @@ const CallbackManager: ComponentType<any> = ({ callBackError, callBackSuccess, c
19
26
  const getOidc = OidcClient.get;
20
27
  try {
21
28
  const { callbackPath } = await getOidc(configurationName).loginCallbackAsync();
22
- const history = (withCustomHistory) ? withCustomHistory() : getCustomHistory();
29
+ const history = withCustomHistory ? withCustomHistory() : getCustomHistory();
23
30
  history.replaceState(callbackPath || '/');
24
31
  } catch (error) {
25
- if (isMounted) {
26
- console.warn(error);
27
- setIsError(true);
28
- }
32
+ if (isMounted) {
33
+ console.warn(error);
34
+ setIsError(true);
35
+ }
29
36
  }
30
37
  };
31
38
  playCallbackAsync();
@@ -1,9 +1,5 @@
1
1
  import { ComponentType } from 'react';
2
2
 
3
- const Loading : ComponentType<any> = () => (
4
- <span className="oidc-loading">
5
- Loading
6
- </span>
7
- );
3
+ const Loading: ComponentType<any> = () => <span className="oidc-loading">Loading</span>;
8
4
 
9
5
  export default Loading;
@@ -1,10 +1,13 @@
1
1
  import { ComponentType } from 'react';
2
2
 
3
- const ServiceWorkerNotSupported : ComponentType<any> = () => (
3
+ const ServiceWorkerNotSupported: ComponentType<any> = () => (
4
4
  <div className="oidc-serviceworker">
5
5
  <div className="oidc-serviceworker__container">
6
6
  <h1 className="oidc-serviceworker__title">Unable to authenticate on this browser</h1>
7
- <p className="oidc-serviceworker__content">Your browser is not secure enough to make authentication work. Try updating your browser or use a newer browser.</p>
7
+ <p className="oidc-serviceworker__content">
8
+ Your browser is not secure enough to make authentication work. Try updating your browser or
9
+ use a newer browser.
10
+ </p>
8
11
  </div>
9
12
  </div>
10
13
  );
@@ -5,7 +5,7 @@ export const SessionLost: ComponentType<any> = () => (
5
5
  <div className="oidc-session-lost__container">
6
6
  <h1 className="oidc-session-lost__title">Session timed out</h1>
7
7
  <p className="oidc-session-lost__content">
8
- Your session has expired. Please re-authenticate.
8
+ Your session has expired. Please re-authenticate.
9
9
  </p>
10
10
  </div>
11
11
  </div>
@@ -1,17 +1,23 @@
1
1
  import { OidcClient } from '@axa-fr/oidc-client';
2
- import { ComponentType, useEffect } from 'react';
2
+ import { FC, useEffect } from 'react';
3
3
 
4
- const SilentCallbackManager: ComponentType<any> = ({ configurationName }) => {
5
- useEffect(() => {
6
- const playCallbackAsync = async () => {
7
- const getOidc = OidcClient.get;
8
- const oidc = getOidc(configurationName);
9
- oidc.silentLoginCallbackAsync();
10
- };
11
- playCallbackAsync();
12
- }, []);
4
+ export interface SilentCallbackProps {
5
+ configurationName: string;
6
+ }
13
7
 
14
- return <></>;
8
+ const SilentCallbackManager: FC<SilentCallbackProps> = ({ configurationName }) => {
9
+ useEffect(() => {
10
+ const playCallbackAsync = async () => {
11
+ const oidc = OidcClient.get(configurationName);
12
+ oidc.silentLoginCallbackAsync();
13
+ };
14
+
15
+ playCallbackAsync().catch(error => {
16
+ console.error('Error during silent login callback:', error);
17
+ });
18
+ }, [configurationName]);
19
+
20
+ return null;
15
21
  };
16
22
 
17
23
  export default SilentCallbackManager;