From 72f2000e3826ff9b40dd59f5252ea246b244d539 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 24 Sep 2021 08:50:18 -0500 Subject: add auth --- src/slskd/Core/API/Hubs/ApplicationHub.cs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/slskd/Core/API/Hubs/ApplicationHub.cs b/src/slskd/Core/API/Hubs/ApplicationHub.cs index 90dc469f..a22fc7df 100644 --- a/src/slskd/Core/API/Hubs/ApplicationHub.cs +++ b/src/slskd/Core/API/Hubs/ApplicationHub.cs @@ -18,6 +18,7 @@ namespace slskd.Core.API { using System.Threading.Tasks; + using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.SignalR; /// @@ -45,6 +46,7 @@ namespace slskd.Core.API /// /// The application SignalR hub. /// + [Authorize] public class ApplicationHub : Hub { } -- cgit v1.2.3 From 9f858530896931d4d14bc332e5416f6a6e8be745 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 24 Sep 2021 08:51:00 -0500 Subject: map request token from access_token for SignalR hubs --- src/slskd/Startup.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/Startup.cs b/src/slskd/Startup.cs index 47bbae68..2098ee3c 100644 --- a/src/slskd/Startup.cs +++ b/src/slskd/Startup.cs @@ -21,6 +21,7 @@ namespace slskd using System.IO; using System.Linq; using System.Text.Json.Serialization; + using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Mvc.ApiExplorer; @@ -34,7 +35,6 @@ namespace slskd using Prometheus.SystemMetrics; using Serilog; using slskd.Authentication; - using slskd.Core; using slskd.Core.API; using slskd.Cryptography; using slskd.Integrations.FTP; @@ -134,6 +134,22 @@ namespace slskd IssuerSigningKey = JwtSigningKey, ValidateIssuerSigningKey = true, }; + + options.Events = new JwtBearerEvents + { + OnMessageReceived = context => + { + // assign the request token from the access_token query parameter + // but only if the destination is a SignalR hub + // https://docs.microsoft.com/en-us/aspnet/core/signalr/authn-and-authz?view=aspnetcore-5.0 + if (context.HttpContext.Request.Path.StartsWithSegments("/hub")) + { + context.Token = context.Request.Query["access_token"]; + } + + return Task.CompletedTask; + }, + }; }); } else -- cgit v1.2.3