create user info from exchange token

This commit is contained in:
Luke Pulverenti 2015-04-03 20:41:16 -04:00
parent 4655a60d29
commit 4f7a69f368
4 changed files with 33 additions and 5 deletions

View File

@ -41,6 +41,13 @@ namespace MediaBrowser.Controller.Connect
/// <returns>Task&lt;List&lt;ConnectAuthorization&gt;&gt;.</returns> /// <returns>Task&lt;List&lt;ConnectAuthorization&gt;&gt;.</returns>
Task<List<ConnectAuthorization>> GetPendingGuests(); Task<List<ConnectAuthorization>> GetPendingGuests();
/// <summary>
/// Gets the user from exchange token.
/// </summary>
/// <param name="token">The token.</param>
/// <returns>User.</returns>
User GetUserFromExchangeToken(string token);
/// <summary> /// <summary>
/// Cancels the authorization. /// Cancels the authorization.
/// </summary> /// </summary>

View File

@ -1125,7 +1125,7 @@ namespace MediaBrowser.Server.Implementations.Connect
url += "?serverId=" + ConnectServerId; url += "?serverId=" + ConnectServerId;
url += "&supporterKey=" + _securityManager.SupporterKey; url += "&supporterKey=" + _securityManager.SupporterKey;
url += "&userId=" + id; url += "&userId=" + id;
var options = new HttpRequestOptions var options = new HttpRequestOptions
{ {
Url = url, Url = url,
@ -1244,6 +1244,16 @@ namespace MediaBrowser.Server.Implementations.Connect
.FirstOrDefault(i => string.Equals(i.ConnectUserId, connectUserId, StringComparison.OrdinalIgnoreCase)); .FirstOrDefault(i => string.Equals(i.ConnectUserId, connectUserId, StringComparison.OrdinalIgnoreCase));
} }
public User GetUserFromExchangeToken(string token)
{
if (string.IsNullOrWhiteSpace(token))
{
throw new ArgumentNullException("token");
}
return _userManager.Users.FirstOrDefault(u => string.Equals(token, u.ConnectAccessKey, StringComparison.OrdinalIgnoreCase));
}
public bool IsAuthorizationTokenValid(string token) public bool IsAuthorizationTokenValid(string token)
{ {
if (string.IsNullOrWhiteSpace(token)) if (string.IsNullOrWhiteSpace(token))

View File

@ -1,4 +1,5 @@
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Connect;
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Security; using MediaBrowser.Controller.Security;
using ServiceStack.Web; using ServiceStack.Web;
using System; using System;
@ -10,10 +11,12 @@ namespace MediaBrowser.Server.Implementations.HttpServer.Security
public class AuthorizationContext : IAuthorizationContext public class AuthorizationContext : IAuthorizationContext
{ {
private readonly IAuthenticationRepository _authRepo; private readonly IAuthenticationRepository _authRepo;
private readonly IConnectManager _connectManager;
public AuthorizationContext(IAuthenticationRepository authRepo) public AuthorizationContext(IAuthenticationRepository authRepo, IConnectManager connectManager)
{ {
_authRepo = authRepo; _authRepo = authRepo;
_connectManager = connectManager;
} }
public AuthorizationInfo GetAuthorizationInfo(object requestContext) public AuthorizationInfo GetAuthorizationInfo(object requestContext)
@ -144,6 +147,14 @@ namespace MediaBrowser.Server.Implementations.HttpServer.Security
info.DeviceId = tokenInfo.DeviceId; info.DeviceId = tokenInfo.DeviceId;
} }
} }
else
{
var user = _connectManager.GetUserFromExchangeToken(token);
if (user != null)
{
info.UserId = user.Id.ToString("N");
}
}
httpReq.Items["OriginalAuthenticationInfo"] = tokenInfo; httpReq.Items["OriginalAuthenticationInfo"] = tokenInfo;
} }

View File

@ -525,7 +525,7 @@ namespace MediaBrowser.Server.Startup.Common
RegisterSingleInstance(activityLogRepo); RegisterSingleInstance(activityLogRepo);
RegisterSingleInstance<IActivityManager>(new ActivityManager(LogManager.GetLogger("ActivityManager"), activityLogRepo, UserManager)); RegisterSingleInstance<IActivityManager>(new ActivityManager(LogManager.GetLogger("ActivityManager"), activityLogRepo, UserManager));
var authContext = new AuthorizationContext(AuthenticationRepository); var authContext = new AuthorizationContext(AuthenticationRepository, ConnectManager);
RegisterSingleInstance<IAuthorizationContext>(authContext); RegisterSingleInstance<IAuthorizationContext>(authContext);
RegisterSingleInstance<ISessionContext>(new SessionContext(UserManager, authContext, SessionManager)); RegisterSingleInstance<ISessionContext>(new SessionContext(UserManager, authContext, SessionManager));
RegisterSingleInstance<IAuthService>(new AuthService(UserManager, authContext, ServerConfigurationManager, ConnectManager, SessionManager, DeviceManager)); RegisterSingleInstance<IAuthService>(new AuthService(UserManager, authContext, ServerConfigurationManager, ConnectManager, SessionManager, DeviceManager));
@ -756,7 +756,7 @@ namespace MediaBrowser.Server.Startup.Common
ChannelManager.AddParts(GetExports<IChannel>(), GetExports<IChannelFactory>()); ChannelManager.AddParts(GetExports<IChannel>(), GetExports<IChannelFactory>());
MediaSourceManager.AddParts(GetExports<IMediaSourceProvider>()); MediaSourceManager.AddParts(GetExports<IMediaSourceProvider>());
NotificationManager.AddParts(GetExports<INotificationService>(), GetExports<INotificationTypeFactory>()); NotificationManager.AddParts(GetExports<INotificationService>(), GetExports<INotificationTypeFactory>());
SyncManager.AddParts(GetExports<ISyncProvider>()); SyncManager.AddParts(GetExports<ISyncProvider>());
} }