aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-09-24 08:51:00 -0500
committerJP Dillingham <jpdillingham@gmail.com>2021-09-24 08:51:00 -0500
commit9f858530896931d4d14bc332e5416f6a6e8be745 (patch)
tree84668ff0accc8647bf6c3b2b6f756308cec18921 /src
parent72f2000e3826ff9b40dd59f5252ea246b244d539 (diff)
downloadslskd-9f858530896931d4d14bc332e5416f6a6e8be745.tar.gz
map request token from access_token for SignalR hubs
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Startup.cs18
1 files changed, 17 insertions, 1 deletions
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