< Summary - Jellyfin

Information
Class: Jellyfin.Server.Implementations.Security.AuthenticationManager
Assembly: Jellyfin.Server.Implementations
File(s): /srv/git/jellyfin/Jellyfin.Server.Implementations/Security/AuthenticationManager.cs
Line coverage
81%
Covered lines: 30
Uncovered lines: 7
Coverable lines: 37
Total lines: 80
Line coverage: 81%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 5/12/2026 - 12:15:57 AM Line coverage: 0% (0/27) Total lines: 6910/29/2026 - 12:17:11 AM Line coverage: 81% (30/37) Total lines: 80

Coverage delta

Coverage delta 81 -81

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
CreateApiKey()100%11100%
GetApiKeys()100%11100%
DeleteApiKey()100%210%

File(s)

/srv/git/jellyfin/Jellyfin.Server.Implementations/Security/AuthenticationManager.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3using System.Threading.Tasks;
 4using Jellyfin.Database.Implementations;
 5using Jellyfin.Database.Implementations.Entities.Security;
 6using MediaBrowser.Controller.Security;
 7using Microsoft.EntityFrameworkCore;
 8
 9namespace Jellyfin.Server.Implementations.Security
 10{
 11    /// <inheritdoc />
 12    public class AuthenticationManager : IAuthenticationManager
 13    {
 14        private readonly IDbContextFactory<JellyfinDbContext> _dbProvider;
 15
 16        /// <summary>
 17        /// Initializes a new instance of the <see cref="AuthenticationManager"/> class.
 18        /// </summary>
 19        /// <param name="dbProvider">The database provider.</param>
 20        public AuthenticationManager(IDbContextFactory<JellyfinDbContext> dbProvider)
 21        {
 222            _dbProvider = dbProvider;
 223        }
 24
 25        /// <inheritdoc />
 26        public async Task<AuthenticationInfo> CreateApiKey(string name)
 27        {
 328            var dbContext = await _dbProvider.CreateDbContextAsync().ConfigureAwait(false);
 329            await using (dbContext.ConfigureAwait(false))
 30            {
 331                var apiKey = new ApiKey(name);
 332                dbContext.ApiKeys.Add(apiKey);
 33
 334                await dbContext.SaveChangesAsync().ConfigureAwait(false);
 35
 336                return new AuthenticationInfo
 337                {
 338                    AppName = apiKey.Name,
 339                    AccessToken = apiKey.AccessToken,
 340                    DateCreated = apiKey.DateCreated,
 341                    DeviceId = string.Empty,
 342                    DeviceName = string.Empty,
 343                    AppVersion = string.Empty
 344                };
 45            }
 346        }
 47
 48        /// <inheritdoc />
 49        public async Task<IReadOnlyList<AuthenticationInfo>> GetApiKeys()
 50        {
 151            var dbContext = await _dbProvider.CreateDbContextAsync().ConfigureAwait(false);
 152            await using (dbContext.ConfigureAwait(false))
 53            {
 154                return await dbContext.ApiKeys
 155                    .Select(key => new AuthenticationInfo
 156                    {
 157                        AppName = key.Name,
 158                        AccessToken = key.AccessToken,
 159                        DateCreated = key.DateCreated,
 160                        DeviceId = string.Empty,
 161                        DeviceName = string.Empty,
 162                        AppVersion = string.Empty
 163                    }).ToListAsync().ConfigureAwait(false);
 64            }
 165        }
 66
 67        /// <inheritdoc />
 68        public async Task DeleteApiKey(string accessToken)
 69        {
 070            var dbContext = await _dbProvider.CreateDbContextAsync().ConfigureAwait(false);
 071            await using (dbContext.ConfigureAwait(false))
 72            {
 073                await dbContext.ApiKeys
 074                    .Where(apiKey => apiKey.AccessToken == accessToken)
 075                    .ExecuteDeleteAsync()
 076                    .ConfigureAwait(false);
 77            }
 078        }
 79    }
 80}