diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2015-04-03 20:41:16 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2015-04-03 20:41:16 -0400 |
| commit | 4f7a69f3689c6aeba6021629818e4e3cced17475 (patch) | |
| tree | 70e37c2952e2cb648659275ec27c0e127388ddc4 | |
| parent | 4655a60d2992b2bb674dda783fbaeb5fba48918f (diff) | |
create user info from exchange token
4 files changed, 33 insertions, 5 deletions
diff --git a/MediaBrowser.Controller/Connect/IConnectManager.cs b/MediaBrowser.Controller/Connect/IConnectManager.cs index 7eecf6ebf..1f7652221 100644 --- a/MediaBrowser.Controller/Connect/IConnectManager.cs +++ b/MediaBrowser.Controller/Connect/IConnectManager.cs @@ -42,6 +42,13 @@ namespace MediaBrowser.Controller.Connect 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> /// Cancels the authorization. /// </summary> /// <param name="id">The identifier.</param> diff --git a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs index a7f8717a7..b1b6cd899 100644 --- a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs +++ b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs @@ -1125,7 +1125,7 @@ namespace MediaBrowser.Server.Implementations.Connect url += "?serverId=" + ConnectServerId; url += "&supporterKey=" + _securityManager.SupporterKey; url += "&userId=" + id; - + var options = new HttpRequestOptions { Url = url, @@ -1244,6 +1244,16 @@ namespace MediaBrowser.Server.Implementations.Connect .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) { if (string.IsNullOrWhiteSpace(token)) diff --git a/MediaBrowser.Server.Implementations/HttpServer/Security/AuthorizationContext.cs b/MediaBrowser.Server.Implementations/HttpServer/Security/AuthorizationContext.cs index cd4d23f5c..9461143a8 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/Security/AuthorizationContext.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/Security/AuthorizationContext.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Net; +using MediaBrowser.Controller.Connect; +using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Security; using ServiceStack.Web; using System; @@ -10,10 +11,12 @@ namespace MediaBrowser.Server.Implementations.HttpServer.Security public class AuthorizationContext : IAuthorizationContext { private readonly IAuthenticationRepository _authRepo; + private readonly IConnectManager _connectManager; - public AuthorizationContext(IAuthenticationRepository authRepo) + public AuthorizationContext(IAuthenticationRepository authRepo, IConnectManager connectManager) { _authRepo = authRepo; + _connectManager = connectManager; } public AuthorizationInfo GetAuthorizationInfo(object requestContext) @@ -144,6 +147,14 @@ namespace MediaBrowser.Server.Implementations.HttpServer.Security info.DeviceId = tokenInfo.DeviceId; } } + else + { + var user = _connectManager.GetUserFromExchangeToken(token); + if (user != null) + { + info.UserId = user.Id.ToString("N"); + } + } httpReq.Items["OriginalAuthenticationInfo"] = tokenInfo; } diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index df7b3f061..911a55634 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -525,7 +525,7 @@ namespace MediaBrowser.Server.Startup.Common RegisterSingleInstance(activityLogRepo); RegisterSingleInstance<IActivityManager>(new ActivityManager(LogManager.GetLogger("ActivityManager"), activityLogRepo, UserManager)); - var authContext = new AuthorizationContext(AuthenticationRepository); + var authContext = new AuthorizationContext(AuthenticationRepository, ConnectManager); RegisterSingleInstance<IAuthorizationContext>(authContext); RegisterSingleInstance<ISessionContext>(new SessionContext(UserManager, authContext, SessionManager)); 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>()); MediaSourceManager.AddParts(GetExports<IMediaSourceProvider>()); - + NotificationManager.AddParts(GetExports<INotificationService>(), GetExports<INotificationTypeFactory>()); SyncManager.AddParts(GetExports<ISyncProvider>()); } |
