Compare commits

...

7 Commits

Author SHA1 Message Date
Developer 02
bf12c889f3 feat(Auth.Client): Erstellt, um Client (Consumer) Ereignisse von SignalR zu behandeln.
- Erstellt ClientParams um AuthClient zu konfigurieren.
 - Erstellt ClientEvents, um Ereignisse im Client zu konfigurieren.
2025-01-24 14:51:02 +01:00
Developer 02
a2f4fcfbe0 feat(AuthHub): IAuthClient als Client Typ implementiert.
- SendMessage, SendMessageToCaller und SendMessageToGroup Methoden hinzugefügt.
2025-01-23 15:55:28 +01:00
Developer 02
6245a94f43 fix(IAuthClient): umbenannt in IAuthClient 2025-01-23 15:38:24 +01:00
Developer 02
f562690b19 feat(Abstraktionen): Erstellt, um gemeinsame Schnittstellen zwischen Clients und Hubs für stark typisierte Hubs zu handhaben, um mögliche Fehler zu vermeiden. 2025-01-23 15:36:50 +01:00
Developer 02
54ecf1f4da feat(Auth.Tests): Erstellt, um Einheitstests für alle Projekte zu verwalten. 2025-01-23 14:35:35 +01:00
Developer 02
3a79bb7984 feat(Auth.Client): Erstellung einer Klassenbibliothek zur Handhabung von .net-Client-Diensten für SignalR.
- Microsoft.AspNetCore.SignalR.Client Paket hinzugefügt.
2025-01-23 13:53:57 +01:00
Developer 02
98a4e2ba5c feat(AuthHub): Erstellt, um eine zweidimensionale Verbindung zwischen API und Konsumenten herzustellen.
- Microsoft.AspNetCore.SignalR Paket hinzugefügt.
 - SignalR Dienst hinzugefügt und aktualisiert um AuthHub abzubilden.
2025-01-23 13:46:37 +01:00
11 changed files with 163 additions and 0 deletions

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,6 @@
namespace DigitalData.Auth.Abstractions;
public interface IAuthClient
{
Task ReceiveMessage(string user, string message);
}

View File

@ -0,0 +1,32 @@
using DigitalData.Auth.Abstractions;
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace DigitalData.Auth.Client;
public class AuthClient : IAuthClient
{
private readonly HubConnection _connection;
private readonly ILogger? _logger;
private readonly ClientParams _params;
public AuthClient(IOptions<ClientParams> paramsOptions, HubConnectionBuilder connectionBuilder, ILogger<AuthClient>? logger = null)
{
_connection = connectionBuilder
.WithUrl(paramsOptions.Value.Url)
.Build();
_connection.On<string, string>(nameof(ReceiveMessage), ReceiveMessage);
_logger = logger;
_params = paramsOptions.Value;
}
public async Task StartAsync() => await _connection.StartAsync();
public Task ReceiveMessage(string user, string message) => _params.Events.OnMessageReceived(user, message, _logger);
}

View File

@ -0,0 +1,12 @@
using Microsoft.Extensions.Logging;
namespace DigitalData.Auth.Client
{
public class ClientEvents
{
public Func<string, string, ILogger?, Task> OnMessageReceived { get; set; } = (user, message, logger)
=> Task.Run(
() => logger?.LogInformation("{user}: {message}", user, message)
);
}
}

View File

@ -0,0 +1,8 @@
namespace DigitalData.Auth.Client;
public class ClientParams
{
public required string Url { get; init; }
public readonly ClientEvents Events = new();
}

View File

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DigitalData.Auth.Abstractions\DigitalData.Auth.Abstractions.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<Compile Remove="NewFolder\**" />
<EmbeddedResource Remove="NewFolder\**" />
<None Remove="NewFolder\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DigitalData.Auth.Client\DigitalData.Auth.Client.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>
</Project>

View File

@ -7,6 +7,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{C0123B52-516
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DigitalData.Auth.API", "src\DigitalData.Auth.API\DigitalData.Auth.API.csproj", "{1AF05BC2-6F15-420A-85F6-E6F8740CD557}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DigitalData.Auth.Client", "DigitalData.Auth.Client\DigitalData.Auth.Client.csproj", "{521A2BC0-AEA8-4500-AAA9-1951556EDF9F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DigitalData.Auth.Tests", "DigitalData.Auth.Tests\DigitalData.Auth.Tests.csproj", "{AF517FD9-3EBE-4452-AAEC-DFF17CC270E3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DigitalData.Auth.Abstractions", "DigitalData.Auth.Abstractions\DigitalData.Auth.Abstractions.csproj", "{09FF9BF0-25BB-4EB2-B1B2-6D2873B9538C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -17,12 +23,27 @@ Global
{1AF05BC2-6F15-420A-85F6-E6F8740CD557}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1AF05BC2-6F15-420A-85F6-E6F8740CD557}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1AF05BC2-6F15-420A-85F6-E6F8740CD557}.Release|Any CPU.Build.0 = Release|Any CPU
{521A2BC0-AEA8-4500-AAA9-1951556EDF9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{521A2BC0-AEA8-4500-AAA9-1951556EDF9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{521A2BC0-AEA8-4500-AAA9-1951556EDF9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{521A2BC0-AEA8-4500-AAA9-1951556EDF9F}.Release|Any CPU.Build.0 = Release|Any CPU
{AF517FD9-3EBE-4452-AAEC-DFF17CC270E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AF517FD9-3EBE-4452-AAEC-DFF17CC270E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AF517FD9-3EBE-4452-AAEC-DFF17CC270E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AF517FD9-3EBE-4452-AAEC-DFF17CC270E3}.Release|Any CPU.Build.0 = Release|Any CPU
{09FF9BF0-25BB-4EB2-B1B2-6D2873B9538C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09FF9BF0-25BB-4EB2-B1B2-6D2873B9538C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09FF9BF0-25BB-4EB2-B1B2-6D2873B9538C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09FF9BF0-25BB-4EB2-B1B2-6D2873B9538C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{1AF05BC2-6F15-420A-85F6-E6F8740CD557} = {C0123B52-5168-4C87-98A0-11A220EC392F}
{521A2BC0-AEA8-4500-AAA9-1951556EDF9F} = {C0123B52-5168-4C87-98A0-11A220EC392F}
{AF517FD9-3EBE-4452-AAEC-DFF17CC270E3} = {C0123B52-5168-4C87-98A0-11A220EC392F}
{09FF9BF0-25BB-4EB2-B1B2-6D2873B9538C} = {C0123B52-5168-4C87-98A0-11A220EC392F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4D163037-043C-41AE-AB94-C7314F2C38DA}

View File

@ -14,6 +14,7 @@
<PackageReference Include="DigitalData.Core.Application" Version="3.2.0" />
<PackageReference Include="DigitalData.Core.Security" Version="1.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.12" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.2.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.3.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.3.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
@ -22,4 +23,8 @@
<PackageReference Include="UserManager.Infrastructure" Version="3.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\DigitalData.Auth.Abstractions\DigitalData.Auth.Abstractions.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,16 @@
using DigitalData.Auth.Abstractions;
using Microsoft.AspNetCore.SignalR;
namespace DigitalData.Auth.API.Hubs;
public class AuthHub : Hub<IAuthClient>
{
public async Task SendMessage(string user, string message)
=> await Clients.All.ReceiveMessage(user, message);
public async Task SendMessageToCaller(string user, string message)
=> await Clients.Caller.ReceiveMessage(user, message);
public async Task SendMessageToGroup(string user, string message)
=> await Clients.Group("Auth.API Consumers").ReceiveMessage(user, message);
}

View File

@ -1,5 +1,6 @@
using DigitalData.Auth.API.Config;
using DigitalData.Auth.API.Entities;
using DigitalData.Auth.API.Hubs;
using DigitalData.Auth.API.Services;
using DigitalData.Core.Abstractions.Security;
using DigitalData.Core.Application;
@ -38,6 +39,7 @@ builder.Services.AddJwtSignatureHandler<UserReadDto>(user => new Dictionary<stri
{ JwtRegisteredClaimNames.Iat, DateTimeOffset.UtcNow.ToUnixTimeSeconds() }
});
builder.Services.AddDirectorySearchService(config.GetSection("DirectorySearchOptions"));
builder.Services.AddSignalR();
var cnn_str = builder.Configuration.GetConnectionString("Default") ?? throw new InvalidOperationException("Default connection string is not found.");
@ -135,4 +137,6 @@ app.UseAuthorization();
app.MapControllers();
app.MapHub<AuthHub>("/auth-hub");
app.Run();