Skip to content

Commit

Permalink
better validation
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored and github-actions committed Dec 24, 2024
1 parent ee88404 commit e3ecd06
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +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.IsNullOrEmpty(model.Tenant))
{
if (string.IsNullOrEmpty(model.Authority))
{
context.Updater.ModelState.AddModelError(Prefix, nameof(model.Tenant), S["A tenant or authority value is required."]);
}
}
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 e3ecd06

Please sign in to comment.