fix web socket session creation
This commit is contained in:
parent
e20ca8f407
commit
dc45d342ed
|
@ -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; }
|
||||||
|
|
|
@ -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…
Reference in New Issue
Block a user