fix websocket session auth and header parsing for jellyfin dashboard

This commit is contained in:
2026-02-02 20:41:25 -05:00
parent b40349206d
commit 83063f594a
3 changed files with 100 additions and 27 deletions

View File

@@ -89,17 +89,28 @@ public class WebSocketProxyMiddleware
// Connect to Jellyfin WebSocket
serverWebSocket = new ClientWebSocket();
// Forward authentication headers
if (context.Request.Headers.TryGetValue("Authorization", out var authHeader))
{
serverWebSocket.Options.SetRequestHeader("Authorization", authHeader.ToString());
_logger.LogWarning("🔑 WEBSOCKET: Forwarded Authorization header");
}
else if (context.Request.Headers.TryGetValue("X-Emby-Authorization", out var embyAuthHeader))
// Forward authentication headers - check X-Emby-Authorization FIRST
// Most Jellyfin clients use X-Emby-Authorization, not Authorization
if (context.Request.Headers.TryGetValue("X-Emby-Authorization", out var embyAuthHeader))
{
serverWebSocket.Options.SetRequestHeader("X-Emby-Authorization", embyAuthHeader.ToString());
_logger.LogWarning("🔑 WEBSOCKET: Forwarded X-Emby-Authorization header");
}
else if (context.Request.Headers.TryGetValue("Authorization", out var authHeader))
{
var authValue = authHeader.ToString();
// If it's a MediaBrowser auth header, use X-Emby-Authorization
if (authValue.Contains("MediaBrowser", StringComparison.OrdinalIgnoreCase))
{
serverWebSocket.Options.SetRequestHeader("X-Emby-Authorization", authValue);
_logger.LogWarning("🔑 WEBSOCKET: Converted Authorization to X-Emby-Authorization header");
}
else
{
serverWebSocket.Options.SetRequestHeader("Authorization", authValue);
_logger.LogWarning("🔑 WEBSOCKET: Forwarded Authorization header");
}
}
// Set user agent
serverWebSocket.Options.SetRequestHeader("User-Agent", "Allstarr/1.0");