@truworth/twc-auth 3.0.4 → 3.0.5
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.
|
@@ -27,12 +27,13 @@ const SSOCallbackComponents = ({ authMethodOverride } = {}) => {
|
|
|
27
27
|
const [code, setCode] = useState('');
|
|
28
28
|
const [authMethod, setAuthMethod] = useState(authMethodOverride ?? null);
|
|
29
29
|
const [isReady, setIsReady] = useState(false);
|
|
30
|
-
// Resolve code
|
|
30
|
+
// Resolve code from query params; clientId from localStorage (only needed for OIDC)
|
|
31
31
|
useEffect(() => {
|
|
32
32
|
const query = navigator.query;
|
|
33
33
|
const codeFromQuery = query.code;
|
|
34
34
|
if (typeof window !== 'undefined') {
|
|
35
35
|
try {
|
|
36
|
+
// clientId only needed for OIDC, not SAML
|
|
36
37
|
const storedClientId = localStorage.getItem('clientId') || '';
|
|
37
38
|
const storedAuthMethod = localStorage.getItem('authMethod') || 'oidc';
|
|
38
39
|
setClientId(storedClientId);
|
|
@@ -19,8 +19,10 @@ const useSSOCallback = ({ clientId, code, authMethod, isReady = true }) => {
|
|
|
19
19
|
const { onLogin, onRegistrationMethodChange, onTokenChange } = useAuthPackageContext();
|
|
20
20
|
const processSSOCallback = useCallback((codeToProcess) => {
|
|
21
21
|
setError(null);
|
|
22
|
+
// SAML: Use simplified endpoint that doesn't require clientId
|
|
23
|
+
// OIDC: Use legacy endpoint with clientId
|
|
22
24
|
const endpoint = authMethod === 'saml'
|
|
23
|
-
? `/auth/
|
|
25
|
+
? `/auth/saml/complete`
|
|
24
26
|
: `/auth/login-sso/${clientId}/callback`;
|
|
25
27
|
axiosClient({
|
|
26
28
|
url: endpoint,
|
|
@@ -42,11 +44,15 @@ const useSSOCallback = ({ clientId, code, authMethod, isReady = true }) => {
|
|
|
42
44
|
});
|
|
43
45
|
}, [clientId, authMethod, onLogin, onRegistrationMethodChange, onTokenChange]);
|
|
44
46
|
useEffect(() => {
|
|
45
|
-
if (isReady
|
|
47
|
+
if (!isReady || !code || hasProcessed)
|
|
48
|
+
return;
|
|
49
|
+
// SAML only needs code; OIDC needs both code and clientId
|
|
50
|
+
const canProcess = authMethod === 'saml' || clientId;
|
|
51
|
+
if (canProcess) {
|
|
46
52
|
setHasProcessed(true);
|
|
47
53
|
processSSOCallback(code);
|
|
48
54
|
}
|
|
49
|
-
}, [isReady, code, clientId, hasProcessed, processSSOCallback]);
|
|
55
|
+
}, [isReady, code, clientId, authMethod, hasProcessed, processSSOCallback]);
|
|
50
56
|
return { result, error };
|
|
51
57
|
};
|
|
52
58
|
export { useSSOCallback };
|