From bda7ffaae83ab4942f5dcb2aab628d91180f375f Mon Sep 17 00:00:00 2001 From: iven <99438726+ivenos@users.noreply.github.com> Date: Wed, 7 Oct 2026 18:47:59 +0200 Subject: Return the created API key from POST /Auth/Keys (#17155) * Return the created API key from POST /Auth/Keys * Keep the other API key fields in the DTO --- Jellyfin.Api/Controllers/ApiKeyController.cs | 37 +++++++++++++++++++++------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'Jellyfin.Api/Controllers/ApiKeyController.cs') diff --git a/Jellyfin.Api/Controllers/ApiKeyController.cs b/Jellyfin.Api/Controllers/ApiKeyController.cs index 161479e4ca..2fa7b649af 100644 --- a/Jellyfin.Api/Controllers/ApiKeyController.cs +++ b/Jellyfin.Api/Controllers/ApiKeyController.cs @@ -1,6 +1,8 @@ using System.ComponentModel.DataAnnotations; +using System.Linq; using System.Threading.Tasks; using Jellyfin.Api.Constants; +using Jellyfin.Api.Models.ApiKeyDtos; using MediaBrowser.Common.Api; using MediaBrowser.Controller.Security; using MediaBrowser.Model.Querying; @@ -32,31 +34,31 @@ public class ApiKeyController : BaseJellyfinApiController /// Get all keys. /// /// Api keys retrieved. - /// A with all keys. + /// A with all keys. [HttpGet("Keys")] [Authorize(Policy = Policies.RequiresElevation)] [ProducesResponseType(StatusCodes.Status200OK)] - public async Task>> GetKeys() + public async Task>> GetKeys() { var keys = await _authenticationManager.GetApiKeys().ConfigureAwait(false); - return new QueryResult(keys); + return new QueryResult(keys.Select(ToDto).ToList()); } /// /// Create a new api key. /// /// Name of the app using the authentication key. - /// Api key created. - /// A . + /// Api key created. + /// The created api key. [HttpPost("Keys")] [Authorize(Policy = Policies.RequiresElevation)] - [ProducesResponseType(StatusCodes.Status204NoContent)] - public async Task CreateKey([FromQuery, Required] string app) + [ProducesResponseType(StatusCodes.Status200OK)] + public async Task> CreateKey([FromQuery, Required] string app) { - await _authenticationManager.CreateApiKey(app).ConfigureAwait(false); + var key = await _authenticationManager.CreateApiKey(app).ConfigureAwait(false); - return NoContent(); + return ToDto(key); } /// @@ -74,4 +76,21 @@ public class ApiKeyController : BaseJellyfinApiController return NoContent(); } + + private static AuthenticationInfoDto ToDto(AuthenticationInfo info) + => new() + { + Id = info.Id, + AccessToken = info.AccessToken, + DeviceId = info.DeviceId, + AppName = info.AppName, + AppVersion = info.AppVersion, + DeviceName = info.DeviceName, + UserId = info.UserId, + IsActive = info.IsActive, + DateCreated = info.DateCreated, + DateRevoked = info.DateRevoked, + DateLastActivity = info.DateLastActivity, + UserName = info.UserName + }; } -- cgit v1.2.3