mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-20 00:55:13 +01:00
update connect methods
This commit is contained in:
@@ -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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1245,5 +1245,6 @@
|
||||
"HeaderSchedule": "Schedule",
|
||||
"OptionEveryday": "Every day",
|
||||
"OptionWeekdays": "Weekdays",
|
||||
"OptionWeekends": "Weekends"
|
||||
"OptionWeekends": "Weekends",
|
||||
"MessageProfileInfoSynced": "User profile information synced with Media Browser Connect."
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user