feat(Melder): Erstellt, um aktuelle Schlüssel an den Kunden zu senden

This commit is contained in:
Developer 02 2025-02-11 09:38:11 +01:00
parent 5ab1f24ce5
commit 484cc86a29
6 changed files with 40 additions and 19 deletions

View File

@ -2,5 +2,5 @@
public interface IAuthListenHandler
{
Task ReceiveKeyAsync(string topic, string key);
Task ReceiveKeyAsync(string name, string value);
}

View File

@ -5,12 +5,6 @@ namespace DigitalData.Auth.API.Hubs;
public class AuthHub : Hub<IAuthListenHandler>, IAuthSenderHandler
{
public async Task SendKeyAsync(string user, string message)
=> await Clients.All.ReceiveKeyAsync(user, message);
public async Task SendMessageToCaller(string user, string message)
=> await Clients.Caller.ReceiveKeyAsync(user, message);
public async Task SendMessageToGroup(string user, string message)
=> await Clients.Group("Auth.API Consumers").ReceiveKeyAsync(user, message);
public async Task SendKeyAsync(string name, string value)
=> await Clients.All.ReceiveKeyAsync(name, value);
}

View File

@ -22,7 +22,7 @@ var apiParams = config.Get<AuthApiParams>() ?? throw new InvalidOperationExcepti
// Add services to the container.
builder.Services.Configure<AuthApiParams>(config);
builder.Services.AddConsumerService(config);
builder.Services.AddAuthService(config);
builder.Services.AddCryptoFactory(config.GetSection("CryptParams"));
builder.Services.AddJwtSignatureHandler<Consumer>(api => new Dictionary<string, object>
{

View File

@ -0,0 +1,6 @@
namespace DigitalData.Auth.API.Services.Contracts;
public interface INotifier
{
Task UpdateKeyAsync(string name, string value);
}

View File

@ -2,16 +2,16 @@
using DigitalData.Auth.API.Services.Contracts;
using Microsoft.Extensions.Options;
namespace DigitalData.Auth.API.Services
namespace DigitalData.Auth.API.Services;
public static class DIExtensions
{
public static class DIExtensions
public static IServiceCollection AddAuthService(this IServiceCollection services, IConfiguration configuration, string key = "Consumers")
{
public static IServiceCollection AddConsumerService(this IServiceCollection services, IConfiguration configuration, string key = "Consumers")
{
var consumers = configuration.GetSection(key).Get<IEnumerable<Consumer>>() ?? throw new InvalidOperationException($"No Consumer list found in {key} in configuration.");
services.AddSingleton(Options.Create(consumers));
services.AddSingleton<IConsumerService, ConfiguredConsumerService>();
return services;
}
var consumers = configuration.GetSection(key).Get<IEnumerable<Consumer>>() ?? throw new InvalidOperationException($"No Consumer list found in {key} in configuration.");
services.AddSingleton(Options.Create(consumers));
services.AddSingleton<IConsumerService, ConfiguredConsumerService>();
services.AddSingleton<INotifier, Notifier>();
return services;
}
}

View File

@ -0,0 +1,21 @@
using DigitalData.Auth.Abstractions;
using DigitalData.Auth.API.Hubs;
using DigitalData.Auth.API.Services.Contracts;
using Microsoft.AspNetCore.SignalR;
namespace DigitalData.Auth.API.Services;
public class Notifier : INotifier
{
private readonly IHubContext<AuthHub, IAuthListenHandler> _hubContext;
public Notifier(IHubContext<AuthHub, IAuthListenHandler> hubContext)
{
_hubContext = hubContext;
}
public async Task UpdateKeyAsync(string name, string value)
{
await _hubContext.Clients.All.ReceiveKeyAsync(name, value);
}
}