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