Files
allstarr/allstarr/Controllers/JellyfinController.Authentication.cs
T
joshpatra 233af5dc8f
Docker Build & Push / build-and-test (push) Has been cancelled
Docker Build & Push / docker (push) Has been cancelled
v1.4.6-beta.1: Hopefully handles #14 and #15, fixes search up to truly interleave, and more transparently proxies /sessions and /socket
2026-04-04 17:36:47 -04:00

68 lines
2.3 KiB
C#

using System.Text.Json;
using Microsoft.AspNetCore.Mvc;
using allstarr.Services.Common;
namespace allstarr.Controllers;
public partial class JellyfinController
{
#region Authentication
/// <summary>
/// Authenticates a user by username and password.
/// This is the primary login endpoint for Jellyfin clients.
/// </summary>
[HttpPost("Users/AuthenticateByName")]
public async Task<IActionResult> AuthenticateByName()
{
try
{
// Enable buffering to allow multiple reads of the request body
Request.EnableBuffering();
// Read the request body
using var reader = new StreamReader(Request.Body, leaveOpen: true);
var body = await reader.ReadToEndAsync();
// Reset stream position
Request.Body.Position = 0;
_logger.LogDebug("Authentication request received");
// DO NOT log request body or detailed headers - contains password
// Forward to Jellyfin server with client headers - completely transparent proxy
var (result, statusCode) =
await _proxyService.PostJsonAsync("Users/AuthenticateByName", body, Request.Headers);
// Pass through Jellyfin's response exactly as-is (transparent proxy)
if (result != null)
{
var responseJson = result.RootElement.GetRawText();
if (statusCode == 200)
{
_logger.LogInformation("Authentication successful");
}
else
{
_logger.LogError("Authentication failed - status {StatusCode}", statusCode);
}
// Return Jellyfin's exact response
return Content(responseJson, "application/json");
}
// No response body from Jellyfin - return status code only
_logger.LogWarning("Authentication request returned {StatusCode} with no response body", statusCode);
return StatusCode(statusCode);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during authentication");
return StatusCode(500, new { error = "Authentication error" });
}
}
#endregion
}