From 55f58ecedd6ed7ac340a52453be8b6d2078d29d0 Mon Sep 17 00:00:00 2001 From: Feiko Joosten Date: Fri, 4 Apr 2025 01:58:01 +0200 Subject: [PATCH 1/2] Prevent force updating username Fixed an issue where you cannot modify the username as the code tried to find users by name instead of its id. --- SSO-Auth/Api/SSOController.cs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/SSO-Auth/Api/SSOController.cs b/SSO-Auth/Api/SSOController.cs index 74dff10..7dd5579 100644 --- a/SSO-Auth/Api/SSOController.cs +++ b/SSO-Auth/Api/SSOController.cs @@ -772,7 +772,28 @@ public class SSOController : ControllerBase private async Task CreateCanonicalLinkAndUserIfNotExist(string mode, string provider, string canonicalName) { User user = null; - user = _userManager.GetUserByName(canonicalName); + + // First try to get the user by its id in case it was already registered before + Guid userId = Guid.Empty; + try + { + userId = GetCanonicalLink(mode, provider, canonicalName); + } + catch (KeyNotFoundException) + { + userId = Guid.Empty; + } + + // No userId found? Let's try and find the user by name instead + if (userId == Guid.Empty) + { + user = _userManager.GetUserByName(canonicalName); + } + else + { + user = _userManager.GetUserById(userId); + } + if (user == null) { _logger.LogInformation($"SSO user {canonicalName} doesn't exist, creating..."); @@ -787,7 +808,7 @@ public class SSOController : ControllerBase UpdateCanonicalLinkConfig(links, mode, provider); } - Guid userId = Guid.Empty; + userId = Guid.Empty; try { userId = GetCanonicalLink(mode, provider, canonicalName); From f761dea35601dc4b8f645adea4e802be0963e176 Mon Sep 17 00:00:00 2001 From: Feiko Joosten Date: Sat, 5 Apr 2025 18:59:36 +0200 Subject: [PATCH 2/2] Removed trailing whitespace --- SSO-Auth/Api/SSOController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SSO-Auth/Api/SSOController.cs b/SSO-Auth/Api/SSOController.cs index 7dd5579..6c75007 100644 --- a/SSO-Auth/Api/SSOController.cs +++ b/SSO-Auth/Api/SSOController.cs @@ -793,7 +793,7 @@ public class SSOController : ControllerBase { user = _userManager.GetUserById(userId); } - + if (user == null) { _logger.LogInformation($"SSO user {canonicalName} doesn't exist, creating...");