aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Api/Controllers/ApiKeyController.cs
diff options
context:
space:
mode:
authorCody Robibero <cody@robibe.ro>2021-10-08 07:49:40 -0600
committerCody Robibero <cody@robibe.ro>2021-10-08 07:49:40 -0600
commit3bbd98cc3fb4e69b5d5471ab7cbdcc22d59a8eb9 (patch)
treed6a0aeb4896ec9ab4305916f0380606483180786 /Jellyfin.Api/Controllers/ApiKeyController.cs
parent7a7fe3e681eca87cde631336c9af565fd6dfe0d7 (diff)
parenta01f9775fffaacfd0fc03b24bff366b4701fe45e (diff)
Merge remote-tracking branch 'upstream/master' into schedules-direct
Diffstat (limited to 'Jellyfin.Api/Controllers/ApiKeyController.cs')
-rw-r--r--Jellyfin.Api/Controllers/ApiKeyController.cs53
1 files changed, 18 insertions, 35 deletions
diff --git a/Jellyfin.Api/Controllers/ApiKeyController.cs b/Jellyfin.Api/Controllers/ApiKeyController.cs
index 8c43d786a..8e0332d3e 100644
--- a/Jellyfin.Api/Controllers/ApiKeyController.cs
+++ b/Jellyfin.Api/Controllers/ApiKeyController.cs
@@ -1,10 +1,7 @@
-using System;
using System.ComponentModel.DataAnnotations;
-using System.Globalization;
+using System.Threading.Tasks;
using Jellyfin.Api.Constants;
-using MediaBrowser.Controller;
using MediaBrowser.Controller.Security;
-using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Querying;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
@@ -18,24 +15,15 @@ namespace Jellyfin.Api.Controllers
[Route("Auth")]
public class ApiKeyController : BaseJellyfinApiController
{
- private readonly ISessionManager _sessionManager;
- private readonly IServerApplicationHost _appHost;
- private readonly IAuthenticationRepository _authRepo;
+ private readonly IAuthenticationManager _authenticationManager;
/// <summary>
/// Initializes a new instance of the <see cref="ApiKeyController"/> class.
/// </summary>
- /// <param name="sessionManager">Instance of <see cref="ISessionManager"/> interface.</param>
- /// <param name="appHost">Instance of <see cref="IServerApplicationHost"/> interface.</param>
- /// <param name="authRepo">Instance of <see cref="IAuthenticationRepository"/> interface.</param>
- public ApiKeyController(
- ISessionManager sessionManager,
- IServerApplicationHost appHost,
- IAuthenticationRepository authRepo)
+ /// <param name="authenticationManager">Instance of <see cref="IAuthenticationManager"/> interface.</param>
+ public ApiKeyController(IAuthenticationManager authenticationManager)
{
- _sessionManager = sessionManager;
- _appHost = appHost;
- _authRepo = authRepo;
+ _authenticationManager = authenticationManager;
}
/// <summary>
@@ -46,14 +34,15 @@ namespace Jellyfin.Api.Controllers
[HttpGet("Keys")]
[Authorize(Policy = Policies.RequiresElevation)]
[ProducesResponseType(StatusCodes.Status200OK)]
- public ActionResult<QueryResult<AuthenticationInfo>> GetKeys()
+ public async Task<ActionResult<QueryResult<AuthenticationInfo>>> GetKeys()
{
- var result = _authRepo.Get(new AuthenticationInfoQuery
- {
- HasUser = false
- });
+ var keys = await _authenticationManager.GetApiKeys();
- return result;
+ return new QueryResult<AuthenticationInfo>
+ {
+ Items = keys,
+ TotalRecordCount = keys.Count
+ };
}
/// <summary>
@@ -65,17 +54,10 @@ namespace Jellyfin.Api.Controllers
[HttpPost("Keys")]
[Authorize(Policy = Policies.RequiresElevation)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
- public ActionResult CreateKey([FromQuery, Required] string app)
+ public async Task<ActionResult> CreateKey([FromQuery, Required] string app)
{
- _authRepo.Create(new AuthenticationInfo
- {
- AppName = app,
- AccessToken = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture),
- DateCreated = DateTime.UtcNow,
- DeviceId = _appHost.SystemId,
- DeviceName = _appHost.FriendlyName,
- AppVersion = _appHost.ApplicationVersionString
- });
+ await _authenticationManager.CreateApiKey(app).ConfigureAwait(false);
+
return NoContent();
}
@@ -88,9 +70,10 @@ namespace Jellyfin.Api.Controllers
[HttpDelete("Keys/{key}")]
[Authorize(Policy = Policies.RequiresElevation)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
- public ActionResult RevokeKey([FromRoute, Required] string key)
+ public async Task<ActionResult> RevokeKey([FromRoute, Required] string key)
{
- _sessionManager.RevokeToken(key);
+ await _authenticationManager.DeleteApiKey(key).ConfigureAwait(false);
+
return NoContent();
}
}