From 5d8ab2deef0197045baf108bde72b7f358cdf295 Mon Sep 17 00:00:00 2001 From: akastijn Date: Sun, 6 Jul 2025 19:39:46 +0200 Subject: [PATCH 1/6] Add debug log for generated token in `LoginController`. --- .../com/alttd/altitudeweb/controllers/login/LoginController.java | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/src/main/java/com/alttd/altitudeweb/controllers/login/LoginController.java b/backend/src/main/java/com/alttd/altitudeweb/controllers/login/LoginController.java index ecbf207..556b58f 100644 --- a/backend/src/main/java/com/alttd/altitudeweb/controllers/login/LoginController.java +++ b/backend/src/main/java/com/alttd/altitudeweb/controllers/login/LoginController.java @@ -95,6 +95,7 @@ public class LoginController implements LoginApi { } String token = generateToken(cacheEntry.uuid); + log.debug("Generated token for user {} with token {}", cacheEntry.uuid, token); cache.remove(code); From 76cb3cd89c14a9a1c680b7c899cc69fb4079fe8e Mon Sep 17 00:00:00 2001 From: akastijn Date: Sun, 6 Jul 2025 20:09:49 +0200 Subject: [PATCH 2/6] Decode JWT before saving in `AuthService`. --- frontend/src/app/services/auth.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/app/services/auth.service.ts b/frontend/src/app/services/auth.service.ts index f88cc1c..d1bd802 100644 --- a/frontend/src/app/services/auth.service.ts +++ b/frontend/src/app/services/auth.service.ts @@ -31,7 +31,7 @@ export class AuthService { public login(code: string): Observable { return this.loginService.login(code).pipe( tap(jwt => { - this.saveJwt(jwt); + this.saveJwt(atob(jwt)); //Decode jwt from base64 this.isAuthenticatedSubject.next(true); }), catchError(error => { From db394beda6934e1e710d3703d31e546a703229d9 Mon Sep 17 00:00:00 2001 From: akastijn Date: Sun, 6 Jul 2025 20:32:02 +0200 Subject: [PATCH 3/6] Add debug logs for JWT and its decoded value in `AuthService`. --- frontend/src/app/services/auth.service.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/src/app/services/auth.service.ts b/frontend/src/app/services/auth.service.ts index d1bd802..53883e6 100644 --- a/frontend/src/app/services/auth.service.ts +++ b/frontend/src/app/services/auth.service.ts @@ -31,6 +31,8 @@ export class AuthService { public login(code: string): Observable { return this.loginService.login(code).pipe( tap(jwt => { + console.log(jwt); + console.log(atob(jwt)); this.saveJwt(atob(jwt)); //Decode jwt from base64 this.isAuthenticatedSubject.next(true); }), From 4c38b070ea24c5c8cfdd53c9869c385f78f755da Mon Sep 17 00:00:00 2001 From: akastijn Date: Sun, 6 Jul 2025 20:53:03 +0200 Subject: [PATCH 4/6] Handle Blob responses in `AuthService.login` and enhance JWT decoding logic. Add utility methods for Blob detection and conversion. --- frontend/src/app/services/auth.service.ts | 30 ++++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/frontend/src/app/services/auth.service.ts b/frontend/src/app/services/auth.service.ts index 53883e6..ac10c9b 100644 --- a/frontend/src/app/services/auth.service.ts +++ b/frontend/src/app/services/auth.service.ts @@ -1,6 +1,6 @@ import {Injectable} from '@angular/core'; import {LoginService} from '@api'; -import {BehaviorSubject, Observable, throwError} from 'rxjs'; +import {BehaviorSubject, from, Observable, of, switchMap, throwError} from 'rxjs'; import {catchError, tap} from 'rxjs/operators'; import {MatSnackBar} from '@angular/material/snack-bar'; import {JwtHelperService} from '@auth0/angular-jwt'; @@ -25,16 +25,34 @@ export class AuthService { this.checkAuthStatus(); } + private isBlob(value: any): boolean { + return value instanceof Blob; + } + + private getAsBlob(value: any): Blob { + return value as Blob; + } + /** * Attempt to login with the provided code */ public login(code: string): Observable { return this.loginService.login(code).pipe( - tap(jwt => { - console.log(jwt); - console.log(atob(jwt)); - this.saveJwt(atob(jwt)); //Decode jwt from base64 - this.isAuthenticatedSubject.next(true); + switchMap(response => { + if (this.isBlob(response)) { + return from(this.getAsBlob(response).text()).pipe( + tap(jwtText => { + console.log('JWT from Blob:', jwtText); + this.saveJwt(jwtText); + this.isAuthenticatedSubject.next(true); + }) + ); + } else { + console.log('JWT as string:', response); + this.saveJwt(atob(response)); + this.isAuthenticatedSubject.next(true); + return of(response); + } }), catchError(error => { this.snackBar.open('Login failed', '', {duration: 2000}); From 2fc6ba53f65ee3803b3dfd6743e472f7add01fb0 Mon Sep 17 00:00:00 2001 From: akastijn Date: Sun, 6 Jul 2025 20:53:13 +0200 Subject: [PATCH 5/6] Handle Blob responses in `AuthService.login` and enhance JWT decoding logic. Add utility methods for Blob detection and conversion. --- open_api/src/main/resources/schemas/login/login.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/open_api/src/main/resources/schemas/login/login.yml b/open_api/src/main/resources/schemas/login/login.yml index 8e15be0..570bc68 100644 --- a/open_api/src/main/resources/schemas/login/login.yml +++ b/open_api/src/main/resources/schemas/login/login.yml @@ -11,7 +11,7 @@ UserLogin: '200': description: Logged in content: - application/text: + text/plain: schema: type: string description: A JWT token for this user From ace969ba3b2c202549c02164892ed5384aad8a83 Mon Sep 17 00:00:00 2001 From: akastijn Date: Sun, 6 Jul 2025 21:00:52 +0200 Subject: [PATCH 6/6] Remove Blob handling logic from `AuthService.login` and simplify JWT processing. --- frontend/src/app/services/auth.service.ts | 28 ++++------------------- 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/frontend/src/app/services/auth.service.ts b/frontend/src/app/services/auth.service.ts index ac10c9b..f88cc1c 100644 --- a/frontend/src/app/services/auth.service.ts +++ b/frontend/src/app/services/auth.service.ts @@ -1,6 +1,6 @@ import {Injectable} from '@angular/core'; import {LoginService} from '@api'; -import {BehaviorSubject, from, Observable, of, switchMap, throwError} from 'rxjs'; +import {BehaviorSubject, Observable, throwError} from 'rxjs'; import {catchError, tap} from 'rxjs/operators'; import {MatSnackBar} from '@angular/material/snack-bar'; import {JwtHelperService} from '@auth0/angular-jwt'; @@ -25,34 +25,14 @@ export class AuthService { this.checkAuthStatus(); } - private isBlob(value: any): boolean { - return value instanceof Blob; - } - - private getAsBlob(value: any): Blob { - return value as Blob; - } - /** * Attempt to login with the provided code */ public login(code: string): Observable { return this.loginService.login(code).pipe( - switchMap(response => { - if (this.isBlob(response)) { - return from(this.getAsBlob(response).text()).pipe( - tap(jwtText => { - console.log('JWT from Blob:', jwtText); - this.saveJwt(jwtText); - this.isAuthenticatedSubject.next(true); - }) - ); - } else { - console.log('JWT as string:', response); - this.saveJwt(atob(response)); - this.isAuthenticatedSubject.next(true); - return of(response); - } + tap(jwt => { + this.saveJwt(jwt); + this.isAuthenticatedSubject.next(true); }), catchError(error => { this.snackBar.open('Login failed', '', {duration: 2000});