@spidy092/auth-client 1.0.6 → 1.0.7
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/core.js +15 -30
- package/package.json +1 -1
package/core.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
1
|
import { setToken, clearToken, getToken } from './token';
|
|
3
2
|
import { getConfig } from './config';
|
|
4
3
|
|
|
5
|
-
export function login(clientKeyArg, redirectUriArg
|
|
4
|
+
export function login(clientKeyArg, redirectUriArg) { // Removed stateArg
|
|
6
5
|
const {
|
|
7
6
|
clientKey: defaultClientKey,
|
|
8
7
|
authBaseUrl,
|
|
@@ -12,44 +11,42 @@ export function login(clientKeyArg, redirectUriArg, stateArg) {
|
|
|
12
11
|
|
|
13
12
|
const clientKey = clientKeyArg || defaultClientKey;
|
|
14
13
|
const redirectUri = redirectUriArg || defaultRedirectUri;
|
|
15
|
-
|
|
14
|
+
// Removed state generation
|
|
16
15
|
|
|
17
16
|
console.log('Initiating login with parameters:', {
|
|
18
17
|
clientKey,
|
|
19
|
-
redirectUri
|
|
20
|
-
state
|
|
18
|
+
redirectUri
|
|
19
|
+
// Removed state from logging
|
|
20
|
+
});
|
|
21
21
|
|
|
22
|
-
|
|
23
22
|
if (!clientKey || !redirectUri) {
|
|
24
23
|
throw new Error('Missing clientKey or redirectUri');
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
// Store
|
|
28
|
-
sessionStorage.setItem('authState', state);
|
|
26
|
+
// Store only app info, no state
|
|
29
27
|
sessionStorage.setItem('originalApp', clientKey);
|
|
30
28
|
sessionStorage.setItem('returnUrl', redirectUri);
|
|
31
29
|
|
|
32
30
|
// --- ENTERPRISE LOGIC ---
|
|
33
31
|
// If we are already in Account-UI, go straight to the backend
|
|
34
32
|
if (window.location.origin === accountUiUrl && clientKey === 'account-ui') {
|
|
35
|
-
// Direct SSO kick-off for Account-UI
|
|
36
|
-
const backendLoginUrl = `${authBaseUrl}/login/${clientKey}?redirect_uri=${encodeURIComponent(redirectUri)}
|
|
33
|
+
// Direct SSO kick-off for Account-UI (no state parameter)
|
|
34
|
+
const backendLoginUrl = `${authBaseUrl}/login/${clientKey}?redirect_uri=${encodeURIComponent(redirectUri)}`;
|
|
37
35
|
console.log('Redirecting directly to auth backend:', backendLoginUrl);
|
|
38
36
|
window.location.href = backendLoginUrl;
|
|
39
37
|
return;
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
// Otherwise, centralized login flow (for other apps)
|
|
40
|
+
// Otherwise, centralized login flow (for other apps, no state)
|
|
43
41
|
const accountLoginUrl = `${accountUiUrl}/login?` + new URLSearchParams({
|
|
44
42
|
client: clientKey,
|
|
45
|
-
redirect_uri: redirectUri
|
|
46
|
-
|
|
43
|
+
redirect_uri: redirectUri
|
|
44
|
+
// Removed state
|
|
47
45
|
});
|
|
48
46
|
console.log('Redirecting to centralized Account UI:', accountLoginUrl);
|
|
49
47
|
window.location.href = accountLoginUrl;
|
|
50
48
|
}
|
|
51
49
|
|
|
52
|
-
|
|
53
50
|
export function logout() {
|
|
54
51
|
const { clientKey, authBaseUrl, accountUiUrl } = getConfig();
|
|
55
52
|
const token = getToken();
|
|
@@ -78,28 +75,16 @@ export function handleCallback() {
|
|
|
78
75
|
const params = new URLSearchParams(window.location.search);
|
|
79
76
|
const accessToken = params.get('access_token');
|
|
80
77
|
const error = params.get('error');
|
|
81
|
-
|
|
82
|
-
const storedState = sessionStorage.getItem('authState');
|
|
78
|
+
// Removed state handling completely
|
|
83
79
|
|
|
84
80
|
console.log('Handling authentication callback:', {
|
|
85
81
|
accessToken,
|
|
86
|
-
error
|
|
87
|
-
state
|
|
88
|
-
storedState
|
|
82
|
+
error
|
|
83
|
+
// Removed state from logging
|
|
89
84
|
});
|
|
90
85
|
|
|
86
|
+
// Removed all state validation
|
|
91
87
|
|
|
92
|
-
// Validate state
|
|
93
|
-
// if (state && storedState && state !== storedState) {
|
|
94
|
-
// throw new Error('Invalid state. Possible CSRF attack.');
|
|
95
|
-
// }
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (!state && !storedState ) {
|
|
99
|
-
throw new Error('no state. Possible CSRF attack.');
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
sessionStorage.removeItem('authState');
|
|
103
88
|
sessionStorage.removeItem('originalApp');
|
|
104
89
|
sessionStorage.removeItem('returnUrl');
|
|
105
90
|
|