< 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: 2
Coverable lines: 2
Total lines: 68
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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)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.Data.Entities.Security;
 5using MediaBrowser.Controller.Security;
 6using Microsoft.EntityFrameworkCore;
 7
 8namespace Jellyfin.Server.Implementations.Security
 9{
 10    /// <inheritdoc />
 11    public class AuthenticationManager : IAuthenticationManager
 12    {
 13        private readonly IDbContextFactory<JellyfinDbContext> _dbProvider;
 14
 15        /// <summary>
 16        /// Initializes a new instance of the <see cref="AuthenticationManager"/> class.
 17        /// </summary>
 18        /// <param name="dbProvider">The database provider.</param>
 19        public AuthenticationManager(IDbContextFactory<JellyfinDbContext> dbProvider)
 20        {
 021            _dbProvider = dbProvider;
 022        }
 23
 24        /// <inheritdoc />
 25        public async Task CreateApiKey(string name)
 26        {
 27            var dbContext = await _dbProvider.CreateDbContextAsync().ConfigureAwait(false);
 28            await using (dbContext.ConfigureAwait(false))
 29            {
 30                dbContext.ApiKeys.Add(new ApiKey(name));
 31
 32                await dbContext.SaveChangesAsync().ConfigureAwait(false);
 33            }
 34        }
 35
 36        /// <inheritdoc />
 37        public async Task<IReadOnlyList<AuthenticationInfo>> GetApiKeys()
 38        {
 39            var dbContext = await _dbProvider.CreateDbContextAsync().ConfigureAwait(false);
 40            await using (dbContext.ConfigureAwait(false))
 41            {
 42                return await dbContext.ApiKeys
 43                    .Select(key => new AuthenticationInfo
 44                    {
 45                        AppName = key.Name,
 46                        AccessToken = key.AccessToken,
 47                        DateCreated = key.DateCreated,
 48                        DeviceId = string.Empty,
 49                        DeviceName = string.Empty,
 50                        AppVersion = string.Empty
 51                    }).ToListAsync().ConfigureAwait(false);
 52            }
 53        }
 54
 55        /// <inheritdoc />
 56        public async Task DeleteApiKey(string accessToken)
 57        {
 58            var dbContext = await _dbProvider.CreateDbContextAsync().ConfigureAwait(false);
 59            await using (dbContext.ConfigureAwait(false))
 60            {
 61                await dbContext.ApiKeys
 62                    .Where(apiKey => apiKey.AccessToken == accessToken)
 63                    .ExecuteDeleteAsync()
 64                    .ConfigureAwait(false);
 65            }
 66        }
 67    }
 68}