using Microsoft.Extensions.DependencyInjection; using Syski.Data; using System; using System.Linq; namespace Syski.WebSocket.Services.WebSockets.Actions.Handlers { public class SystemAuthenticationHandler : AuthenticationHandler { public SystemAuthenticationHandler(Action action, WebSocketConnection webSocketConnection, IServiceProvider serviceProvider) : base(action, webSocketConnection, serviceProvider) { } public override void HandleAction() { using (var serviceScope = serviceProvider.GetRequiredService().CreateScope()) { var context = serviceScope.ServiceProvider.GetService(); var system = context.Systems.FirstOrDefault(s => s.Id == Guid.Parse((string) action.properties.SelectToken("system")) && s.Secret == (string) action.properties.SelectToken("secret")); if (system != null) { WebSocketManager websocketManager = serviceProvider.GetService(); websocketManager.SetSystemLink(webSocketConnection.Id, Guid.Parse((string) action.properties.SelectToken("system"))); base.HandleAction(); } } } } }