< 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
0%
Covered lines: 0
Uncovered lines: 27
Coverable lines: 27
Total lines: 69
Line coverage: 0%
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 1/23/2026 - 12:11:06 AM Line coverage: 0% (0/2) Total lines: 694/19/2026 - 12:14:27 AM Line coverage: 0% (0/27) Total lines: 69

Coverage delta

Coverage delta 1 -1

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
CreateApiKey()100%210%
GetApiKeys()100%210%
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        {
 022            _dbProvider = dbProvider;
 023        }
 24
 25        /// <inheritdoc />
 26        public async Task CreateApiKey(string name)
 27        {
 028            var dbContext = await _dbProvider.CreateDbContextAsync().ConfigureAwait(false);
 029            await using (dbContext.ConfigureAwait(false))
 30            {
 031                dbContext.ApiKeys.Add(new ApiKey(name));
 32
 033                await dbContext.SaveChangesAsync().ConfigureAwait(false);
 34            }
 035        }
 36
 37        /// <inheritdoc />
 38        public async Task<IReadOnlyList<AuthenticationInfo>> GetApiKeys()
 39        {
 040            var dbContext = await _dbProvider.CreateDbContextAsync().ConfigureAwait(false);
 041            await using (dbContext.ConfigureAwait(false))
 42            {
 043                return await dbContext.ApiKeys
 044                    .Select(key => new AuthenticationInfo
 045                    {
 046                        AppName = key.Name,
 047                        AccessToken = key.AccessToken,
 048                        DateCreated = key.DateCreated,
 049                        DeviceId = string.Empty,
 050                        DeviceName = string.Empty,
 051                        AppVersion = string.Empty
 052                    }).ToListAsync().ConfigureAwait(false);
 53            }
 054        }
 55
 56        /// <inheritdoc />
 57        public async Task DeleteApiKey(string accessToken)
 58        {
 059            var dbContext = await _dbProvider.CreateDbContextAsync().ConfigureAwait(false);
 060            await using (dbContext.ConfigureAwait(false))
 61            {
 062                await dbContext.ApiKeys
 063                    .Where(apiKey => apiKey.AccessToken == accessToken)
 064                    .ExecuteDeleteAsync()
 065                    .ConfigureAwait(false);
 66            }
 067        }
 68    }
 69}