The Free Software Media System - Server Backend & API
update connect methods
Luke Pulverenti4f207c43dd91
diff --git a/MediaBrowser.Api/UserService.cs b/MediaBrowser.Api/UserService.csindex 01111a9988..fede6caafe 100644--- a/MediaBrowser.Api/UserService.cs+++ b/MediaBrowser.Api/UserService.cs@@ -106,6 +106,9 @@ namespace MediaBrowser.Api/// <value>The password.</value>[ApiMember(Name = "Password", IsRequired = true, DataType = "string", ParameterType = "body", Verb = "POST")]public string Password { get; set; }++ [ApiMember(Name = "PasswordMd5", IsRequired = true, DataType = "string", ParameterType = "body", Verb = "POST")]+ public string PasswordMd5 { get; set; }}/// <summary>@@ -351,7 +354,8 @@ namespace MediaBrowser.ApiAppVersion = auth.Version,DeviceId = auth.DeviceId,DeviceName = auth.Device,- Password = request.Password,+ PasswordSha1 = request.Password,+ PasswordMd5 = request.PasswordMd5,RemoteEndPoint = Request.RemoteIp,Username = request.Usernamediff --git a/MediaBrowser.Controller/Connect/IConnectManager.cs b/MediaBrowser.Controller/Connect/IConnectManager.csindex 8bd0332c01..52175fdd2c 100644--- a/MediaBrowser.Controller/Connect/IConnectManager.cs+++ b/MediaBrowser.Controller/Connect/IConnectManager.cs@@ -47,5 +47,13 @@ namespace MediaBrowser.Controller.Connect/// <param name="id">The identifier.</param>/// <returns>Task.</returns>Task CancelAuthorization(string id);++ /// <summary>+ /// Authenticates the specified username.+ /// </summary>+ /// <param name="username">The username.</param>+ /// <param name="passwordMd5">The password MD5.</param>+ /// <returns>Task.</returns>+ Task Authenticate(string username, string passwordMd5);}}diff --git a/MediaBrowser.Controller/Library/IUserManager.cs b/MediaBrowser.Controller/Library/IUserManager.csindex 39ec2b85d1..e9785e2ce8 100644--- a/MediaBrowser.Controller/Library/IUserManager.cs+++ b/MediaBrowser.Controller/Library/IUserManager.cs@@ -131,5 +131,15 @@ namespace MediaBrowser.Controller.Library/// <param name="remoteEndPoint">The remote end point.</param>/// <returns>UserDto.</returns>UserDto GetUserDto(User user, string remoteEndPoint = null);++ /// <summary>+ /// Authenticates the user.+ /// </summary>+ /// <param name="username">The username.</param>+ /// <param name="passwordSha1">The password sha1.</param>+ /// <param name="passwordMd5">The password MD5.</param>+ /// <param name="remoteEndPoint">The remote end point.</param>+ /// <returns>Task<System.Boolean>.</returns>+ Task<bool> AuthenticateUser(string username, string passwordSha1, string passwordMd5, string remoteEndPoint);}}diff --git a/MediaBrowser.Controller/Session/AuthenticationRequest.cs b/MediaBrowser.Controller/Session/AuthenticationRequest.csindex 38871e8147..bfd7f928bd 100644--- a/MediaBrowser.Controller/Session/AuthenticationRequest.cs+++ b/MediaBrowser.Controller/Session/AuthenticationRequest.cs@@ -4,7 +4,8 @@ namespace MediaBrowser.Controller.Sessionpublic class AuthenticationRequest{public string Username { get; set; }- public string Password { get; set; }+ public string PasswordSha1 { get; set; }+ public string PasswordMd5 { get; set; }public string App { get; set; }public string AppVersion { get; set; }public string DeviceId { get; set; }diff --git a/MediaBrowser.MediaEncoding/Encoder/EncodingUtils.cs b/MediaBrowser.MediaEncoding/Encoder/EncodingUtils.csindex 56ff427adf..c76f780095 100644--- a/MediaBrowser.MediaEncoding/Encoder/EncodingUtils.cs+++ b/MediaBrowser.MediaEncoding/Encoder/EncodingUtils.cs@@ -20,6 +20,12 @@ namespace MediaBrowser.MediaEncoding.Encoderreturn string.Format("\"{0}\"", url);}+ if (protocol == MediaProtocol.Rtsp)+ {+ var url = inputFiles.First();++ return string.Format("\"{0}\"", url);+ }return GetConcatInputArgument(inputFiles);}diff --git a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csprojindex 0217c2dc72..3aacffd9b8 100644--- a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj+++ b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj@@ -104,6 +104,9 @@<Compile Include="..\MediaBrowser.Model\ApiClient\IServerEvents.cs"><Link>ApiClient\IServerEvents.cs</Link></Compile>+ <Compile Include="..\MediaBrowser.Model\ApiClient\ServerCredentials.cs">+ <Link>ApiClient\ServerCredentials.cs</Link>+ </Compile><Compile Include="..\MediaBrowser.Model\ApiClient\ServerDiscoveryInfo.cs"><Link>ApiClient\ServerDiscoveryInfo.cs</Link></Compile>diff --git a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csprojindex 4fc9f479e6..b80788a984 100644--- a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj+++ b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj@@ -70,6 +70,9 @@<Compile Include="..\MediaBrowser.Model\ApiClient\IServerEvents.cs"><Link>ApiClient\IServerEvents.cs</Link></Compile>+ <Compile Include="..\MediaBrowser.Model\ApiClient\ServerCredentials.cs">+ <Link>ApiClient\ServerCredentials.cs</Link>+ </Compile><Compile Include="..\MediaBrowser.Model\ApiClient\ServerDiscoveryInfo.cs"><Link>ApiClient\ServerDiscoveryInfo.cs</Link></Compile>diff --git a/MediaBrowser.Model/ApiClient/ServerCredentials.cs b/MediaBrowser.Model/ApiClient/ServerCredentials.csnew file mode 100644index 0000000000..787fb9a0de--- /dev/null+++ b/MediaBrowser.Model/ApiClient/ServerCredentials.cs@@ -0,0 +1,60 @@+using MediaBrowser.Model.Extensions;+using System;+using System.Collections.Generic;+using System.Linq;++namespace MediaBrowser.Model.ApiClient+{+ public class ServerCredentials+ {+ public List<ServerInfo> Servers { get; set; }++ public string ConnectUserId { get; set; }+ public string ConnectAccessToken { get; set; }++ public ServerCredentials()+ {+ Servers = new List<ServerInfo>();+ }++ public void AddOrUpdateServer(ServerInfo server)+ {+ if (server == null)+ {+ throw new ArgumentNullException("server");+ }++ var list = Servers.ToList();++ var index = FindIndex(list, server.Id);++ if (index != -1)+ {+ list[index] = server;+ }+ else+ {+ list.Add(server);+ }++ Servers = list;+ }++ private int FindIndex(List<ServerInfo> servers, string id)+ {+ var index = 0;++ foreach (var server in servers)+ {+ if (StringHelper.Equals(id, server.Id))+ {+ return index;+ }++ index++;+ }++ return -1;+ }+ }+}diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csprojindex 80c1259330..3faca062ad 100644--- a/MediaBrowser.Model/MediaBrowser.Model.csproj+++ b/MediaBrowser.Model/MediaBrowser.Model.csproj@@ -71,6 +71,7 @@<Compile Include="ApiClient\IDevice.cs" /><Compile Include="ApiClient\IServerEvents.cs" /><Compile Include="ApiClient\GeneralCommandEventArgs.cs" />+ <Compile Include="ApiClient\ServerCredentials.cs" /><Compile Include="ApiClient\ServerDiscoveryInfo.cs" /><Compile Include="ApiClient\ServerInfo.cs" /><Compile Include="ApiClient\SessionUpdatesEventArgs.cs" />diff --git a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs b/MediaBrowser.Server.Implementations/Connect/ConnectManager.csindex e3d4b600ca..f1a9601cb5 100644--- a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs+++ b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs@@ -1,4 +1,6 @@-using MediaBrowser.Common.Configuration;+using System.Security.Cryptography;+using MediaBrowser.Common.Configuration;+using MediaBrowser.Common.Extensions;using MediaBrowser.Common.Net;using MediaBrowser.Controller;using MediaBrowser.Controller.Configuration;@@ -825,5 +827,24 @@ namespace MediaBrowser.Server.Implementations.Connect_logger.Debug("Connect returned a 404 when removing a user auth link. Handling it.");}}++ public async Task Authenticate(string username, string passwordMd5)+ {+ var request = new HttpRequestOptions+ {+ Url = GetConnectUrl("user/authenticate")+ };++ request.SetPostData(new Dictionary<string, string>+ {+ {"userName",username},+ {"password",passwordMd5}+ });++ // No need to examine the response+ using (var stream = (await _httpClient.SendAsync(request, "POST").ConfigureAwait(false)).Content)+ {+ }+ }}}diff --git a/MediaBrowser.Server.Implementations/Library/UserManager.cs b/MediaBrowser.Server.Implementations/Library/UserManager.csindex 163ad943e8..1b3f649847 100644--- a/MediaBrowser.Server.Implementations/Library/UserManager.cs+++ b/MediaBrowser.Server.Implementations/Library/UserManager.cs@@ -147,7 +147,12 @@ namespace MediaBrowser.Server.Implementations.LibraryUsers = await LoadUsers().ConfigureAwait(false);}- public async Task<bool> AuthenticateUser(string username, string passwordSha1, string remoteEndPoint)+ public Task<bool> AuthenticateUser(string username, string passwordSha1, string remoteEndPoint)+ {+ return AuthenticateUser(username, passwordSha1, null, remoteEndPoint);+ }++ public async Task<bool> AuthenticateUser(string username, string passwordSha1, string passwordMd5, string remoteEndPoint){if (string.IsNullOrWhiteSpace(username)){@@ -161,11 +166,31 @@ namespace MediaBrowser.Server.Implementations.Librarythrow new AuthenticationException(string.Format("The {0} account is currently disabled. Please consult with your administrator.", user.Name));}- var success = string.Equals(GetPasswordHash(user), passwordSha1.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase);+ var success = false;- if (!success && _networkManager.IsInLocalNetwork(remoteEndPoint) && user.Configuration.EnableLocalPassword)+ // Authenticate using local credentials if not a guest+ if (!user.ConnectLinkType.HasValue || user.ConnectLinkType.Value != UserLinkType.Guest){- success = string.Equals(GetLocalPasswordHash(user), passwordSha1.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase);+ success = string.Equals(GetPasswordHash(user), passwordSha1.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase);++ if (!success && _networkManager.IsInLocalNetwork(remoteEndPoint) && user.Configuration.EnableLocalPassword)+ {+ success = string.Equals(GetLocalPasswordHash(user), passwordSha1.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase);+ }+ }++ // Maybe user accidently entered connect credentials. let's be flexible+ if (!success && user.ConnectLinkType.HasValue && !string.IsNullOrWhiteSpace(passwordMd5))+ {+ try+ {+ await _connectFactory().Authenticate(user.ConnectUserName, passwordMd5).ConfigureAwait(false);+ success = true;+ }+ catch+ {++ }}// Update LastActivityDate and LastLoginDate, then savediff --git a/MediaBrowser.Server.Implementations/Localization/Server/server.json b/MediaBrowser.Server.Implementations/Localization/Server/server.jsonindex 07faaf884e..78ccba96e4 100644--- a/MediaBrowser.Server.Implementations/Localization/Server/server.json+++ b/MediaBrowser.Server.Implementations/Localization/Server/server.json@@ -1245,5 +1245,6 @@"HeaderSchedule": "Schedule","OptionEveryday": "Every day","OptionWeekdays": "Weekdays",- "OptionWeekends": "Weekends"+ "OptionWeekends": "Weekends",+ "MessageProfileInfoSynced": "User profile information synced with Media Browser Connect."}diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.csindex 9f77f52949..cf204a5baa 100644--- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs+++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs@@ -1252,7 +1252,7 @@ namespace MediaBrowser.Server.Implementations.Session&& !(user != null && user.ConnectLinkType.HasValue && user.ConnectLinkType.Value == UserLinkType.Guest);var result = allowWithoutPassword ||- await _userManager.AuthenticateUser(request.Username, request.Password, request.RemoteEndPoint).ConfigureAwait(false);+ await _userManager.AuthenticateUser(request.Username, request.PasswordSha1, request.PasswordMd5, request.RemoteEndPoint).ConfigureAwait(false);if (!result){diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspecindex 7591687ed3..fa18975c9c 100644--- a/Nuget/MediaBrowser.Common.Internal.nuspec+++ b/Nuget/MediaBrowser.Common.Internal.nuspec@@ -2,7 +2,7 @@<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"><metadata><id>MediaBrowser.Common.Internal</id>- <version>3.0.487</version>+ <version>3.0.488</version><title>MediaBrowser.Common.Internal</title><authors>Luke</authors><owners>ebr,Luke,scottisafool</owners>@@ -12,7 +12,7 @@<description>Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption.</description><copyright>Copyright © Media Browser 2013</copyright><dependencies>- <dependency id="MediaBrowser.Common" version="3.0.487" />+ <dependency id="MediaBrowser.Common" version="3.0.488" /><dependency id="NLog" version="3.1.0.0" /><dependency id="SimpleInjector" version="2.5.2" /><dependency id="sharpcompress" version="0.10.2" />diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspecindex c130fa9936..effe8e3fa8 100644--- a/Nuget/MediaBrowser.Common.nuspec+++ b/Nuget/MediaBrowser.Common.nuspec@@ -2,7 +2,7 @@<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"><metadata><id>MediaBrowser.Common</id>- <version>3.0.487</version>+ <version>3.0.488</version><title>MediaBrowser.Common</title><authors>Media Browser Team</authors><owners>ebr,Luke,scottisafool</owners>diff --git a/Nuget/MediaBrowser.Model.Signed.nuspec b/Nuget/MediaBrowser.Model.Signed.nuspecindex 9e4971e1f7..ff1001cf3b 100644--- a/Nuget/MediaBrowser.Model.Signed.nuspec+++ b/Nuget/MediaBrowser.Model.Signed.nuspec@@ -2,7 +2,7 @@<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"><metadata><id>MediaBrowser.Model.Signed</id>- <version>3.0.487</version>+ <version>3.0.488</version><title>MediaBrowser.Model - Signed Edition</title><authors>Media Browser Team</authors><owners>ebr,Luke,scottisafool</owners>diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspecindex d9cbadb18a..5660e78b04 100644--- a/Nuget/MediaBrowser.Server.Core.nuspec+++ b/Nuget/MediaBrowser.Server.Core.nuspec@@ -2,7 +2,7 @@<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"><metadata><id>MediaBrowser.Server.Core</id>- <version>3.0.487</version>+ <version>3.0.488</version><title>Media Browser.Server.Core</title><authors>Media Browser Team</authors><owners>ebr,Luke,scottisafool</owners>@@ -12,7 +12,7 @@<description>Contains core components required to build plugins for Media Browser Server.</description><copyright>Copyright © Media Browser 2013</copyright><dependencies>- <dependency id="MediaBrowser.Common" version="3.0.487" />+ <dependency id="MediaBrowser.Common" version="3.0.488" /></dependencies></metadata><files>