diff options
Diffstat (limited to 'Jellyfin.Api/Controllers/ApiKeyController.cs')
| -rw-r--r-- | Jellyfin.Api/Controllers/ApiKeyController.cs | 37 |
1 files changed, 28 insertions, 9 deletions
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. /// </summary> /// <response code="200">Api keys retrieved.</response> - /// <returns>A <see cref="QueryResult{AuthenticationInfo}"/> with all keys.</returns> + /// <returns>A <see cref="QueryResult{AuthenticationInfoDto}"/> with all keys.</returns> [HttpGet("Keys")] [Authorize(Policy = Policies.RequiresElevation)] [ProducesResponseType(StatusCodes.Status200OK)] - public async Task<ActionResult<QueryResult<AuthenticationInfo>>> GetKeys() + public async Task<ActionResult<QueryResult<AuthenticationInfoDto>>> GetKeys() { var keys = await _authenticationManager.GetApiKeys().ConfigureAwait(false); - return new QueryResult<AuthenticationInfo>(keys); + return new QueryResult<AuthenticationInfoDto>(keys.Select(ToDto).ToList()); } /// <summary> /// Create a new api key. /// </summary> /// <param name="app">Name of the app using the authentication key.</param> - /// <response code="204">Api key created.</response> - /// <returns>A <see cref="NoContentResult"/>.</returns> + /// <response code="200">Api key created.</response> + /// <returns>The created api key.</returns> [HttpPost("Keys")] [Authorize(Policy = Policies.RequiresElevation)] - [ProducesResponseType(StatusCodes.Status204NoContent)] - public async Task<ActionResult> CreateKey([FromQuery, Required] string app) + [ProducesResponseType(StatusCodes.Status200OK)] + public async Task<ActionResult<AuthenticationInfoDto>> CreateKey([FromQuery, Required] string app) { - await _authenticationManager.CreateApiKey(app).ConfigureAwait(false); + var key = await _authenticationManager.CreateApiKey(app).ConfigureAwait(false); - return NoContent(); + return ToDto(key); } /// <summary> @@ -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 + }; } |
