mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
fix web socket session creation
This commit is contained in:
parent
0c95297269
commit
d95c0e8324
@ -7,6 +7,7 @@ using ServiceStack;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using MediaBrowser.Controller.Session;
|
||||||
|
|
||||||
namespace MediaBrowser.Api
|
namespace MediaBrowser.Api
|
||||||
{
|
{
|
||||||
@ -76,12 +77,12 @@ namespace MediaBrowser.Api
|
|||||||
public class ConnectService : BaseApiService
|
public class ConnectService : BaseApiService
|
||||||
{
|
{
|
||||||
private readonly IConnectManager _connectManager;
|
private readonly IConnectManager _connectManager;
|
||||||
private readonly IUserManager _userManager;
|
private readonly ISessionManager _sessionManager;
|
||||||
|
|
||||||
public ConnectService(IConnectManager connectManager, IUserManager userManager)
|
public ConnectService(IConnectManager connectManager, ISessionManager sessionManager)
|
||||||
{
|
{
|
||||||
_connectManager = connectManager;
|
_connectManager = connectManager;
|
||||||
_userManager = userManager;
|
_sessionManager = sessionManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public object Post(CreateConnectLink request)
|
public object Post(CreateConnectLink request)
|
||||||
@ -141,10 +142,33 @@ namespace MediaBrowser.Api
|
|||||||
throw new ResourceNotFoundException();
|
throw new ResourceNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var auth = AuthorizationContext.GetAuthorizationInfo(Request);
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(auth.Client))
|
||||||
|
{
|
||||||
|
return ToOptimizedResult(new ConnectAuthenticationExchangeResult
|
||||||
|
{
|
||||||
|
AccessToken = user.ConnectAccessKey,
|
||||||
|
LocalUserId = user.Id.ToString("N")
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var session = await _sessionManager.CreateNewSession(new AuthenticationRequest
|
||||||
|
{
|
||||||
|
App = auth.Client,
|
||||||
|
AppVersion = auth.Version,
|
||||||
|
DeviceId = auth.DeviceId,
|
||||||
|
DeviceName = auth.Device,
|
||||||
|
RemoteEndPoint = Request.RemoteIp,
|
||||||
|
Username = user.Name,
|
||||||
|
UserId = user.Id.ToString("N")
|
||||||
|
|
||||||
|
}).ConfigureAwait(false);
|
||||||
|
|
||||||
return ToOptimizedResult(new ConnectAuthenticationExchangeResult
|
return ToOptimizedResult(new ConnectAuthenticationExchangeResult
|
||||||
{
|
{
|
||||||
AccessToken = user.ConnectAccessKey,
|
AccessToken = session.AccessToken,
|
||||||
LocalUserId = user.Id.ToString("N")
|
LocalUserId = session.User.Id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ namespace MediaBrowser.Controller.Session
|
|||||||
public class AuthenticationRequest
|
public class AuthenticationRequest
|
||||||
{
|
{
|
||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
|
public string UserId { get; set; }
|
||||||
public string PasswordSha1 { get; set; }
|
public string PasswordSha1 { get; set; }
|
||||||
public string PasswordMd5 { get; set; }
|
public string PasswordMd5 { get; set; }
|
||||||
public string App { get; set; }
|
public string App { get; set; }
|
||||||
|
@ -547,8 +547,6 @@ namespace MediaBrowser.Providers.Manager
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
refreshResult.Failures++;
|
|
||||||
|
|
||||||
Logger.ErrorException("Error in {0}", ex, provider.Name);
|
Logger.ErrorException("Error in {0}", ex, provider.Name);
|
||||||
|
|
||||||
// If a local provider fails, consider that a failure
|
// If a local provider fails, consider that a failure
|
||||||
|
@ -695,7 +695,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||||||
|
|
||||||
public IEnumerable<BaseItem> ResolvePaths(IEnumerable<FileSystemMetadata> files,
|
public IEnumerable<BaseItem> ResolvePaths(IEnumerable<FileSystemMetadata> files,
|
||||||
IDirectoryService directoryService,
|
IDirectoryService directoryService,
|
||||||
Folder parent,
|
Folder parent,
|
||||||
LibraryOptions libraryOptions,
|
LibraryOptions libraryOptions,
|
||||||
string collectionType,
|
string collectionType,
|
||||||
IItemResolver[] resolvers)
|
IItemResolver[] resolvers)
|
||||||
@ -1490,10 +1490,10 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||||||
|
|
||||||
private void AddUserToQuery(InternalItemsQuery query, User user)
|
private void AddUserToQuery(InternalItemsQuery query, User user)
|
||||||
{
|
{
|
||||||
if (query.AncestorIds.Length == 0 &&
|
if (query.AncestorIds.Length == 0 &&
|
||||||
!query.ParentId.HasValue &&
|
!query.ParentId.HasValue &&
|
||||||
query.ChannelIds.Length == 0 &&
|
query.ChannelIds.Length == 0 &&
|
||||||
query.TopParentIds.Length == 0 &&
|
query.TopParentIds.Length == 0 &&
|
||||||
string.IsNullOrWhiteSpace(query.AncestorWithPresentationUniqueKey)
|
string.IsNullOrWhiteSpace(query.AncestorWithPresentationUniqueKey)
|
||||||
&& query.ItemIds.Length == 0)
|
&& query.ItemIds.Length == 0)
|
||||||
{
|
{
|
||||||
@ -2552,7 +2552,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||||||
throw new ArgumentNullException("to");
|
throw new ArgumentNullException("to");
|
||||||
}
|
}
|
||||||
|
|
||||||
var newPath = path.Replace(from, to, StringComparison.OrdinalIgnoreCase);
|
var newPath = path.Replace(from.Trim(), to.Trim(), StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
if (!string.Equals(newPath, path))
|
if (!string.Equals(newPath, path))
|
||||||
{
|
{
|
||||||
|
@ -1341,8 +1341,19 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||||||
|
|
||||||
private async Task<AuthenticationResult> AuthenticateNewSessionInternal(AuthenticationRequest request, bool enforcePassword)
|
private async Task<AuthenticationResult> AuthenticateNewSessionInternal(AuthenticationRequest request, bool enforcePassword)
|
||||||
{
|
{
|
||||||
var user = _userManager.Users
|
User user = null;
|
||||||
.FirstOrDefault(i => string.Equals(request.Username, i.Name, StringComparison.OrdinalIgnoreCase));
|
if (!string.IsNullOrWhiteSpace(request.UserId))
|
||||||
|
{
|
||||||
|
var idGuid = new Guid(request.UserId);
|
||||||
|
user = _userManager.Users
|
||||||
|
.FirstOrDefault(i => i.Id == idGuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
user = _userManager.Users
|
||||||
|
.FirstOrDefault(i => string.Equals(request.Username, i.Name, StringComparison.OrdinalIgnoreCase));
|
||||||
|
}
|
||||||
|
|
||||||
if (user != null && !string.IsNullOrWhiteSpace(request.DeviceId))
|
if (user != null && !string.IsNullOrWhiteSpace(request.DeviceId))
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user