From 8d6e7d893b4f814cdd82d235c4a2cfc4df6dad05 Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Tue, 5 Sep 2023 16:49:28 -0400 Subject: [PATCH 1/3] Remove one session per device id limitation --- .../Session/SessionManager.cs | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs index 03ff96b19a..f7015b31e5 100644 --- a/Emby.Server.Implementations/Session/SessionManager.cs +++ b/Emby.Server.Implementations/Session/SessionManager.cs @@ -1519,24 +1519,9 @@ namespace Emby.Server.Implementations.Session DeviceId = deviceId }).ConfigureAwait(false)).Items; - foreach (var auth in allExistingForDevice) - { - if (existing is null || !string.Equals(auth.AccessToken, existing.AccessToken, StringComparison.Ordinal)) - { - try - { - await Logout(auth).ConfigureAwait(false); - } - catch (Exception ex) - { - _logger.LogError(ex, "Error while logging out."); - } - } - } - if (existing is not null) { - _logger.LogInformation("Reissuing access token: {Token}", existing.AccessToken); + _logger.LogInformation("Reusing existing access token: {Token}", existing.AccessToken); return existing.AccessToken; } From aea57c1a4a557d30c6169b530b6dccb0b0220b64 Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Wed, 6 Sep 2023 00:06:08 -0400 Subject: [PATCH 2/3] Remove unused variable --- Emby.Server.Implementations/Session/SessionManager.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs index f7015b31e5..bbc096a876 100644 --- a/Emby.Server.Implementations/Session/SessionManager.cs +++ b/Emby.Server.Implementations/Session/SessionManager.cs @@ -1513,12 +1513,6 @@ namespace Emby.Server.Implementations.Session Limit = 1 }).ConfigureAwait(false)).Items.FirstOrDefault(); - var allExistingForDevice = (await _deviceManager.GetDevices( - new DeviceQuery - { - DeviceId = deviceId - }).ConfigureAwait(false)).Items; - if (existing is not null) { _logger.LogInformation("Reusing existing access token: {Token}", existing.AccessToken); From 9ea46b9e17c82ae276d13d32647bf4c8d0c10ac3 Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Mon, 11 Sep 2023 10:49:01 -0400 Subject: [PATCH 3/3] Remove existing sessions for a user on the same device on login --- .../Session/SessionManager.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs index bbc096a876..b4a622ccf4 100644 --- a/Emby.Server.Implementations/Session/SessionManager.cs +++ b/Emby.Server.Implementations/Session/SessionManager.cs @@ -1509,14 +1509,20 @@ namespace Emby.Server.Implementations.Session new DeviceQuery { DeviceId = deviceId, - UserId = user.Id, - Limit = 1 - }).ConfigureAwait(false)).Items.FirstOrDefault(); + UserId = user.Id + }).ConfigureAwait(false)).Items; - if (existing is not null) + foreach (var auth in existing) { - _logger.LogInformation("Reusing existing access token: {Token}", existing.AccessToken); - return existing.AccessToken; + try + { + // Logout any existing sessions for the user on this device + await Logout(auth).ConfigureAwait(false); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error while logging out existing session."); + } } _logger.LogInformation("Creating new access token for user {0}", user.Id);