@@ -7,7 +7,7 @@ interface TokenResponse {
77}
88
99interface TokenData {
10- accessToken : string ;
10+ cessToken : string ;
1111 tokenType : string ;
1212 expiresAt : Date ;
1313 refreshToken ?: string ;
@@ -35,15 +35,11 @@ class AuthService {
3535 * Get a valid access token (user tokens only - no client credentials)
3636 */
3737 public async getAccessToken ( ) : Promise < string > {
38- console . log ( '🎫 getAccessToken() called' ) ;
39-
4038 // Only return user tokens, never client credential tokens
4139 if ( this . tokenData && this . isTokenValid ( ) && this . isAuthenticated ( ) ) {
42- console . log ( '✅ Using existing valid user token' ) ;
4340 return this . tokenData . accessToken ;
4441 }
4542
46- console . log ( '❌ No valid user token available - client must authenticate via OAuth' ) ;
4743 throw new Error ( 'No valid user token available. User must log in via OAuth.' ) ;
4844 }
4945
@@ -83,10 +79,6 @@ class AuthService {
8379 */
8480 private loadTokenFromStorage ( ) : void {
8581 const stored = localStorage . getItem ( 'trackman_auth_token' ) ;
86- console . log ( '🔍 Loading token from storage:' , {
87- hasStoredToken : ! ! stored ,
88- tokenPreview : stored ? stored . substring ( 0 , 50 ) + '...' : 'none'
89- } ) ;
9082
9183 if ( stored ) {
9284 try {
@@ -98,17 +90,8 @@ class AuthService {
9890 scope : parsed . scope ,
9991 } ;
10092
101- console . log ( '📦 Loaded token data:' , {
102- hasAccessToken : ! ! this . tokenData . accessToken ,
103- tokenType : this . tokenData . tokenType ,
104- expiresAt : this . tokenData . expiresAt ,
105- scope : this . tokenData . scope ,
106- isValid : this . isTokenValid ( )
107- } ) ;
108-
10993 // Clean up if token is expired
11094 if ( ! this . isTokenValid ( ) ) {
111- console . log ( '🗑️ Token is expired, clearing...' ) ;
11295 this . clearToken ( ) ;
11396 }
11497 } catch ( error ) {
@@ -122,8 +105,6 @@ class AuthService {
122105 * Clear the current token and all authentication state
123106 */
124107 public clearToken ( ) : void {
125- console . log ( '🧹 Clearing all authentication tokens and state...' ) ;
126-
127108 // Clear in-memory token
128109 this . tokenData = null ;
129110
@@ -136,17 +117,13 @@ class AuthService {
136117 sessionStorage . removeItem ( 'oauth_code_verifier' ) ;
137118 sessionStorage . removeItem ( 'oauth_state' ) ;
138119 sessionStorage . removeItem ( 'oauth_processed' ) ;
139-
140- console . log ( '✅ All authentication state cleared' ) ;
141120 }
142121
143122 /**
144123 * Force clear all authentication state and reload the page
145124 * Use this to completely reset authentication for testing
146125 */
147126 public forceResetAuthentication ( ) : void {
148- console . log ( '🔴 Force resetting all authentication...' ) ;
149-
150127 // Clear all storage
151128 localStorage . clear ( ) ;
152129 sessionStorage . clear ( ) ;
@@ -155,7 +132,6 @@ class AuthService {
155132 this . tokenData = null ;
156133 this . tokenRefreshPromise = null ;
157134
158- console . log ( '🔄 Reloading page to complete reset...' ) ;
159135 window . location . href = window . location . origin ;
160136 }
161137
@@ -172,40 +148,41 @@ class AuthService {
172148 try {
173149 localStorage . clear ( ) ;
174150 sessionStorage . clear ( ) ;
175- console . log ( '🧹 Cleared all browser storage' ) ;
151+
176152 } catch ( error ) {
177153 console . warn ( 'Failed to clear storage:' , error ) ;
178154 }
179155
180- // Use TrackMan portal approach: redirect directly to server logout endpoint
181- // This lets the OAuth server handle session clearing and proper logout flow
156+ // Mimic what the portal's /account/ logout endpoint does:
157+ // Redirect to OAuth logout with returnUrl parameter (exactly like portal)
182158 try {
183159 const { ENV_URLS , OAUTH_CONFIG } = await import ( './env' ) ;
184160
185- // Build logout URL with returnUrl parameter (exactly like portal approach)
161+ // This is what we want to return to after logout
186162 const returnUrl = `${ window . location . origin } /?logout_complete=true&t=${ Date . now ( ) } ` ;
163+
164+ // Build the OAuth logout URL exactly like the portal's server would
187165 const logoutUrl = new URL ( `${ ENV_URLS . loginBase } /connect/endsession` ) ;
188166
189- // Add required parameters for proper logout
190167 if ( OAUTH_CONFIG . webClientId ) {
191168 logoutUrl . searchParams . set ( 'client_id' , OAUTH_CONFIG . webClientId ) ;
192169 }
193170
194- // Use both standard OAuth parameter and portal-style returnUrl
195- logoutUrl . searchParams . set ( 'post_logout_redirect_uri' , returnUrl ) ;
196- logoutUrl . searchParams . set ( 'returnUrl' , encodeURIComponent ( returnUrl ) ) ; // Portal style
171+ // Use the same returnUrl parameter format as the portal
172+ logoutUrl . searchParams . set ( 'returnUrl' , returnUrl ) ;
197173
198- console . log ( '🔄 Redirecting to TrackMan logout endpoint:' , logoutUrl . toString ( ) ) ;
174+ console . log ( '🔄 Mimicking portal logout: redirecting to OAuth logout with returnUrl' ) ;
175+ console . log ( '� OAuth logout URL:' , logoutUrl . toString ( ) ) ;
199176 console . log ( '🔍 Return URL after logout:' , returnUrl ) ;
200177
201- // Direct redirect to OAuth server logout (like portal does)
178+ // Redirect to OAuth logout (this is what portal's /account/logout does)
202179 window . location . href = logoutUrl . toString ( ) ;
203180
204181 } catch ( error ) {
205- console . error ( '❌ Failed to build logout URL:' , error ) ;
206- // Fallback to simple logout completion page
182+ console . error ( '❌ Failed to build OAuth logout URL:' , error ) ;
183+ // Fallback
207184 const fallbackUrl = `${ window . location . origin } /?logout_complete=true&t=${ Date . now ( ) } ` ;
208- console . log ( '🔄 Fallback: Redirecting to logout completion page:' , fallbackUrl ) ;
185+
209186 window . location . href = fallbackUrl ;
210187 }
211188 }
@@ -223,12 +200,7 @@ class AuthService {
223200 const scope = this . tokenData . scope || '' ;
224201 const hasUserScopes = scope . includes ( 'openid' ) || scope . includes ( 'profile' ) || scope . includes ( 'email' ) ;
225202
226- console . log ( '🔍 Authentication check:' , {
227- hasToken : ! ! this . tokenData ,
228- isValid : this . isTokenValid ( ) ,
229- scope : scope ,
230- hasUserScopes : hasUserScopes
231- } ) ;
203+
232204
233205 return hasUserScopes ;
234206 }
@@ -247,19 +219,7 @@ class AuthService {
247219 const { buildAuthorizationUrl, generateCodeVerifier, generateState } = await import ( './oauth2-utils' ) ;
248220 const { ENV_URLS , OAUTH_CONFIG } = await import ( './env' ) ;
249221
250- console . log ( '🚀 Starting OAuth login flow...' ) ;
251- console . log ( '🔍 startOAuthLogin called with prompt parameter:' , prompt ) ;
252- if ( prompt ) {
253- console . log ( '🔑 Using prompt parameter:' , prompt , '- This will force login screen' ) ;
254- } else {
255- console . log ( '⚠️ No prompt parameter provided - may auto-login if server session exists' ) ;
256- }
257- console . log ( 'OAuth Config:' , {
258- webClientId : OAUTH_CONFIG . webClientId ,
259- redirectUri : OAUTH_CONFIG . redirectUri ,
260- loginBaseUrl : ENV_URLS . loginBase ,
261- scopes : OAUTH_CONFIG . scopes
262- } ) ;
222+
263223
264224 // Check for required configuration
265225 if ( ! OAUTH_CONFIG . webClientId ) {
@@ -279,10 +239,7 @@ class AuthService {
279239 const codeVerifier = generateCodeVerifier ( ) ;
280240 const state = generateState ( ) ;
281241
282- console . log ( '📝 Generated PKCE parameters:' , {
283- codeVerifierLength : codeVerifier . length ,
284- stateLength : state . length
285- } ) ;
242+
286243
287244 // Store PKCE parameters in sessionStorage for callback
288245 sessionStorage . setItem ( 'oauth_code_verifier' , codeVerifier ) ;
@@ -301,8 +258,7 @@ class AuthService {
301258 prompt
302259 ) ;
303260
304- console . log ( '🔗 Authorization URL:' , authUrl ) ;
305- console . log ( '🌐 About to redirect to TrackMan login server...' ) ;
261+
306262
307263 // Redirect to login server
308264 window . location . href = authUrl ;
@@ -315,7 +271,7 @@ class AuthService {
315271 const { parseAuthorizationCallback, exchangeCodeForToken } = await import ( './oauth2-utils' ) ;
316272 const { ENV_URLS , OAUTH_CONFIG } = await import ( './env' ) ;
317273
318- console . log ( '🔄 Processing OAuth callback...' ) ;
274+
319275
320276 // Parse callback URL
321277 const { code, state, error, error_description } = parseAuthorizationCallback ( callbackUrl ) ;
@@ -367,9 +323,7 @@ class AuthService {
367323 this . tokenData = tokenData ;
368324 this . saveTokenToStorage ( ) ;
369325
370- console . log ( '✅ OAuth login successful!' ) ;
371- console . log ( ' Token expires at:' , tokenData . expiresAt ) ;
372- console . log ( ' Scopes:' , tokenData . scope ) ;
326+
373327
374328 } finally {
375329 // Clean up session storage
0 commit comments