update connect methods

This commit is contained in:
Luke Pulverenti 2014-10-17 00:52:41 -04:00
parent 6ca771cc79
commit 4f207c43dd
17 changed files with 158 additions and 15 deletions

View File

@ -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

View File

@ -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);
}
}

View File

@ -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&lt;System.Boolean&gt;.</returns>
Task<bool> AuthenticateUser(string username, string passwordSha1, string passwordMd5, string remoteEndPoint);
}
}

View File

@ -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; }

View File

@ -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);
}

View File

@ -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>

View File

@ -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>

View File

@ -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;
}
}
}

View File

@ -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" />

View File

@ -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)
{
}
}
}
}

View File

@ -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,12 +166,32 @@ 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;
// Authenticate using local credentials if not a guest
if (!user.ConnectLinkType.HasValue || user.ConnectLinkType.Value != UserLinkType.Guest)
{
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
if (success)

View File

@ -1245,5 +1245,6 @@
"HeaderSchedule": "Schedule",
"OptionEveryday": "Every day",
"OptionWeekdays": "Weekdays",
"OptionWeekends": "Weekends"
"OptionWeekends": "Weekends",
"MessageProfileInfoSynced": "User profile information synced with Media Browser Connect."
}

View File

@ -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)
{

View File

@ -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" />

View File

@ -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>

View File

@ -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>

View File

@ -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>