@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.
- package/README.md +87 -114
- package/bin/copy-service-worker-files.mjs +24 -17
- package/dist/FetchToken.d.ts.map +1 -1
- package/dist/OidcProvider.d.ts +1 -1
- package/dist/OidcProvider.d.ts.map +1 -1
- package/dist/OidcSecure.d.ts.map +1 -1
- package/dist/OidcTrustedDomains.js +13 -10
- package/dist/ReactOidc.d.ts.map +1 -1
- package/dist/User.d.ts.map +1 -1
- package/dist/core/default-component/Authenticating.component.d.ts.map +1 -1
- package/dist/core/default-component/Callback.component.d.ts.map +1 -1
- package/dist/core/default-component/Loading.component.d.ts.map +1 -1
- package/dist/core/default-component/ServiceWorkerNotSupported.component.d.ts.map +1 -1
- package/dist/core/default-component/SilentCallback.component.d.ts +5 -2
- package/dist/core/default-component/SilentCallback.component.d.ts.map +1 -1
- package/dist/core/routes/OidcRoutes.d.ts.map +1 -1
- package/dist/core/routes/withRouter.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +165 -72
- package/dist/index.umd.cjs +1 -1
- package/package.json +3 -3
- package/src/FetchToken.tsx +36 -13
- package/src/OidcProvider.tsx +222 -176
- package/src/OidcSecure.tsx +34 -23
- package/src/ReactOidc.tsx +181 -142
- package/src/User.ts +60 -50
- package/src/core/default-component/Authenticating.component.tsx +1 -1
- package/src/core/default-component/Callback.component.tsx +18 -11
- package/src/core/default-component/Loading.component.tsx +1 -5
- package/src/core/default-component/ServiceWorkerNotSupported.component.tsx +5 -2
- package/src/core/default-component/SessionLost.component.tsx +1 -1
- package/src/core/default-component/SilentCallback.component.tsx +17 -11
- package/src/core/default-component/SilentLogin.component.tsx +18 -18
- package/src/core/routes/OidcRoutes.spec.tsx +2 -2
- package/src/core/routes/OidcRoutes.tsx +12 -5
- package/src/core/routes/withRouter.spec.tsx +5 -6
- package/src/core/routes/withRouter.tsx +21 -19
- package/src/index.ts +8 -3
package/src/ReactOidc.tsx
CHANGED
|
@@ -1,179 +1,218 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
8
|
-
}
|
|
7
|
+
(configurationName?: string): any;
|
|
8
|
+
};
|
|
9
9
|
|
|
10
10
|
const defaultIsAuthenticated = (getOidc: GetOidcFn, configurationName: string) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
};
|
|
45
|
-
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
104
|
+
accessToken?: any;
|
|
105
|
+
accessTokenPayload?: any;
|
|
106
|
+
generateDemonstrationOfProofOfPossessionAsync?: any;
|
|
107
|
+
};
|
|
86
108
|
|
|
87
109
|
function getGenerateDemonstrationOfProofOfPossessionAsync(oidc: OidcClient, tokens: Tokens) {
|
|
88
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
+
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
177
|
+
idToken?: any;
|
|
178
|
+
idTokenPayload?: any;
|
|
179
|
+
};
|
|
146
180
|
|
|
147
181
|
export const useOidcIdToken = (configurationName = defaultConfigurationName) => {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
13
|
-
|
|
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
|
-
|
|
29
|
+
useEffect(() => {
|
|
17
30
|
const oidc = OidcClient.get(configurationName);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
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
|
|
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> = () => (
|
|
8
|
-
<div className="oidc-
|
|
9
|
-
<
|
|
10
|
-
|
|
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
|
-
|
|
14
|
+
);
|
|
13
15
|
|
|
14
|
-
const CallbackManager: ComponentType<any> = ({
|
|
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 =
|
|
29
|
+
const history = withCustomHistory ? withCustomHistory() : getCustomHistory();
|
|
23
30
|
history.replaceState(callbackPath || '/');
|
|
24
31
|
} catch (error) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
|
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
|
|
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">
|
|
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
|
-
|
|
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 {
|
|
2
|
+
import { FC, useEffect } from 'react';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
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;
|