diff --git a/DigitalData.Auth.Abstractions/IAuthListenHandler.cs b/DigitalData.Auth.Abstractions/IAuthListenHandler.cs index 0aeb7b4..925ff9a 100644 --- a/DigitalData.Auth.Abstractions/IAuthListenHandler.cs +++ b/DigitalData.Auth.Abstractions/IAuthListenHandler.cs @@ -2,5 +2,5 @@ public interface IAuthListenHandler { - Task ReceiveKeyAsync(string topic, string key); + Task ReceiveKeyAsync(string name, string value); } \ No newline at end of file diff --git a/src/DigitalData.Auth.API/Hubs/AuthHub.cs b/src/DigitalData.Auth.API/Hubs/AuthHub.cs index 8ab3c6f..189bd06 100644 --- a/src/DigitalData.Auth.API/Hubs/AuthHub.cs +++ b/src/DigitalData.Auth.API/Hubs/AuthHub.cs @@ -5,12 +5,6 @@ namespace DigitalData.Auth.API.Hubs; public class AuthHub : Hub, 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); } \ No newline at end of file diff --git a/src/DigitalData.Auth.API/Program.cs b/src/DigitalData.Auth.API/Program.cs index 81f6330..da03833 100644 --- a/src/DigitalData.Auth.API/Program.cs +++ b/src/DigitalData.Auth.API/Program.cs @@ -22,7 +22,7 @@ var apiParams = config.Get() ?? throw new InvalidOperationExcepti // Add services to the container. builder.Services.Configure(config); -builder.Services.AddConsumerService(config); +builder.Services.AddAuthService(config); builder.Services.AddCryptoFactory(config.GetSection("CryptParams")); builder.Services.AddJwtSignatureHandler(api => new Dictionary { diff --git a/src/DigitalData.Auth.API/Services/Contracts/INotifier.cs b/src/DigitalData.Auth.API/Services/Contracts/INotifier.cs new file mode 100644 index 0000000..fb0f783 --- /dev/null +++ b/src/DigitalData.Auth.API/Services/Contracts/INotifier.cs @@ -0,0 +1,6 @@ +namespace DigitalData.Auth.API.Services.Contracts; + +public interface INotifier +{ + Task UpdateKeyAsync(string name, string value); +} diff --git a/src/DigitalData.Auth.API/Services/DIExtensions.cs b/src/DigitalData.Auth.API/Services/DIExtensions.cs index 5048900..af87acc 100644 --- a/src/DigitalData.Auth.API/Services/DIExtensions.cs +++ b/src/DigitalData.Auth.API/Services/DIExtensions.cs @@ -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>() ?? throw new InvalidOperationException($"No Consumer list found in {key} in configuration."); - services.AddSingleton(Options.Create(consumers)); - services.AddSingleton(); - return services; - } + var consumers = configuration.GetSection(key).Get>() ?? throw new InvalidOperationException($"No Consumer list found in {key} in configuration."); + services.AddSingleton(Options.Create(consumers)); + services.AddSingleton(); + services.AddSingleton(); + return services; } } \ No newline at end of file diff --git a/src/DigitalData.Auth.API/Services/Notifier.cs b/src/DigitalData.Auth.API/Services/Notifier.cs new file mode 100644 index 0000000..90aa85b --- /dev/null +++ b/src/DigitalData.Auth.API/Services/Notifier.cs @@ -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 _hubContext; + + public Notifier(IHubContext hubContext) + { + _hubContext = hubContext; + } + + public async Task UpdateKeyAsync(string name, string value) + { + await _hubContext.Clients.All.ReceiveKeyAsync(name, value); + } +}