From e530cf735a47f02bbdd467c20546f41983bd1993 Mon Sep 17 00:00:00 2001 From: Leon Hoppe Date: Tue, 24 Dec 2024 12:19:32 +0100 Subject: [PATCH] added option to disable auth endpoints --- HopFrame.sln.DotSettings.user | 2 ++ docs/api/endpoints.md | 21 ------------------- .../Extensions/ServiceCollectionExtensions.cs | 8 +++---- .../Models/HopFrameApiModuleConfig.cs | 1 + .../HopFrameAuthenticationExtensions.cs | 2 +- .../ServiceCollectionExtensions.cs | 1 - 6 files changed, 8 insertions(+), 27 deletions(-) delete mode 100644 docs/api/endpoints.md diff --git a/HopFrame.sln.DotSettings.user b/HopFrame.sln.DotSettings.user index 34c8e0d..ee120fc 100644 --- a/HopFrame.sln.DotSettings.user +++ b/HopFrame.sln.DotSettings.user @@ -6,8 +6,10 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded <AssemblyExplorer> diff --git a/docs/api/endpoints.md b/docs/api/endpoints.md deleted file mode 100644 index c02a3bc..0000000 --- a/docs/api/endpoints.md +++ /dev/null @@ -1,21 +0,0 @@ -# HopFrame Endpoints -HopFrame currently only supports endpoints for authentication out of the box. - -> **Hint:** with the help of the [repositories](../repositories.md) you can very easily create missing endpoints for HopFrame components yourself. - -## All currently supported endpoints - -> **Hint:** you can use the build-in [swagger](https://swagger.io/) ui to explore and test all endpoints of your application __including__ HopFrame endpoints. - -### SecurityController -Base endpoint: `/api/v1/authentication`\ -**Important:** All primitive data types (including `string`) are return as a [`SingleValueResult`](./models.md#SingleValueResult) - - -| Method | Endpoint | Payload | Returns | -|--------|---------------|--------------------------------------------------------------|-----------------------| -| PUT | /login | [UserLogin](../models.md#UserLogin) | access token (string) | -| POST | /register | [UserRegister](../models.md#UserRegister) | access token (string) | -| GET | /authenticate | | access token (string) | -| DELETE | /logout | | | -| DELETE | /delete | [UserPasswordValidation](./models.md#UserPasswordValidation) | | diff --git a/src/HopFrame.Api/Extensions/ServiceCollectionExtensions.cs b/src/HopFrame.Api/Extensions/ServiceCollectionExtensions.cs index 3f7a265..156b438 100644 --- a/src/HopFrame.Api/Extensions/ServiceCollectionExtensions.cs +++ b/src/HopFrame.Api/Extensions/ServiceCollectionExtensions.cs @@ -19,7 +19,7 @@ public static class ServiceCollectionExtensions { /// /// The service provider to add the services to /// The configuration used to configure HopFrame authentication - /// Configuration for how the HopFrame services get set up + /// Configuration for how the HopFrame services are set up /// The data source for all HopFrame entities public static void AddHopFrame(this IServiceCollection services, ConfigurationManager configuration, HopFrameApiModuleConfig config = null) where TDbContext : HopDbContextBase { config ??= new(); @@ -30,10 +30,10 @@ public static class ServiceCollectionExtensions { controllers.AddRange([typeof(UserController), typeof(GroupController)]); var defaultAuthenticationSection = configuration.GetSection("HopFrame:Authentication:DefaultAuthentication"); - if (!defaultAuthenticationSection.Exists() || configuration.GetValue("HopFrame:Authentication:DefaultAuthentication")) + if ((!defaultAuthenticationSection.Exists() || configuration.GetValue("HopFrame:Authentication:DefaultAuthentication")) && config.ExposeAuthEndpoints) controllers.Add(typeof(AuthController)); - if (configuration.GetValue("HopFrame:Authentication:OpenID:Enabled")) { + if (configuration.GetValue("HopFrame:Authentication:OpenID:Enabled") && config.ExposeAuthEndpoints) { IOpenIdAccessor.DefaultCallback = OpenIdController.DefaultCallback; controllers.Add(typeof(OpenIdController)); } @@ -47,7 +47,7 @@ public static class ServiceCollectionExtensions { /// /// The service provider to add the services to /// The configuration used to configure HopFrame authentication - /// Configuration for how the HopFrame services get set up + /// Configuration for how the HopFrame services are set up /// The data source for all HopFrame entities public static void AddHopFrameNoEndpoints(this IServiceCollection services, ConfigurationManager configuration, HopFrameApiModuleConfig config = null) where TDbContext : HopDbContextBase { config ??= new(); diff --git a/src/HopFrame.Api/Models/HopFrameApiModuleConfig.cs b/src/HopFrame.Api/Models/HopFrameApiModuleConfig.cs index 85afc5b..c0bd3e3 100644 --- a/src/HopFrame.Api/Models/HopFrameApiModuleConfig.cs +++ b/src/HopFrame.Api/Models/HopFrameApiModuleConfig.cs @@ -4,4 +4,5 @@ namespace HopFrame.Api.Models; public class HopFrameApiModuleConfig : HopFrameConfig { public bool ExposeModelEndpoints { get; set; } = true; + public bool ExposeAuthEndpoints { get; set; } = true; } \ No newline at end of file diff --git a/src/HopFrame.Security/Authentication/HopFrameAuthenticationExtensions.cs b/src/HopFrame.Security/Authentication/HopFrameAuthenticationExtensions.cs index 90b0387..dd5eecb 100644 --- a/src/HopFrame.Security/Authentication/HopFrameAuthenticationExtensions.cs +++ b/src/HopFrame.Security/Authentication/HopFrameAuthenticationExtensions.cs @@ -21,7 +21,7 @@ public static class HopFrameAuthenticationExtensions { /// /// The service provider to add the services to /// The configuration used to configure HopFrame authentication - /// Configuration for how the HopFrame services get set up + /// Configuration for how the HopFrame services are set up /// public static IServiceCollection AddHopFrameAuthentication(this IServiceCollection services, ConfigurationManager configuration, HopFrameConfig config = null) { config ??= new HopFrameConfig(); diff --git a/src/HopFrame.Web/ServiceCollectionExtensions.cs b/src/HopFrame.Web/ServiceCollectionExtensions.cs index c6b62fa..6282a29 100644 --- a/src/HopFrame.Web/ServiceCollectionExtensions.cs +++ b/src/HopFrame.Web/ServiceCollectionExtensions.cs @@ -15,7 +15,6 @@ namespace HopFrame.Web; public static class ServiceCollectionExtensions { public static IServiceCollection AddHopFrame(this IServiceCollection services, ConfigurationManager configuration, HopFrameWebModuleConfig config = null) where TDbContext : HopDbContextBase { config ??= new HopFrameWebModuleConfig(); - services.AddHttpClient(); services.AddHopFrameRepositories(); services.AddScoped(); services.AddTransient();