aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2015-04-03 21:12:09 -0400
committerLuke <luke.pulverenti@gmail.com>2015-04-03 21:12:09 -0400
commit7bafdfadb9b395568d67bafb2ceeb02f1c203aab (patch)
treeb9cc0b422ace9ae8583729ccfa2bec86c849e030 /MediaBrowser.Server.Implementations
parentef505c8e9e2b8f348aeaa89be6bc446014b72996 (diff)
parent4f7a69f3689c6aeba6021629818e4e3cced17475 (diff)
Merge pull request #1066 from MediaBrowser/master
create user info from exchange token
Diffstat (limited to 'MediaBrowser.Server.Implementations')
-rw-r--r--MediaBrowser.Server.Implementations/Connect/ConnectManager.cs12
-rw-r--r--MediaBrowser.Server.Implementations/HttpServer/Security/AuthorizationContext.cs15
2 files changed, 24 insertions, 3 deletions
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;
}