Skip to content

Commit

Permalink
Fix required tenant in OpenId Validation settings UI (#17266)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Mike Alhayek <[email protected]>
  • Loading branch information
salmattia and MikeAlhayek authored Dec 24, 2024
1 parent 1180bd3 commit d8168f2
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,22 @@ public override async Task<IDisplayResult> 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);
Expand Down

0 comments on commit d8168f2

Please sign in to comment.