aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-09-25 18:19:05 -0500
committerGitHub <noreply@github.com>2021-09-25 18:19:05 -0500
commit02d43eb0b04a0164c77349aa03834dc22b65bb29 (patch)
tree84668ff0accc8647bf6c3b2b6f756308cec18921 /src
parentbc17beab782c8c9b9c04035a31c435d4d9c42596 (diff)
parent9f858530896931d4d14bc332e5416f6a6e8be745 (diff)
downloadslskd-02d43eb0b04a0164c77349aa03834dc22b65bb29.tar.gz
Merge pull request #204 from slskd/signalr-security
Configure SignalR security
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Core/API/Hubs/ApplicationHub.cs2
-rw-r--r--src/slskd/Startup.cs18
2 files changed, 19 insertions, 1 deletions
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;
/// <summary>
@@ -45,6 +46,7 @@ namespace slskd.Core.API
/// <summary>
/// The application SignalR hub.
/// </summary>
+ [Authorize]
public class ApplicationHub : Hub
{
}
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