aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CONTRIBUTORS.md1
-rw-r--r--Emby.Server.Implementations/ApplicationHost.cs3
-rw-r--r--Emby.Server.Implementations/QuickConnect/QuickConnectManager.cs296
-rw-r--r--Emby.Server.Implementations/Session/SessionManager.cs18
-rw-r--r--MediaBrowser.Api/QuickConnect/QuickConnectService.cs132
-rw-r--r--MediaBrowser.Api/UserService.cs34
-rw-r--r--MediaBrowser.Controller/QuickConnect/IQuickConnect.cs90
-rw-r--r--MediaBrowser.Controller/Session/ISessionManager.cs2
-rw-r--r--MediaBrowser.Model/Configuration/ServerConfiguration.cs6
-rw-r--r--MediaBrowser.Model/QuickConnect/QuickConnectResult.cs45
-rw-r--r--MediaBrowser.Model/QuickConnect/QuickConnectState.cs23
11 files changed, 650 insertions, 0 deletions
diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index c5f35c088..1b4fdc8c4 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -16,6 +16,7 @@
- [bugfixin](https://github.com/bugfixin)
- [chaosinnovator](https://github.com/chaosinnovator)
- [ckcr4lyf](https://github.com/ckcr4lyf)
+ - [ConfusedPolarBear](https://github.com/ConfusedPolarBear)
- [crankdoofus](https://github.com/crankdoofus)
- [crobibero](https://github.com/crobibero)
- [cromefire](https://github.com/cromefire)
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs
index 23f0571a1..54ce59d75 100644
--- a/Emby.Server.Implementations/ApplicationHost.cs
+++ b/Emby.Server.Implementations/ApplicationHost.cs
@@ -73,6 +73,7 @@ using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Playlists;
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Controller.Providers;
+using MediaBrowser.Controller.QuickConnect;
using MediaBrowser.Controller.Resolvers;
using MediaBrowser.Controller.Security;
using MediaBrowser.Controller.Session;
@@ -104,6 +105,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Prometheus.DotNetRuntime;
using OperatingSystem = MediaBrowser.Common.System.OperatingSystem;
+using Emby.Server.Implementations.QuickConnect;
namespace Emby.Server.Implementations
{
@@ -631,6 +633,7 @@ namespace Emby.Server.Implementations
serviceCollection.AddSingleton<ISessionContext, SessionContext>();
serviceCollection.AddSingleton<IAuthService, AuthService>();
+ serviceCollection.AddSingleton<IQuickConnect, QuickConnectManager>();
serviceCollection.AddSingleton<ISubtitleEncoder, MediaBrowser.MediaEncoding.Subtitles.SubtitleEncoder>();
diff --git a/Emby.Server.Implementations/QuickConnect/QuickConnectManager.cs b/Emby.Server.Implementations/QuickConnect/QuickConnectManager.cs
new file mode 100644
index 000000000..263556e9d
--- /dev/null
+++ b/Emby.Server.Implementations/QuickConnect/QuickConnectManager.cs
@@ -0,0 +1,296 @@
+using System;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Security.Cryptography;
+using MediaBrowser.Controller;
+using MediaBrowser.Controller.Configuration;
+using MediaBrowser.Controller.Net;
+using MediaBrowser.Controller.QuickConnect;
+using MediaBrowser.Controller.Security;
+using MediaBrowser.Model.QuickConnect;
+using MediaBrowser.Model.Services;
+using MediaBrowser.Common;
+using Microsoft.Extensions.Logging;
+using MediaBrowser.Common.Extensions;
+
+namespace Emby.Server.Implementations.QuickConnect
+{
+ /// <summary>
+ /// Quick connect implementation.
+ /// </summary>
+ public class QuickConnectManager : IQuickConnect, IDisposable
+ {
+ private readonly RNGCryptoServiceProvider _rng = new RNGCryptoServiceProvider();
+ private readonly ConcurrentDictionary<string, QuickConnectResult> _currentRequests = new ConcurrentDictionary<string, QuickConnectResult>();
+
+ private readonly IServerConfigurationManager _config;
+ private readonly ILogger<QuickConnectManager> _logger;
+ private readonly IAuthenticationRepository _authenticationRepository;
+ private readonly IAuthorizationContext _authContext;
+ private readonly IServerApplicationHost _appHost;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="QuickConnectManager"/> class.
+ /// Should only be called at server startup when a singleton is created.
+ /// </summary>
+ /// <param name="config">Configuration.</param>
+ /// <param name="logger">Logger.</param>
+ /// <param name="appHost">Application host.</param>
+ /// <param name="authContext">Authentication context.</param>
+ /// <param name="authenticationRepository">Authentication repository.</param>
+ public QuickConnectManager(
+ IServerConfigurationManager config,
+ ILogger<QuickConnectManager> logger,
+ IServerApplicationHost appHost,
+ IAuthorizationContext authContext,
+ IAuthenticationRepository authenticationRepository)
+ {
+ _config = config;
+ _logger = logger;
+ _appHost = appHost;
+ _authContext = authContext;
+ _authenticationRepository = authenticationRepository;
+
+ ReloadConfiguration();
+ }
+
+ /// <inheritdoc/>
+ public int CodeLength { get; set; } = 6;
+
+ /// <inheritdoc/>
+ public string TokenNamePrefix { get; set; } = "QuickConnect-";
+
+ /// <inheritdoc/>
+ public QuickConnectState State { get; private set; } = QuickConnectState.Unavailable;
+
+ /// <inheritdoc/>
+ public int Timeout { get; set; } = 5;
+
+ private DateTime DateActivated { get; set; }
+
+ /// <inheritdoc/>
+ public void AssertActive()
+ {
+ if (State != QuickConnectState.Active)
+ {
+ throw new ArgumentException("Quick connect is not active on this server");
+ }
+ }
+
+ /// <inheritdoc/>
+ public void Activate()
+ {
+ DateActivated = DateTime.Now;
+ SetEnabled(QuickConnectState.Active);
+ }
+
+ /// <inheritdoc/>
+ public void SetEnabled(QuickConnectState newState)
+ {
+ _logger.LogDebug("Changed quick connect state from {0} to {1}", State, newState);
+
+ ExpireRequests(true);
+
+ State = newState;
+ _config.Configuration.QuickConnectAvailable = newState == QuickConnectState.Available || newState == QuickConnectState.Active;
+ _config.SaveConfiguration();
+
+ _logger.LogDebug("Configuration saved");
+ }
+
+ /// <inheritdoc/>
+ public QuickConnectResult TryConnect(string friendlyName)
+ {
+ ExpireRequests();
+
+ if (State != QuickConnectState.Active)
+ {
+ _logger.LogDebug("Refusing quick connect initiation request, current state is {0}", State);
+
+ return new QuickConnectResult()
+ {
+ Error = "Quick connect is not active on this server"
+ };
+ }
+
+ _logger.LogDebug("Got new quick connect request from {friendlyName}", friendlyName);
+
+ var code = GenerateCode();
+ var result = new QuickConnectResult()
+ {
+ Secret = GenerateSecureRandom(),
+ FriendlyName = friendlyName,
+ DateAdded = DateTime.Now,
+ Code = code
+ };
+
+ _currentRequests[code] = result;
+ return result;
+ }
+
+ /// <inheritdoc/>
+ public QuickConnectResult CheckRequestStatus(string secret)
+ {
+ ExpireRequests();
+ AssertActive();
+
+ string code = _currentRequests.Where(x => x.Value.Secret == secret).Select(x => x.Value.Code).DefaultIfEmpty(string.Empty).First();
+
+ if (!_currentRequests.TryGetValue(code, out QuickConnectResult result))
+ {
+ throw new ResourceNotFoundException("Unable to find request with provided secret");
+ }
+
+ return result;
+ }
+
+ /// <inheritdoc/>
+ public string GenerateCode()
+ {
+ int min = (int)Math.Pow(10, CodeLength - 1);
+ int max = (int)Math.Pow(10, CodeLength);
+
+ uint scale = uint.MaxValue;
+ while (scale == uint.MaxValue)
+ {
+ byte[] raw = new byte[4];
+ _rng.GetBytes(raw);
+ scale = BitConverter.ToUInt32(raw, 0);
+ }
+
+ int code = (int)(min + ((max - min) * (scale / (double)uint.MaxValue)));
+ return code.ToString(CultureInfo.InvariantCulture);
+ }
+
+ /// <inheritdoc/>
+ public bool AuthorizeRequest(IRequest request, string code)
+ {
+ ExpireRequests();
+ AssertActive();
+
+ var auth = _authContext.GetAuthorizationInfo(request);
+
+ if (!_currentRequests.TryGetValue(code, out QuickConnectResult result))
+ {
+ throw new ResourceNotFoundException("Unable to find request");
+ }
+
+ if (result.Authenticated)
+ {
+ throw new InvalidOperationException("Request is already authorized");
+ }
+
+ result.Authentication = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);
+
+ // Change the time on the request so it expires one minute into the future. It can't expire immediately as otherwise some clients wouldn't ever see that they have been authenticated.
+ var added = result.DateAdded ?? DateTime.Now.Subtract(new TimeSpan(0, Timeout, 0));
+ result.DateAdded = added.Subtract(new TimeSpan(0, Timeout - 1, 0));
+
+ _authenticationRepository.Create(new AuthenticationInfo
+ {
+ AppName = TokenNamePrefix + result.FriendlyName,
+ AccessToken = result.Authentication,
+ DateCreated = DateTime.UtcNow,
+ DeviceId = _appHost.SystemId,
+ DeviceName = _appHost.FriendlyName,
+ AppVersion = _appHost.ApplicationVersionString,
+ UserId = auth.UserId
+ });
+
+ _logger.LogInformation("Allowing device {0} to login as user {1} with quick connect code {2}", result.FriendlyName, auth.User.Username, result.Code);
+
+ return true;
+ }
+
+ /// <inheritdoc/>
+ public int DeleteAllDevices(Guid user)
+ {
+ var raw = _authenticationRepository.Get(new AuthenticationInfoQuery()
+ {
+ DeviceId = _appHost.SystemId,
+ UserId = user
+ });
+
+ var tokens = raw.Items.Where(x => x.AppName.StartsWith(TokenNamePrefix, StringComparison.CurrentCulture));
+
+ foreach (var token in tokens)
+ {
+ _authenticationRepository.Delete(token);
+ _logger.LogDebug("Deleted token {0}", token.AccessToken);
+ }
+
+ return tokens.Count();
+ }
+
+ /// <summary>
+ /// Dispose.
+ /// </summary>
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ /// <summary>
+ /// Dispose.
+ /// </summary>
+ /// <param name="disposing">Dispose unmanaged resources.</param>
+ protected virtual void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ _rng?.Dispose();
+ }
+ }
+
+ private string GenerateSecureRandom(int length = 32)
+ {
+ var bytes = new byte[length];
+ _rng.GetBytes(bytes);
+
+ return Hex.Encode(bytes);
+ }
+
+ /// <inheritdoc/>
+ public void ExpireRequests(bool expireAll = false)
+ {
+ // Check if quick connect should be deactivated
+ if (State == QuickConnectState.Active && DateTime.Now > DateActivated.AddMinutes(Timeout) && !expireAll)
+ {
+ _logger.LogDebug("Quick connect time expired, deactivating");
+ SetEnabled(QuickConnectState.Available);
+ expireAll = true;
+ }
+
+ // Expire stale connection requests
+ var delete = new List<string>();
+ var values = _currentRequests.Values.ToList();
+
+ for (int i = 0; i < values.Count; i++)
+ {
+ var added = values[i].DateAdded ?? DateTime.UnixEpoch;
+ if (DateTime.Now > added.AddMinutes(Timeout) || expireAll)
+ {
+ delete.Add(values[i].Code);
+ }
+ }
+
+ foreach (var code in delete)
+ {
+ _logger.LogDebug("Removing expired request {code}", code);
+
+ if (!_currentRequests.TryRemove(code, out _))
+ {
+ _logger.LogWarning("Request {code} already expired", code);
+ }
+ }
+ }
+
+ private void ReloadConfiguration()
+ {
+ State = _config.Configuration.QuickConnectAvailable ? QuickConnectState.Available : QuickConnectState.Unavailable;
+ }
+ }
+}
diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs
index 75fdedd10..b458fcb32 100644
--- a/Emby.Server.Implementations/Session/SessionManager.cs
+++ b/Emby.Server.Implementations/Session/SessionManager.cs
@@ -1423,6 +1423,24 @@ namespace Emby.Server.Implementations.Session
return AuthenticateNewSessionInternal(request, false);
}
+ public Task<AuthenticationResult> AuthenticateQuickConnect(AuthenticationRequest request, string token)
+ {
+ var result = _authRepo.Get(new AuthenticationInfoQuery()
+ {
+ AccessToken = token,
+ DeviceId = _appHost.SystemId,
+ Limit = 1
+ });
+
+ if (result.TotalRecordCount < 1)
+ {
+ throw new SecurityException("Unknown quick connect token");
+ }
+
+ request.UserId = result.Items[0].UserId;
+ return AuthenticateNewSessionInternal(request, false);
+ }
+
private async Task<AuthenticationResult> AuthenticateNewSessionInternal(AuthenticationRequest request, bool enforcePassword)
{
CheckDisposed();
diff --git a/MediaBrowser.Api/QuickConnect/QuickConnectService.cs b/MediaBrowser.Api/QuickConnect/QuickConnectService.cs
new file mode 100644
index 000000000..9047a1e95
--- /dev/null
+++ b/MediaBrowser.Api/QuickConnect/QuickConnectService.cs
@@ -0,0 +1,132 @@
+using System;
+using MediaBrowser.Controller.Configuration;
+using MediaBrowser.Controller.Library;
+using MediaBrowser.Controller.Net;
+using MediaBrowser.Controller.QuickConnect;
+using MediaBrowser.Model.QuickConnect;
+using MediaBrowser.Model.Services;
+using Microsoft.Extensions.Logging;
+
+namespace MediaBrowser.Api.QuickConnect
+{
+ [Route("/QuickConnect/Initiate", "GET", Summary = "Requests a new quick connect code")]
+ public class Initiate : IReturn<QuickConnectResult>
+ {
+ [ApiMember(Name = "FriendlyName", Description = "Device friendly name", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
+ public string FriendlyName { get; set; }
+ }
+
+ [Route("/QuickConnect/Connect", "GET", Summary = "Attempts to retrieve authentication information")]
+ public class Connect : IReturn<QuickConnectResult>
+ {
+ [ApiMember(Name = "Secret", Description = "Quick connect secret", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
+ public string Secret { get; set; }
+ }
+
+ [Route("/QuickConnect/Authorize", "POST", Summary = "Authorizes a pending quick connect request")]
+ [Authenticated]
+ public class Authorize : IReturn<bool>
+ {
+ [ApiMember(Name = "Code", Description = "Quick connect identifying code", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
+ public string Code { get; set; }
+ }
+
+ [Route("/QuickConnect/Deauthorize", "POST", Summary = "Deletes all quick connect authorization tokens for the current user")]
+ [Authenticated]
+ public class Deauthorize : IReturn<int>
+ {
+ [ApiMember(Name = "UserId", Description = "User Id", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
+ public Guid UserId { get; set; }
+ }
+
+ [Route("/QuickConnect/Status", "GET", Summary = "Gets the current quick connect state")]
+ public class QuickConnectStatus : IReturn<QuickConnectResult>
+ {
+
+ }
+
+ [Route("/QuickConnect/Available", "POST", Summary = "Enables or disables quick connect")]
+ [Authenticated(Roles = "Admin")]
+ public class Available : IReturn<QuickConnectState>
+ {
+ [ApiMember(Name = "Status", Description = "New quick connect status", IsRequired = false, DataType = "QuickConnectState", ParameterType = "query", Verb = "GET")]
+ public QuickConnectState Status { get; set; }
+ }
+
+ [Route("/QuickConnect/Activate", "POST", Summary = "Temporarily activates quick connect for the time period defined in the server configuration")]
+ [Authenticated]
+ public class Activate : IReturn<bool>
+ {
+
+ }
+
+ public class QuickConnectService : BaseApiService
+ {
+ private IQuickConnect _quickConnect;
+ private IUserManager _userManager;
+ private IAuthorizationContext _authContext;
+
+ public QuickConnectService(
+ ILogger<QuickConnectService> logger,
+ IServerConfigurationManager serverConfigurationManager,
+ IHttpResultFactory httpResultFactory,
+ IUserManager userManager,
+ IAuthorizationContext authContext,
+ IQuickConnect quickConnect)
+ : base(logger, serverConfigurationManager, httpResultFactory)
+ {
+ _userManager = userManager;
+ _quickConnect = quickConnect;
+ _authContext = authContext;
+ }
+
+ public object Get(Initiate request)
+ {
+ return _quickConnect.TryConnect(request.FriendlyName);
+ }
+
+ public object Get(Connect request)
+ {
+ return _quickConnect.CheckRequestStatus(request.Secret);
+ }
+
+ public object Get(QuickConnectStatus request)
+ {
+ _quickConnect.ExpireRequests();
+ return _quickConnect.State;
+ }
+
+ public object Post(Deauthorize request)
+ {
+ AssertCanUpdateUser(_authContext, _userManager, request.UserId, true);
+
+ return _quickConnect.DeleteAllDevices(request.UserId);
+ }
+
+ public object Post(Authorize request)
+ {
+ return _quickConnect.AuthorizeRequest(Request, request.Code);
+ }
+
+ public object Post(Activate request)
+ {
+ if(_quickConnect.State == QuickConnectState.Unavailable)
+ {
+ return false;
+ }
+
+ string name = _authContext.GetAuthorizationInfo(Request).User.Username;
+
+ Logger.LogInformation("{name} temporarily activated quick connect", name);
+ _quickConnect.Activate();
+
+ return true;
+ }
+
+ public object Post(Available request)
+ {
+ _quickConnect.SetEnabled(request.Status);
+ return _quickConnect.State;
+ }
+ }
+}
diff --git a/MediaBrowser.Api/UserService.cs b/MediaBrowser.Api/UserService.cs
index 131def554..e791dca6a 100644
--- a/MediaBrowser.Api/UserService.cs
+++ b/MediaBrowser.Api/UserService.cs
@@ -118,6 +118,17 @@ namespace MediaBrowser.Api
public string Pw { get; set; }
}
+ [Route("/Users/AuthenticateWithQuickConnect", "POST", Summary = "Authenticates a user")]
+ public class AuthenticateUserQuickConnect : IReturn<AuthenticationResult>
+ {
+ /// <summary>
+ /// Gets or sets the token.
+ /// </summary>
+ /// <value>The token</value>
+ [ApiMember(Name = "Token", IsRequired = true, DataType = "string", ParameterType = "body", Verb = "POST")]
+ public string Token { get; set; }
+ }
+
/// <summary>
/// Class UpdateUserPassword.
/// </summary>
@@ -431,6 +442,29 @@ namespace MediaBrowser.Api
}
}
+ public async Task<object> Post(AuthenticateUserQuickConnect request)
+ {
+ var auth = _authContext.GetAuthorizationInfo(Request);
+
+ try
+ {
+ var result = await _sessionMananger.AuthenticateQuickConnect(new AuthenticationRequest
+ {
+ App = auth.Client,
+ AppVersion = auth.Version,
+ DeviceId = auth.DeviceId,
+ DeviceName = auth.Device
+ }, request.Token).ConfigureAwait(false);
+
+ return ToOptimizedResult(result);
+ }
+ catch (SecurityException e)
+ {
+ // rethrow adding IP address to message
+ throw new SecurityException($"[{Request.RemoteIp}] {e.Message}");
+ }
+ }
+
/// <summary>
/// Posts the specified request.
/// </summary>
diff --git a/MediaBrowser.Controller/QuickConnect/IQuickConnect.cs b/MediaBrowser.Controller/QuickConnect/IQuickConnect.cs
new file mode 100644
index 000000000..10ec9e6cb
--- /dev/null
+++ b/MediaBrowser.Controller/QuickConnect/IQuickConnect.cs
@@ -0,0 +1,90 @@
+using System;
+using System.Collections.Generic;
+using MediaBrowser.Model.QuickConnect;
+using MediaBrowser.Model.Services;
+
+namespace MediaBrowser.Controller.QuickConnect
+{
+ /// <summary>
+ /// Quick connect standard interface.
+ /// </summary>
+ public interface IQuickConnect
+ {
+ /// <summary>
+ /// Gets or sets the length of user facing codes.
+ /// </summary>
+ public int CodeLength { get; set; }
+
+ /// <summary>
+ /// Gets or sets the string to prefix internal access tokens with.
+ /// </summary>
+ public string TokenNamePrefix { get; set; }
+
+ /// <summary>
+ /// Gets the current state of quick connect.
+ /// </summary>
+ public QuickConnectState State { get; }
+
+ /// <summary>
+ /// Gets or sets the time (in minutes) before quick connect will automatically deactivate.
+ /// </summary>
+ public int Timeout { get; set; }
+
+ /// <summary>
+ /// Assert that quick connect is currently active and throws an exception if it is not.
+ /// </summary>
+ void AssertActive();
+
+ /// <summary>
+ /// Temporarily activates quick connect for a short amount of time.
+ /// </summary>
+ void Activate();
+
+ /// <summary>
+ /// Changes the status of quick connect.
+ /// </summary>
+ /// <param name="newState">New state to change to.</param>
+ void SetEnabled(QuickConnectState newState);
+
+ /// <summary>
+ /// Initiates a new quick connect request.
+ /// </summary>
+ /// <param name="friendlyName">Friendly device name to display in the request UI.</param>
+ /// <returns>A quick connect result with tokens to proceed or a descriptive error message otherwise.</returns>
+ QuickConnectResult TryConnect(string friendlyName);
+
+ /// <summary>
+ /// Checks the status of an individual request.
+ /// </summary>
+ /// <param name="secret">Unique secret identifier of the request.</param>
+ /// <returns>Quick connect result.</returns>
+ QuickConnectResult CheckRequestStatus(string secret);
+
+ /// <summary>
+ /// Authorizes a quick connect request to connect as the calling user.
+ /// </summary>
+ /// <param name="request">HTTP request object.</param>
+ /// <param name="code">Identifying code for the request.</param>
+ /// <returns>A boolean indicating if the authorization completed successfully.</returns>
+ bool AuthorizeRequest(IRequest request, string code);
+
+ /// <summary>
+ /// Expire quick connect requests that are over the time limit. If <paramref name="expireAll"/> is true, all requests are unconditionally expired.
+ /// </summary>
+ /// <param name="expireAll">If true, all requests will be expired.</param>
+ public void ExpireRequests(bool expireAll = false);
+
+ /// <summary>
+ /// Deletes all quick connect access tokens for the provided user.
+ /// </summary>
+ /// <param name="user">Guid of the user to delete tokens for.</param>
+ /// <returns>A count of the deleted tokens.</returns>
+ int DeleteAllDevices(Guid user);
+
+ /// <summary>
+ /// Generates a short code to display to the user to uniquely identify this request.
+ /// </summary>
+ /// <returns>A short, unique alphanumeric string.</returns>
+ string GenerateCode();
+ }
+}
diff --git a/MediaBrowser.Controller/Session/ISessionManager.cs b/MediaBrowser.Controller/Session/ISessionManager.cs
index e54f21050..23230e41e 100644
--- a/MediaBrowser.Controller/Session/ISessionManager.cs
+++ b/MediaBrowser.Controller/Session/ISessionManager.cs
@@ -264,6 +264,8 @@ namespace MediaBrowser.Controller.Session
/// <returns>Task{SessionInfo}.</returns>
Task<AuthenticationResult> AuthenticateNewSession(AuthenticationRequest request);
+ public Task<AuthenticationResult> AuthenticateQuickConnect(AuthenticationRequest request, string token);
+
/// <summary>
/// Creates the new session.
/// </summary>
diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs
index 742887620..4a7cf7801 100644
--- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs
+++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs
@@ -76,6 +76,11 @@ namespace MediaBrowser.Model.Configuration
/// <value><c>true</c> if this instance is port authorized; otherwise, <c>false</c>.</value>
public bool IsPortAuthorized { get; set; }
+ /// <summary>
+ /// Gets or sets if quick connect is available for use on this server.
+ /// </summary>
+ public bool QuickConnectAvailable { get; set; }
+
public bool AutoRunWebApp { get; set; }
public bool EnableRemoteAccess { get; set; }
@@ -281,6 +286,7 @@ namespace MediaBrowser.Model.Configuration
AutoRunWebApp = true;
EnableRemoteAccess = true;
+ QuickConnectAvailable = false;
EnableUPnP = false;
MinResumePct = 5;
diff --git a/MediaBrowser.Model/QuickConnect/QuickConnectResult.cs b/MediaBrowser.Model/QuickConnect/QuickConnectResult.cs
new file mode 100644
index 000000000..a10d60d57
--- /dev/null
+++ b/MediaBrowser.Model/QuickConnect/QuickConnectResult.cs
@@ -0,0 +1,45 @@
+using System;
+
+namespace MediaBrowser.Model.QuickConnect
+{
+ /// <summary>
+ /// Stores the result of an incoming quick connect request.
+ /// </summary>
+ public class QuickConnectResult
+ {
+ /// <summary>
+ /// Gets a value indicating whether this request is authorized.
+ /// </summary>
+ public bool Authenticated => !string.IsNullOrEmpty(Authentication);
+
+ /// <summary>
+ /// Gets or sets the secret value used to uniquely identify this request. Can be used to retrieve authentication information.
+ /// </summary>
+ public string? Secret { get; set; }
+
+ /// <summary>
+ /// Gets or sets the user facing code used so the user can quickly differentiate this request from others.
+ /// </summary>
+ public string? Code { get; set; }
+
+ /// <summary>
+ /// Gets or sets the device friendly name.
+ /// </summary>
+ public string? FriendlyName { get; set; }
+
+ /// <summary>
+ /// Gets or sets the private access token.
+ /// </summary>
+ public string? Authentication { get; set; }
+
+ /// <summary>
+ /// Gets or sets an error message.
+ /// </summary>
+ public string? Error { get; set; }
+
+ /// <summary>
+ /// Gets or sets the DateTime that this request was created.
+ /// </summary>
+ public DateTime? DateAdded { get; set; }
+ }
+}
diff --git a/MediaBrowser.Model/QuickConnect/QuickConnectState.cs b/MediaBrowser.Model/QuickConnect/QuickConnectState.cs
new file mode 100644
index 000000000..f1074f25f
--- /dev/null
+++ b/MediaBrowser.Model/QuickConnect/QuickConnectState.cs
@@ -0,0 +1,23 @@
+namespace MediaBrowser.Model.QuickConnect
+{
+ /// <summary>
+ /// Quick connect state.
+ /// </summary>
+ public enum QuickConnectState
+ {
+ /// <summary>
+ /// This feature has not been opted into and is unavailable until the server administrator chooses to opt-in.
+ /// </summary>
+ Unavailable = 0,
+
+ /// <summary>
+ /// The feature is enabled for use on the server but is not currently accepting connection requests.
+ /// </summary>
+ Available = 1,
+
+ /// <summary>
+ /// The feature is actively accepting connection requests.
+ /// </summary>
+ Active = 2
+ }
+}