From 9b739b02f6e4633cea4abaff37e250c6e38e945c Mon Sep 17 00:00:00 2001 From: Christophe Date: Mon, 13 Apr 2026 23:59:20 +0200 Subject: [PATCH] Integrer l'authentification Keycloak dans l'application --- ChessCubing.App/Components/SiteMenu.razor | 399 +++++++++++++----- ChessCubing.App/Layout/MainLayout.razor | 3 +- .../Models/Auth/AuthSessionResponse.cs | 16 + ChessCubing.App/Models/Auth/LoginRequest.cs | 8 + .../Models/Auth/RegisterRequest.cs | 16 + ChessCubing.App/Pages/Authentication.razor | 101 +---- ChessCubing.App/Program.cs | 47 +-- .../AppAuthenticationStateProvider.cs | 101 +++++ ChessCubing.Server/Auth/AuthContracts.cs | 59 +++ .../Auth/KeycloakAuthOptions.cs | 18 + .../Auth/KeycloakAuthService.cs | 334 +++++++++++++++ ChessCubing.Server/ChessCubing.Server.csproj | 11 + ChessCubing.Server/Program.cs | 173 ++++++++ Dockerfile.auth | 17 + README.md | 31 +- docker-compose.yml | 42 +- keycloak/realm/chesscubing-realm.json | 2 +- keycloak/scripts/init-config.sh | 43 ++ nginx.conf | 10 + styles.css | 46 +- 20 files changed, 1201 insertions(+), 276 deletions(-) create mode 100644 ChessCubing.App/Models/Auth/AuthSessionResponse.cs create mode 100644 ChessCubing.App/Models/Auth/LoginRequest.cs create mode 100644 ChessCubing.App/Models/Auth/RegisterRequest.cs create mode 100644 ChessCubing.App/Services/AppAuthenticationStateProvider.cs create mode 100644 ChessCubing.Server/Auth/AuthContracts.cs create mode 100644 ChessCubing.Server/Auth/KeycloakAuthOptions.cs create mode 100644 ChessCubing.Server/Auth/KeycloakAuthService.cs create mode 100644 ChessCubing.Server/ChessCubing.Server.csproj create mode 100644 ChessCubing.Server/Program.cs create mode 100644 Dockerfile.auth create mode 100644 keycloak/scripts/init-config.sh diff --git a/ChessCubing.App/Components/SiteMenu.razor b/ChessCubing.App/Components/SiteMenu.razor index dceb6a8..0c7c21f 100644 --- a/ChessCubing.App/Components/SiteMenu.razor +++ b/ChessCubing.App/Components/SiteMenu.razor @@ -1,8 +1,12 @@ +@using System.ComponentModel.DataAnnotations +@using System.Net.Http.Json @using System.Security.Claims -@implements IAsyncDisposable -@inject AuthenticationStateProvider AuthenticationStateProvider +@using ChessCubing.App.Models.Auth +@using Microsoft.AspNetCore.Components.Authorization +@implements IDisposable +@inject AppAuthenticationStateProvider AuthenticationStateProvider +@inject HttpClient Http @inject NavigationManager Navigation -@inject IJSRuntime JS