From d8168f2cf03b7c986e757aaaa8b060a255eb8c5b Mon Sep 17 00:00:00 2001 From: Mattia Salvetti <36173554+salmattia@users.noreply.github.com> Date: Tue, 24 Dec 2024 22:18:15 +0100 Subject: [PATCH] Fix required tenant in OpenId Validation settings UI (#17266) --------- Co-authored-by: Mike Alhayek --- .../OpenIdValidationSettingsDisplayDriver.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Drivers/OpenIdValidationSettingsDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Drivers/OpenIdValidationSettingsDisplayDriver.cs index b0fc7e8ecdc..3e25b2520a1 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Drivers/OpenIdValidationSettingsDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Drivers/OpenIdValidationSettingsDisplayDriver.cs @@ -64,19 +64,22 @@ public override async Task UpdateAsync(OpenIdValidationSettings await context.Updater.TryUpdateModelAsync(model, Prefix); - settings.Authority = !string.IsNullOrEmpty(model.Authority) ? new Uri(model.Authority, UriKind.Absolute) : null; + var hasAuthority = !string.IsNullOrEmpty(model.Authority); + + settings.Authority = hasAuthority ? new Uri(model.Authority, UriKind.Absolute) : null; settings.MetadataAddress = !string.IsNullOrEmpty(model.MetadataAddress) ? new Uri(model.MetadataAddress, UriKind.Absolute) : null; settings.Audience = model.Audience?.Trim(); settings.DisableTokenTypeValidation = model.DisableTokenTypeValidation; settings.Tenant = model.Tenant; - if (string.IsNullOrWhiteSpace(model.Tenant)) - { - context.Updater.ModelState.AddModelError(Prefix, nameof(model.Tenant), S["tenant is a required value"]); - } - else if (!_shellHost.TryGetShellContext(model.Tenant, out var shellContext) || !shellContext.Settings.IsRunning()) + if (!string.IsNullOrEmpty(model.Tenant) && + (!_shellHost.TryGetShellContext(model.Tenant, out var shellContext) || !shellContext.Settings.IsRunning())) { context.Updater.ModelState.AddModelError(Prefix, nameof(model.Tenant), S["Invalid tenant value."]); + } + else if (!hasAuthority) + { + context.Updater.ModelState.AddModelError(Prefix, nameof(model.Authority), S["A tenant or authority value is required."]); } return await EditAsync(settings, context);