diff options
| author | hatharry <hatharry@hotmail.com> | 2016-10-11 17:10:00 +1300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-10-11 17:10:00 +1300 |
| commit | 9b0ac4bde5beb74703a258d582f477c6411ec6ec (patch) | |
| tree | a59864414d58bd01c86085a36355fc553dd43736 /MediaBrowser.Api/ConnectService.cs | |
| parent | 71386f0ceb15ce0bac2e588f90781a4bd274fe68 (diff) | |
| parent | cb26cb94579b772fa7825c6769dc7ace38217168 (diff) | |
Merge pull request #28 from MediaBrowser/dev
Dev
Diffstat (limited to 'MediaBrowser.Api/ConnectService.cs')
| -rw-r--r-- | MediaBrowser.Api/ConnectService.cs | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/MediaBrowser.Api/ConnectService.cs b/MediaBrowser.Api/ConnectService.cs index 4bcd33d9e..494a6e756 100644 --- a/MediaBrowser.Api/ConnectService.cs +++ b/MediaBrowser.Api/ConnectService.cs @@ -7,6 +7,7 @@ using ServiceStack; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using MediaBrowser.Controller.Session; namespace MediaBrowser.Api { @@ -76,12 +77,12 @@ namespace MediaBrowser.Api public class ConnectService : BaseApiService { 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; - _userManager = userManager; + _sessionManager = sessionManager; } public object Post(CreateConnectLink request) @@ -141,10 +142,33 @@ namespace MediaBrowser.Api 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 { - AccessToken = user.ConnectAccessKey, - LocalUserId = user.Id.ToString("N") + AccessToken = session.AccessToken, + LocalUserId = session.User.Id }); } } |
