Refactor namespaces and introduce backdoor authentication

This commit refactors the namespace from `DigitalData.Auth.API.Dto` to `DigitalData.Auth.API.Models` in several files, improving the organization of data structures. A new `Backdoor` class is added to support backdoor authentication, along with a method in `DependencyInjection.cs` to register backdoor configurations. Additionally, `AuthApiParams` configuration is included in `Program.cs`, and a new JSON structure for backdoor users is introduced in `backdoors.json`. These changes enhance the codebase's structure and functionality.
This commit is contained in:
Developer 02 2025-05-09 14:35:15 +02:00
parent bac1fb6054
commit 019abaffa6
7 changed files with 37 additions and 3 deletions

View File

@ -5,7 +5,7 @@ using Microsoft.Extensions.Options;
using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.User;
using DigitalData.Core.Abstractions.Application;
using DigitalData.Auth.API.Dto;
using DigitalData.Auth.API.Models;
using DigitalData.Auth.API.Services.Contracts;
using DigitalData.Auth.API.Entities;
using DigitalData.Core.DTO;

View File

@ -0,0 +1,10 @@
namespace DigitalData.Auth.API.Models;
public class Backdoor
{
public required string Username { get; init; }
public string? Password { get; init; }
public string? PasswordHash { get; init; }
}

View File

@ -1,4 +1,4 @@
namespace DigitalData.Auth.API.Dto
namespace DigitalData.Auth.API.Models
{
public record ConsumerLogin(string Name, string Password);
}

View File

@ -0,0 +1,12 @@
using Microsoft.Extensions.Options;
namespace DigitalData.Auth.API.Models;
public static class DependencyInjection
{
public static IServiceCollection AddBackdoors(this IServiceCollection services, IConfiguration configuration)
{
var backdoors = configuration.Get<IEnumerable<Backdoor>>() ?? Enumerable.Empty<Backdoor>();
return services.AddSingleton(Options.Create(backdoors));
}
}

View File

@ -1,3 +1,3 @@
namespace DigitalData.Auth.API.Dto;
namespace DigitalData.Auth.API.Models;
public record UserLogin(string Password, int? UserId = null, string? Username = null);

View File

@ -24,11 +24,14 @@ try
builder.Configuration.AddJsonFile("consumer-repository.json", true, true);
builder.Configuration.AddJsonFile("consumer-repository.json", true, true);
var config = builder.Configuration;
var apiParams = config.Get<AuthApiParams>() ?? throw new InvalidOperationException("AuthApiOptions is missing or invalid in appsettings.");
// Add services to the container.
builder.Services.Configure<>
builder.Services.Configure<AuthApiParams>(config);
builder.Services.AddAuthService(config);
builder.Services.AddRSAPool(config.GetSection("CryptParams"));

View File

@ -0,0 +1,9 @@
{
"backdoors": [
{
"Username": "Foo",
"Password": null,
"PasswordHash": ""
}
]
}