From 6bd41b31893aec782b12c4bb77c75a7f7341e8b3 Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Fri, 1 Nov 2024 08:31:26 -0500 Subject: [PATCH] Authentication provider setup --- KeyCloakIntegration/Directory.Packages.props | 1 + KeyCloakIntegration/src/Web/Program.cs | 7 ++++++- KeyCloakIntegration/src/Web/Web.csproj | 1 + .../src/Web/appsettings.Development.json | 10 ++++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/KeyCloakIntegration/Directory.Packages.props b/KeyCloakIntegration/Directory.Packages.props index e550999..c0b73b1 100644 --- a/KeyCloakIntegration/Directory.Packages.props +++ b/KeyCloakIntegration/Directory.Packages.props @@ -12,6 +12,7 @@ + diff --git a/KeyCloakIntegration/src/Web/Program.cs b/KeyCloakIntegration/src/Web/Program.cs index d731c22..f62818a 100644 --- a/KeyCloakIntegration/src/Web/Program.cs +++ b/KeyCloakIntegration/src/Web/Program.cs @@ -1,4 +1,5 @@ using KeyCloakIntegration.Infrastructure.Data; +using Keycloak.AuthServices.Authentication; var builder = WebApplication.CreateBuilder(args); @@ -8,6 +9,8 @@ builder.Services.AddApplicationServices(); builder.Services.AddInfrastructureServices(builder.Configuration); builder.Services.AddWebServices(); +builder.Services.AddKeycloakWebApiAuthentication(builder.Configuration); +builder.Services.AddAuthorization(); var app = builder.Build(); @@ -42,9 +45,11 @@ app.UseExceptionHandler(options => { }); - app.MapEndpoints(); +app.UseAuthentication(); +app.UseAuthorization(); + app.Run(); public partial class Program { } diff --git a/KeyCloakIntegration/src/Web/Web.csproj b/KeyCloakIntegration/src/Web/Web.csproj index 6e8ef7e..f99ac72 100644 --- a/KeyCloakIntegration/src/Web/Web.csproj +++ b/KeyCloakIntegration/src/Web/Web.csproj @@ -16,6 +16,7 @@ + diff --git a/KeyCloakIntegration/src/Web/appsettings.Development.json b/KeyCloakIntegration/src/Web/appsettings.Development.json index 84308c9..7b1b7fd 100644 --- a/KeyCloakIntegration/src/Web/appsettings.Development.json +++ b/KeyCloakIntegration/src/Web/appsettings.Development.json @@ -6,5 +6,15 @@ "Microsoft.AspNetCore.SpaProxy": "Information", "Microsoft.Hosting.Lifetime": "Information" } + }, + "Keycloak": { + "realm": "Multiplied", + "auth-server-url": "http://localhost:8080/", + "ssl-required": "false", + "resource": "KeyCloakIntegration", + "credentials": { + "secret": "C9ZzKoldRgXoeVwDg0y9BdQlfb643Ppn" + }, + "confidential-port": 0 } }