mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-09 23:55:10 -05:00
add debug logging for websocket auth headers
Some checks failed
CI / build-and-test (push) Has been cancelled
Some checks failed
CI / build-and-test (push) Has been cancelled
This commit is contained in:
@@ -60,6 +60,10 @@ public class JellyfinSessionManager : IDisposable
|
|||||||
|
|
||||||
_logger.LogWarning("🔧 SESSION: Creating new session for device: {DeviceId} ({Client} on {Device})", deviceId, client, device);
|
_logger.LogWarning("🔧 SESSION: Creating new session for device: {DeviceId} ({Client} on {Device})", deviceId, client, device);
|
||||||
|
|
||||||
|
// Log the headers we received for debugging
|
||||||
|
_logger.LogWarning("🔍 SESSION: Headers received for session creation: {Headers}",
|
||||||
|
string.Join(", ", headers.Select(h => $"{h.Key}={h.Value.ToString().Substring(0, Math.Min(30, h.Value.ToString().Length))}...")));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Post session capabilities to Jellyfin - this creates the session
|
// Post session capabilities to Jellyfin - this creates the session
|
||||||
@@ -204,16 +208,21 @@ public class JellyfinSessionManager : IDisposable
|
|||||||
// The client's token is passed via X-Emby-Authorization header
|
// The client's token is passed via X-Emby-Authorization header
|
||||||
// Using api_key would create a session for the server/admin, not the actual user's client
|
// Using api_key would create a session for the server/admin, not the actual user's client
|
||||||
|
|
||||||
_logger.LogWarning("🔗 WEBSOCKET: Connecting to Jellyfin for device {DeviceId}: {Url}", deviceId, jellyfinWsUrl);
|
|
||||||
|
|
||||||
webSocket = new ClientWebSocket();
|
webSocket = new ClientWebSocket();
|
||||||
session.WebSocket = webSocket;
|
session.WebSocket = webSocket;
|
||||||
|
|
||||||
|
// Log available headers for debugging
|
||||||
|
_logger.LogWarning("🔍 WEBSOCKET: Available headers for {DeviceId}: {Headers}",
|
||||||
|
deviceId, string.Join(", ", headers.Keys));
|
||||||
|
|
||||||
// Forward authentication headers from the CLIENT - this is critical for session to appear under the right user
|
// Forward authentication headers from the CLIENT - this is critical for session to appear under the right user
|
||||||
|
bool authFound = false;
|
||||||
if (headers.TryGetValue("X-Emby-Authorization", out var embyAuth))
|
if (headers.TryGetValue("X-Emby-Authorization", out var embyAuth))
|
||||||
{
|
{
|
||||||
webSocket.Options.SetRequestHeader("X-Emby-Authorization", embyAuth.ToString());
|
webSocket.Options.SetRequestHeader("X-Emby-Authorization", embyAuth.ToString());
|
||||||
_logger.LogWarning("🔑 WEBSOCKET: Forwarded X-Emby-Authorization for {DeviceId}", deviceId);
|
_logger.LogWarning("🔑 WEBSOCKET: Using X-Emby-Authorization for {DeviceId}: {Auth}",
|
||||||
|
deviceId, embyAuth.ToString().Length > 50 ? embyAuth.ToString()[..50] + "..." : embyAuth.ToString());
|
||||||
|
authFound = true;
|
||||||
}
|
}
|
||||||
else if (headers.TryGetValue("Authorization", out var auth))
|
else if (headers.TryGetValue("Authorization", out var auth))
|
||||||
{
|
{
|
||||||
@@ -221,24 +230,35 @@ public class JellyfinSessionManager : IDisposable
|
|||||||
if (authValue.Contains("MediaBrowser", StringComparison.OrdinalIgnoreCase))
|
if (authValue.Contains("MediaBrowser", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
webSocket.Options.SetRequestHeader("X-Emby-Authorization", authValue);
|
webSocket.Options.SetRequestHeader("X-Emby-Authorization", authValue);
|
||||||
_logger.LogWarning("🔑 WEBSOCKET: Converted Authorization to X-Emby-Authorization for {DeviceId}", deviceId);
|
_logger.LogWarning("🔑 WEBSOCKET: Converted Authorization to X-Emby-Authorization for {DeviceId}: {Auth}",
|
||||||
|
deviceId, authValue.Length > 50 ? authValue[..50] + "..." : authValue);
|
||||||
|
authFound = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
webSocket.Options.SetRequestHeader("Authorization", authValue);
|
webSocket.Options.SetRequestHeader("Authorization", authValue);
|
||||||
_logger.LogWarning("🔑 WEBSOCKET: Forwarded Authorization for {DeviceId}", deviceId);
|
_logger.LogWarning("🔑 WEBSOCKET: Using Authorization for {DeviceId}: {Auth}",
|
||||||
|
deviceId, authValue.Length > 50 ? authValue[..50] + "..." : authValue);
|
||||||
|
authFound = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (!authFound)
|
||||||
{
|
{
|
||||||
// No client auth found - fall back to server API key as last resort
|
// No client auth found - fall back to server API key as last resort
|
||||||
if (!string.IsNullOrEmpty(_settings.ApiKey))
|
if (!string.IsNullOrEmpty(_settings.ApiKey))
|
||||||
{
|
{
|
||||||
jellyfinWsUrl += $"?api_key={_settings.ApiKey}";
|
jellyfinWsUrl += $"?api_key={_settings.ApiKey}";
|
||||||
_logger.LogWarning("⚠️ WEBSOCKET: No client auth found, falling back to server API key for {DeviceId}", deviceId);
|
_logger.LogWarning("⚠️ WEBSOCKET: No client auth found in headers, falling back to server API key for {DeviceId}", deviceId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogWarning("❌ WEBSOCKET: No authentication available for {DeviceId}!", deviceId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_logger.LogWarning("🔗 WEBSOCKET: Connecting to Jellyfin for device {DeviceId}: {Url}", deviceId, jellyfinWsUrl);
|
||||||
|
|
||||||
// Set user agent
|
// Set user agent
|
||||||
webSocket.Options.SetRequestHeader("User-Agent", $"Allstarr-Proxy/{session.Client}");
|
webSocket.Options.SetRequestHeader("User-Agent", $"Allstarr-Proxy/{session.Client}");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user