From aa79d60e6c29bd6795474fc4eaf89647bd565f96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20H=C3=B6rner?= Date: Fri, 13 Jun 2025 13:20:47 +0200 Subject: [PATCH 1/4] Fix todo in authentication interceptor --- .../authentication.interceptor.spec.ts | 13 +++++++++++++ .../interceptors/authentication.interceptor.ts | 15 ++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 src/Turnierplan.App/Client/src/app/core/interceptors/authentication.interceptor.spec.ts diff --git a/src/Turnierplan.App/Client/src/app/core/interceptors/authentication.interceptor.spec.ts b/src/Turnierplan.App/Client/src/app/core/interceptors/authentication.interceptor.spec.ts new file mode 100644 index 00000000..11003000 --- /dev/null +++ b/src/Turnierplan.App/Client/src/app/core/interceptors/authentication.interceptor.spec.ts @@ -0,0 +1,13 @@ +import { AuthenticationInterceptor } from './authentication.interceptor'; + +describe('AuthenticationInterceptor', () => { + it('should determine correctly whether authentication is required or not', () => { + expect(AuthenticationInterceptor.doesPathRequireAuthentication(`/api`)).toBeTrue(); + expect(AuthenticationInterceptor.doesPathRequireAuthentication(`/api/test`)).toBeTrue(); + expect(AuthenticationInterceptor.doesPathRequireAuthentication(`/api/test/identity`)).toBeTrue(); + expect(AuthenticationInterceptor.doesPathRequireAuthentication(`/api/identity`)).toBeFalse(); + expect(AuthenticationInterceptor.doesPathRequireAuthentication(`/api/identity/test`)).toBeFalse(); + expect(AuthenticationInterceptor.doesPathRequireAuthentication(`/something/api`)).toBeFalse(); + expect(AuthenticationInterceptor.doesPathRequireAuthentication(`/something/api/identity`)).toBeFalse(); + }); +}); diff --git a/src/Turnierplan.App/Client/src/app/core/interceptors/authentication.interceptor.ts b/src/Turnierplan.App/Client/src/app/core/interceptors/authentication.interceptor.ts index 9dc675e5..6c15ab3a 100644 --- a/src/Turnierplan.App/Client/src/app/core/interceptors/authentication.interceptor.ts +++ b/src/Turnierplan.App/Client/src/app/core/interceptors/authentication.interceptor.ts @@ -6,17 +6,14 @@ import { AuthenticationService } from '../services/authentication.service'; @Injectable() export class AuthenticationInterceptor implements HttpInterceptor { - private readonly apiRoutesPrefix = `${window.origin}/api`; - private readonly identityRoutesPrefix = `${window.origin}/api/identity`; - constructor(private readonly authenticationService: AuthenticationService) {} public intercept(request: HttpRequest, next: HttpHandler): Observable> { - // IDEA: The check below could maybe be improved with a regex. Also, the API route for changing the user data also - // requires authentication even though its path '/api/identity/user-data/' is excluded by the logic below. - const requireAuthentication = request.url.startsWith(this.apiRoutesPrefix) && !request.url.startsWith(this.identityRoutesPrefix); + if (!request.url.startsWith(window.origin)) { + return next.handle(request); + } - if (!requireAuthentication) { + if (!AuthenticationInterceptor.doesPathRequireAuthentication(request.url.substring(window.origin.length))) { return next.handle(request); } @@ -30,4 +27,8 @@ export class AuthenticationInterceptor implements HttpInterceptor { }) ); } + + public static doesPathRequireAuthentication(path: string): boolean { + return /^\/api(?!\/identity)/.test(path); + } } From 07f09e08e2a0dc60eaf99fb7a43b50667d71d634 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20H=C3=B6rner?= Date: Fri, 13 Jun 2025 13:31:27 +0200 Subject: [PATCH 2/4] Some layout improvements --- src/Turnierplan.App/Application.cs | 12 ++++++++++++ src/Turnierplan.App/Pages/Shared/_Layout.cshtml | 6 +++--- src/Turnierplan.App/wwwroot/assets/turnierplan.css | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 src/Turnierplan.App/Application.cs diff --git a/src/Turnierplan.App/Application.cs b/src/Turnierplan.App/Application.cs new file mode 100644 index 00000000..3d84015d --- /dev/null +++ b/src/Turnierplan.App/Application.cs @@ -0,0 +1,12 @@ +namespace Turnierplan.App; + +internal static class Application +{ + public static readonly string Version; + + static Application() + { + var assemblyVersion = typeof(Application).Assembly.GetName().Version?.ToString(); + Version = assemblyVersion?[..assemblyVersion.LastIndexOf('.')] ?? "?.?.?"; + } +} diff --git a/src/Turnierplan.App/Pages/Shared/_Layout.cshtml b/src/Turnierplan.App/Pages/Shared/_Layout.cshtml index 3ced4349..6839e30e 100644 --- a/src/Turnierplan.App/Pages/Shared/_Layout.cshtml +++ b/src/Turnierplan.App/Pages/Shared/_Layout.cshtml @@ -42,11 +42,11 @@
-