diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-10-17 00:52:41 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-10-17 00:52:41 -0400 |
| commit | 4f207c43dd912b710345e083adfb6ad45c849b1d (patch) | |
| tree | 56d9e71f10ba8b5f67fee39b846f6ebf2123f6a3 | |
| parent | 6ca771cc7906ae6524f737ae9bf0bc1b916efb40 (diff) | |
update connect methods
17 files changed, 158 insertions, 15 deletions
diff --git a/MediaBrowser.Api/UserService.cs b/MediaBrowser.Api/UserService.cs index 01111a998..fede6caaf 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.Api AppVersion = auth.Version, DeviceId = auth.DeviceId, DeviceName = auth.Device, - Password = request.Password, + PasswordSha1 = request.Password, + PasswordMd5 = request.PasswordMd5, RemoteEndPoint = Request.RemoteIp, Username = request.Username diff --git a/MediaBrowser.Controller/Connect/IConnectManager.cs b/MediaBrowser.Controller/Connect/IConnectManager.cs index 8bd0332c0..52175fdd2 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.cs index 39ec2b85d..e9785e2ce 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.cs index 38871e814..bfd7f928b 100644 --- a/MediaBrowser.Controller/Session/AuthenticationRequest.cs +++ b/MediaBrowser.Controller/Session/AuthenticationRequest.cs @@ -4,7 +4,8 @@ namespace MediaBrowser.Controller.Session public 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.cs index 56ff427ad..c76f78009 100644 --- a/MediaBrowser.MediaEncoding/Encoder/EncodingUtils.cs +++ b/MediaBrowser.MediaEncoding/Encoder/EncodingUtils.cs @@ -20,6 +20,12 @@ namespace MediaBrowser.MediaEncoding.Encoder return 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.csproj index 0217c2dc7..3aacffd9b 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.csproj index 4fc9f479e..b80788a98 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.cs new file mode 100644 index 000000000..787fb9a0d --- /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.csproj index 80c125933..3faca062a 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.cs index e3d4b600c..f1a9601cb 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.cs index 163ad943e..1b3f64984 100644 --- a/MediaBrowser.Server.Implementations/Library/UserManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserManager.cs @@ -147,7 +147,12 @@ namespace MediaBrowser.Server.Implementations.Library Users = 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.Library throw 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 save diff --git a/MediaBrowser.Server.Implementations/Localization/Server/server.json b/MediaBrowser.Server.Implementations/Localization/Server/server.json index 07faaf884..78ccba96e 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.cs index 9f77f5294..cf204a5ba 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.nuspec index 7591687ed..fa18975c9 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.nuspec index c130fa993..effe8e3fa 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.nuspec index 9e4971e1f..ff1001cf3 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.nuspec index d9cbadb18..5660e78b0 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> |
