< Summary - Jellyfin

Information
Class: Jellyfin.Api.Controllers.QuickConnectController
Assembly: Jellyfin.Api
File(s): /srv/git/jellyfin/Jellyfin.Api/Controllers/QuickConnectController.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 11
Coverable lines: 11
Total lines: 119
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 11/7/2025 - 12:11:55 AM Line coverage: 0% (0/11) Total lines: 1291/29/2026 - 12:13:32 AM Line coverage: 0% (0/11) Total lines: 119

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
GetQuickConnectEnabled()100%210%
GetQuickConnectState(...)100%210%

File(s)

/srv/git/jellyfin/Jellyfin.Api/Controllers/QuickConnectController.cs

#LineLine coverage
 1using System;
 2using System.ComponentModel.DataAnnotations;
 3using System.Threading.Tasks;
 4using Jellyfin.Api.Helpers;
 5using MediaBrowser.Common.Extensions;
 6using MediaBrowser.Controller.Authentication;
 7using MediaBrowser.Controller.Net;
 8using MediaBrowser.Controller.QuickConnect;
 9using MediaBrowser.Model.QuickConnect;
 10using Microsoft.AspNetCore.Authorization;
 11using Microsoft.AspNetCore.Http;
 12using Microsoft.AspNetCore.Mvc;
 13
 14namespace Jellyfin.Api.Controllers;
 15
 16/// <summary>
 17/// Quick connect controller.
 18/// </summary>
 19public class QuickConnectController : BaseJellyfinApiController
 20{
 21    private readonly IQuickConnect _quickConnect;
 22    private readonly IAuthorizationContext _authContext;
 23
 24    /// <summary>
 25    /// Initializes a new instance of the <see cref="QuickConnectController"/> class.
 26    /// </summary>
 27    /// <param name="quickConnect">Instance of the <see cref="IQuickConnect"/> interface.</param>
 28    /// <param name="authContext">Instance of the <see cref="IAuthorizationContext"/> interface.</param>
 029    public QuickConnectController(IQuickConnect quickConnect, IAuthorizationContext authContext)
 30    {
 031        _quickConnect = quickConnect;
 032        _authContext = authContext;
 033    }
 34
 35    /// <summary>
 36    /// Gets the current quick connect state.
 37    /// </summary>
 38    /// <response code="200">Quick connect state returned.</response>
 39    /// <returns>Whether Quick Connect is enabled on the server or not.</returns>
 40    [HttpGet("Enabled")]
 41    [ProducesResponseType(StatusCodes.Status200OK)]
 42    public ActionResult<bool> GetQuickConnectEnabled()
 43    {
 044        return _quickConnect.IsEnabled;
 45    }
 46
 47    /// <summary>
 48    /// Initiate a new quick connect request.
 49    /// </summary>
 50    /// <response code="200">Quick connect request successfully created.</response>
 51    /// <response code="401">Quick connect is not active on this server.</response>
 52    /// <returns>A <see cref="QuickConnectResult"/> with a secret and code for future use or an error message.</returns>
 53    [HttpPost("Initiate")]
 54    [ProducesResponseType(StatusCodes.Status200OK)]
 55    public async Task<ActionResult<QuickConnectResult>> InitiateQuickConnect()
 56    {
 57        try
 58        {
 59            var auth = await _authContext.GetAuthorizationInfo(Request).ConfigureAwait(false);
 60            return _quickConnect.TryConnect(auth);
 61        }
 62        catch (AuthenticationException)
 63        {
 64            return Unauthorized("Quick connect is disabled");
 65        }
 66    }
 67
 68    /// <summary>
 69    /// Attempts to retrieve authentication information.
 70    /// </summary>
 71    /// <param name="secret">Secret previously returned from the Initiate endpoint.</param>
 72    /// <response code="200">Quick connect result returned.</response>
 73    /// <response code="404">Unknown quick connect secret.</response>
 74    /// <returns>An updated <see cref="QuickConnectResult"/>.</returns>
 75    [HttpGet("Connect")]
 76    [ProducesResponseType(StatusCodes.Status200OK)]
 77    [ProducesResponseType(StatusCodes.Status404NotFound)]
 78    public ActionResult<QuickConnectResult> GetQuickConnectState([FromQuery, Required] string secret)
 79    {
 80        try
 81        {
 082            return _quickConnect.CheckRequestStatus(secret);
 83        }
 084        catch (ResourceNotFoundException)
 85        {
 086            return NotFound("Unknown secret");
 87        }
 088        catch (AuthenticationException)
 89        {
 090            return Unauthorized("Quick connect is disabled");
 91        }
 092    }
 93
 94    /// <summary>
 95    /// Authorizes a pending quick connect request.
 96    /// </summary>
 97    /// <param name="code">Quick connect code to authorize.</param>
 98    /// <param name="userId">The user the authorize. Access to the requested user is required.</param>
 99    /// <response code="200">Quick connect result authorized successfully.</response>
 100    /// <response code="403">Unknown user id.</response>
 101    /// <returns>Boolean indicating if the authorization was successful.</returns>
 102    [HttpPost("Authorize")]
 103    [Authorize]
 104    [ProducesResponseType(StatusCodes.Status200OK)]
 105    [ProducesResponseType(StatusCodes.Status403Forbidden)]
 106    public async Task<ActionResult<bool>> AuthorizeQuickConnect([FromQuery, Required] string code, [FromQuery] Guid? use
 107    {
 108        userId = RequestHelpers.GetUserId(User, userId);
 109
 110        try
 111        {
 112            return await _quickConnect.AuthorizeRequest(userId.Value, code).ConfigureAwait(false);
 113        }
 114        catch (AuthenticationException)
 115        {
 116            return Unauthorized("Quick connect is disabled");
 117        }
 118    }
 119}