From 7763b51623ba5a8d711101ba76e4871ceec54a76 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 12 Oct 2014 13:46:25 -0400 Subject: [PATCH] update authorization refreshing --- .../Connect/ConnectManager.cs | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs index b3234aae5..9b49c111f 100644 --- a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs +++ b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs @@ -471,12 +471,46 @@ namespace MediaBrowser.Server.Implementations.Connect { _logger.ErrorException("Error refreshing server authorizations.", ex); } - } private void RefreshAuthorizations(List list) { - + // TODO: Handle newly added guests that we don't know about + + var users = _userManager.Users.ToList(); + + // Handle existing authorizations that were removed by the Connect server + // Handle existing authorizations whose status may have been updated + foreach (var user in users) + { + if (!string.IsNullOrWhiteSpace(user.ConnectUserId)) + { + var connectEntry = list.FirstOrDefault(i => string.Equals(i.UserId, user.ConnectUserId, StringComparison.OrdinalIgnoreCase)); + + if (connectEntry == null) + { + user.ConnectUserId = null; + user.ConnectAccessKey = null; + user.ConnectUserName = null; + + _userManager.UpdateUser(user); + } + else + { + var changed = !string.Equals(user.ConnectAccessKey, connectEntry.AccessToken, StringComparison.OrdinalIgnoreCase); + + if (changed) + { + user.ConnectUserId = connectEntry.UserId; + user.ConnectAccessKey = connectEntry.AccessToken; + + _userManager.UpdateUser(user); + } + } + } + } + + } } }