Removed old manual access token checking and switched to asp.net jwt handling. Removed old console subscriber handling and switched to full signal r solution + asp.net core auth

This commit is contained in:
2025-04-13 00:09:06 +02:00
parent ec0c336825
commit 36cbc83c63
15 changed files with 181 additions and 380 deletions

View File

@@ -1,11 +1,13 @@
using Docker.DotNet;
using Docker.DotNet.Models;
using Microsoft.AspNetCore.SignalR;
using MoonCore.Attributes;
using MoonCore.Exceptions;
using MoonCore.Models;
using MoonlightServers.Daemon.Abstractions;
using MoonlightServers.Daemon.Enums;
using MoonlightServers.Daemon.Extensions;
using MoonlightServers.Daemon.Http.Hubs;
using MoonlightServers.Daemon.Models.Cache;
using MoonlightServers.DaemonShared.PanelSide.Http.Responses;
@@ -19,6 +21,7 @@ public class ServerService : IHostedLifecycleService
private readonly RemoteService RemoteService;
private readonly IServiceProvider ServiceProvider;
private readonly ILoggerFactory LoggerFactory;
private readonly IHubContext<ServerWebSocketHub> WebSocketHub;
private CancellationTokenSource Cancellation = new();
private bool IsInitialized = false;
@@ -26,13 +29,15 @@ public class ServerService : IHostedLifecycleService
RemoteService remoteService,
ILogger<ServerService> logger,
IServiceProvider serviceProvider,
ILoggerFactory loggerFactory
ILoggerFactory loggerFactory,
IHubContext<ServerWebSocketHub> webSocketHub
)
{
RemoteService = remoteService;
Logger = logger;
ServiceProvider = serviceProvider;
LoggerFactory = loggerFactory;
WebSocketHub = webSocketHub;
}
public async Task Initialize() //TODO: Add initialize call from panel
@@ -190,7 +195,8 @@ public class ServerService : IHostedLifecycleService
var server = new Server(
LoggerFactory.CreateLogger($"Server {serverConfiguration.Id}"),
ServiceProvider,
serverConfiguration
serverConfiguration,
WebSocketHub
);
await server.Initialize(existingContainers);

View File

@@ -1,68 +0,0 @@
using Microsoft.AspNetCore.SignalR;
using MoonCore.Attributes;
using MoonlightServers.Daemon.Helpers;
using MoonlightServers.Daemon.Http.Hubs;
namespace MoonlightServers.Daemon.Services;
[Singleton]
public class ServerWebSocketService
{
private readonly ILogger<ServerWebSocketService> Logger;
private readonly IServiceProvider ServiceProvider;
private readonly Dictionary<string, ServerWebSocketConnection> Connections = new();
public ServerWebSocketService(
ILogger<ServerWebSocketService> logger,
IServiceProvider serviceProvider
)
{
Logger = logger;
ServiceProvider = serviceProvider;
}
public async Task InitializeClient(HubCallerContext context)
{
var connection = new ServerWebSocketConnection(
ServiceProvider.GetRequiredService<ServerService>(),
ServiceProvider.GetRequiredService<ILogger<ServerWebSocketConnection>>(),
ServiceProvider.GetRequiredService<AccessTokenHelper>(),
ServiceProvider.GetRequiredService<IHubContext<ServerWebSocketHub>>()
);
lock (Connections)
Connections[context.ConnectionId] = connection;
await connection.Initialize(context);
}
public async Task AuthenticateClient(HubCallerContext context, string accessToken)
{
ServerWebSocketConnection? connection;
lock (Connections)
connection = Connections.GetValueOrDefault(context.ConnectionId);
if(connection == null)
return;
await connection.Authenticate(context, accessToken);
}
public async Task DestroyClient(HubCallerContext context)
{
ServerWebSocketConnection? connection;
lock (Connections)
connection = Connections.GetValueOrDefault(context.ConnectionId);
if(connection == null)
return;
await connection.Destroy(context);
lock (Connections)
Connections.Remove(context.ConnectionId);
}
}