@spidy092/auth-client 2.0.7 → 2.0.8
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/config.js +0 -1
- package/core.js +15 -54
- package/package.json +1 -1
package/config.js
CHANGED
package/core.js
CHANGED
|
@@ -12,7 +12,7 @@ import { getConfig, isRouterMode } from './config';
|
|
|
12
12
|
|
|
13
13
|
let callbackProcessed = false;
|
|
14
14
|
|
|
15
|
-
export function login(clientKeyArg, redirectUriArg
|
|
15
|
+
export function login(clientKeyArg, redirectUriArg) {
|
|
16
16
|
// ✅ Reset callback state when starting new login
|
|
17
17
|
resetCallbackState();
|
|
18
18
|
|
|
@@ -25,14 +25,11 @@ export function login(clientKeyArg, redirectUriArg, options = {}) {
|
|
|
25
25
|
|
|
26
26
|
const clientKey = clientKeyArg || defaultClientKey;
|
|
27
27
|
const redirectUri = redirectUriArg || defaultRedirectUri;
|
|
28
|
-
const { codeChallenge, codeChallengeMethod, state } = options;
|
|
29
28
|
|
|
30
29
|
console.log('🔄 Smart Login initiated:', {
|
|
31
30
|
mode: isRouterMode() ? 'ROUTER' : 'CLIENT',
|
|
32
31
|
clientKey,
|
|
33
|
-
redirectUri
|
|
34
|
-
hasPKCE: !!codeChallenge,
|
|
35
|
-
hasState: !!state
|
|
32
|
+
redirectUri
|
|
36
33
|
});
|
|
37
34
|
|
|
38
35
|
if (!clientKey || !redirectUri) {
|
|
@@ -44,39 +41,27 @@ export function login(clientKeyArg, redirectUriArg, options = {}) {
|
|
|
44
41
|
|
|
45
42
|
if (isRouterMode()) {
|
|
46
43
|
// Router mode: Direct backend authentication
|
|
47
|
-
return routerLogin(clientKey, redirectUri
|
|
44
|
+
return routerLogin(clientKey, redirectUri);
|
|
48
45
|
} else {
|
|
49
46
|
// Client mode: Redirect to centralized login
|
|
50
|
-
return clientLogin(clientKey, redirectUri
|
|
47
|
+
return clientLogin(clientKey, redirectUri);
|
|
51
48
|
}
|
|
52
49
|
}
|
|
53
50
|
|
|
54
51
|
// ✅ Router mode: Direct backend call
|
|
55
|
-
function routerLogin(clientKey, redirectUri
|
|
52
|
+
function routerLogin(clientKey, redirectUri) {
|
|
56
53
|
const { authBaseUrl } = getConfig();
|
|
57
|
-
const { codeChallenge, codeChallengeMethod, state } = options;
|
|
58
|
-
|
|
59
|
-
// Build URL with PKCE and state parameters
|
|
60
|
-
const params = new URLSearchParams({
|
|
61
|
-
redirect_uri: redirectUri
|
|
62
|
-
});
|
|
63
54
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
params.append('
|
|
55
|
+
const params = new URLSearchParams();
|
|
56
|
+
if (redirectUri) {
|
|
57
|
+
params.append('redirect_uri', redirectUri);
|
|
67
58
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
params.append('state', state);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const backendLoginUrl = `${authBaseUrl}/login/${clientKey}?${params.toString()}`;
|
|
59
|
+
const query = params.toString();
|
|
60
|
+
const backendLoginUrl = `${authBaseUrl}/login/${clientKey}${query ? `?${query}` : ''}`;
|
|
74
61
|
|
|
75
62
|
console.log('🏭 Router Login: Direct backend authentication', {
|
|
76
63
|
clientKey,
|
|
77
64
|
redirectUri,
|
|
78
|
-
hasPKCE: !!codeChallenge,
|
|
79
|
-
hasState: !!state,
|
|
80
65
|
backendUrl: backendLoginUrl
|
|
81
66
|
});
|
|
82
67
|
|
|
@@ -84,32 +69,20 @@ function routerLogin(clientKey, redirectUri, options = {}) {
|
|
|
84
69
|
}
|
|
85
70
|
|
|
86
71
|
// ✅ Client mode: Centralized login
|
|
87
|
-
function clientLogin(clientKey, redirectUri
|
|
72
|
+
function clientLogin(clientKey, redirectUri) {
|
|
88
73
|
const { accountUiUrl } = getConfig();
|
|
89
|
-
const { codeChallenge, codeChallengeMethod, state } = options;
|
|
90
74
|
|
|
91
|
-
// Build URL with PKCE and state parameters
|
|
92
75
|
const params = new URLSearchParams({
|
|
93
|
-
client: clientKey
|
|
94
|
-
redirect_uri: redirectUri
|
|
76
|
+
client: clientKey
|
|
95
77
|
});
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
params.append('code_challenge', codeChallenge);
|
|
99
|
-
params.append('code_challenge_method', codeChallengeMethod || 'S256');
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (state) {
|
|
103
|
-
params.append('state', state);
|
|
78
|
+
if (redirectUri) {
|
|
79
|
+
params.append('redirect_uri', redirectUri);
|
|
104
80
|
}
|
|
105
|
-
|
|
106
81
|
const centralizedLoginUrl = `${accountUiUrl}/login?${params.toString()}`;
|
|
107
82
|
|
|
108
83
|
console.log('🔄 Client Login: Redirecting to centralized login', {
|
|
109
84
|
clientKey,
|
|
110
85
|
redirectUri,
|
|
111
|
-
hasPKCE: !!codeChallenge,
|
|
112
|
-
hasState: !!state,
|
|
113
86
|
centralizedUrl: centralizedLoginUrl
|
|
114
87
|
});
|
|
115
88
|
|
|
@@ -187,23 +160,12 @@ export function handleCallback() {
|
|
|
187
160
|
const params = new URLSearchParams(window.location.search);
|
|
188
161
|
const accessToken = params.get('access_token');
|
|
189
162
|
const error = params.get('error');
|
|
190
|
-
const state = params.get('state');
|
|
191
163
|
|
|
192
164
|
console.log('🔄 Callback handling:', {
|
|
193
165
|
hasAccessToken: !!accessToken,
|
|
194
|
-
error
|
|
195
|
-
hasState: !!state
|
|
166
|
+
error
|
|
196
167
|
});
|
|
197
168
|
|
|
198
|
-
// ✅ Validate state parameter
|
|
199
|
-
if (state) {
|
|
200
|
-
console.warn("⚠️ State returned but validation disabled (demo mode)");
|
|
201
|
-
|
|
202
|
-
// Clean up any existing stored state
|
|
203
|
-
sessionStorage.removeItem('oauth_state');
|
|
204
|
-
sessionStorage.removeItem('pkce_timestamp');
|
|
205
|
-
}
|
|
206
|
-
|
|
207
169
|
// ✅ Prevent duplicate callback processing
|
|
208
170
|
if (callbackProcessed) {
|
|
209
171
|
const existingToken = getToken();
|
|
@@ -218,7 +180,6 @@ export function handleCallback() {
|
|
|
218
180
|
callbackProcessed = true;
|
|
219
181
|
sessionStorage.removeItem('originalApp');
|
|
220
182
|
sessionStorage.removeItem('returnUrl');
|
|
221
|
-
sessionStorage.removeItem('pkce_code_verifier'); // Clear PKCE verifier after use
|
|
222
183
|
|
|
223
184
|
if (error) {
|
|
224
185
|
const errorDescription = params.get('error_description') || error;
|