From f8c523895b4387e2414122103260dc447a598ca8 Mon Sep 17 00:00:00 2001 From: Jeff Mattson Date: Thu, 9 May 2024 16:15:55 -0400 Subject: [PATCH] fix overwriting of external claims --- .../Services/AccountService.cs | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Identity.Accounts/Services/AccountService.cs b/src/Identity.Accounts/Services/AccountService.cs index 3c0f25b..a40596c 100644 --- a/src/Identity.Accounts/Services/AccountService.cs +++ b/src/Identity.Accounts/Services/AccountService.cs @@ -199,7 +199,7 @@ public async Task RegisterExternalUser(ClaimsPrincipal principal, strin UpdateProperty(account, "origin", subClaim.Issuer); - if (_options.Registration.StoreEmail && registration.Username.IsEmailAddress()) + if (_options.Registration.StoreEmail && email.IsEmailAddress()) { UpdateProperty(account, ClaimTypes.Email, registration.Username); } @@ -221,13 +221,13 @@ public async Task RegisterExternalUser(ClaimsPrincipal principal, strin private void UpdateExternalUserProfile(Data.Account account, ClaimsPrincipal principal) { - UpdateProperty(account, ClaimTypes.Name, principal.FindFirst(ClaimTypes.Name)?.Value); - UpdateProperty(account, ClaimTypes.Avatar, principal.FindFirst(ClaimTypes.Avatar)?.Value); - UpdateProperty(account, ClaimTypes.Org, principal.FindFirst(ClaimTypes.Org)?.Value); - UpdateProperty(account, ClaimTypes.IdAffiliate, principal.FindFirst(ClaimTypes.IdAffiliate)?.Value); - UpdateProperty(account, ClaimTypes.Unit, principal.FindFirst(ClaimTypes.Unit)?.Value); - UpdateProperty(account, ClaimTypes.OrgLogo, principal.FindFirst(ClaimTypes.OrgLogo)?.Value); - UpdateProperty(account, ClaimTypes.UnitLogo, principal.FindFirst(ClaimTypes.UnitLogo)?.Value); + UpdatePropertyIfValue(account, ClaimTypes.Name, principal.FindFirst(ClaimTypes.Name)?.Value); + UpdatePropertyIfValue(account, ClaimTypes.Avatar, principal.FindFirst(ClaimTypes.Avatar)?.Value); + UpdatePropertyIfValue(account, ClaimTypes.Org, principal.FindFirst(ClaimTypes.Org)?.Value); + UpdatePropertyIfValue(account, ClaimTypes.IdAffiliate, principal.FindFirst(ClaimTypes.IdAffiliate)?.Value); + UpdatePropertyIfValue(account, ClaimTypes.Unit, principal.FindFirst(ClaimTypes.Unit)?.Value); + UpdatePropertyIfValue(account, ClaimTypes.OrgLogo, principal.FindFirst(ClaimTypes.OrgLogo)?.Value); + UpdatePropertyIfValue(account, ClaimTypes.UnitLogo, principal.FindFirst(ClaimTypes.UnitLogo)?.Value); } protected async Task Register(string accountName, string name, AccountTokenType type, bool id_affiliate, string globalId = "") @@ -899,6 +899,12 @@ public async Task RemoveAccountAsync(int accountId, string accountName) } } + private void UpdatePropertyIfValue(Data.Account account, string key, string val) + { + if (val.HasValue()) + UpdateProperty(account, key, val); + } + private void UpdateProperty(Data.Account account, string key, string val) { var prop = account.Properties.SingleOrDefault(p => p.Key == key);