From a04c7222b2d90116de580633756ac0230641482f Mon Sep 17 00:00:00 2001 From: Shaun Walker Date: Fri, 30 Sep 2022 09:53:37 -0400 Subject: [PATCH] add upgrade logic for sites using remapped identifier and email claim types --- Oqtane.Client/Modules/Admin/Users/Index.razor | 4 -- .../Infrastructure/UpgradeManager.cs | 39 +++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/Oqtane.Client/Modules/Admin/Users/Index.razor b/Oqtane.Client/Modules/Admin/Users/Index.razor index 32233793d..13d67f4f4 100644 --- a/Oqtane.Client/Modules/Admin/Users/Index.razor +++ b/Oqtane.Client/Modules/Admin/Users/Index.razor @@ -602,14 +602,10 @@ else if (_providertype == AuthenticationProviderTypes.OpenIDConnect) { _scopes = "openid,profile,email"; - _identifierclaimtype = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier"; - _emailclaimtype = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"; } else { _scopes = ""; - _identifierclaimtype = "sub"; - _emailclaimtype = "email"; } } _redirecturl = PageState.Uri.Scheme + "://" + PageState.Alias.Name + "/signin-" + _providertype; diff --git a/Oqtane.Server/Infrastructure/UpgradeManager.cs b/Oqtane.Server/Infrastructure/UpgradeManager.cs index 8ce40fb27..2a108e819 100644 --- a/Oqtane.Server/Infrastructure/UpgradeManager.cs +++ b/Oqtane.Server/Infrastructure/UpgradeManager.cs @@ -57,6 +57,9 @@ public void Upgrade(Tenant tenant, string version) case "3.2.0": Upgrade_3_2_0(tenant, scope); break; + case "3.2.1": + Upgrade_3_2_1(tenant, scope); + break; } } } @@ -264,5 +267,41 @@ private void Upgrade_3_2_0(Tenant tenant, IServiceScope scope) } } + private void Upgrade_3_2_1(Tenant tenant, IServiceScope scope) + { + try + { + // convert Identifier Claim Type and Email Claim Type + var settingRepository = scope.ServiceProvider.GetRequiredService(); + var siteRepository = scope.ServiceProvider.GetRequiredService(); + foreach (Site site in siteRepository.GetSites().ToList()) + { + var settings = settingRepository.GetSettings(EntityNames.Site, site.SiteId).ToList(); + var setting = settings.FirstOrDefault(item => item.SettingName == "ExternalLogin:IdentifierClaimType"); + if (setting != null) + { + if (setting.SettingValue == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier") + { + setting.SettingValue = "sub"; + settingRepository.UpdateSetting(setting); + } + } + setting = settings.FirstOrDefault(item => item.SettingName == "ExternalLogin:EmailClaimType"); + if (setting != null) + { + if (setting.SettingValue == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress") + { + setting.SettingValue = "email"; + settingRepository.UpdateSetting(setting); + } + } + } + } + catch (Exception ex) + { + Debug.WriteLine($"Oqtane Error: Error In 3.2.1 Upgrade Logic - {ex}"); + } + } + } }