private async Task <OpenIdValidationSettings> GetValidationSettingsAsync() { var settings = await _validationService.GetSettingsAsync(); if ((await _validationService.ValidateSettingsAsync(settings)).Any(result => result != ValidationResult.Success)) { _logger.LogWarning("The OpenID Connect module is not correctly configured."); return(null); } return(settings); }
public async Task <IActionResult> IndexPost() { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageValidationSettings)) { return(Forbid()); } var settings = await _validationService.GetSettingsAsync(); var shape = await _validationSettingsDisplayManager.UpdateEditorAsync(settings, updater : _updateModelAccessor.ModelUpdater, isNew : false); if (!ModelState.IsValid) { return(View(shape)); } foreach (var result in await _validationService.ValidateSettingsAsync(settings)) { if (result != ValidationResult.Success) { var key = result.MemberNames.FirstOrDefault() ?? string.Empty; ModelState.AddModelError(key, result.ErrorMessage); } } if (!ModelState.IsValid) { return(View(shape)); } await _validationService.UpdateSettingsAsync(settings); _notifier.Success(H["OpenID validation configuration successfully updated."]); await _shellHost.ReloadShellContextAsync(_shellSettings); return(RedirectToAction(nameof(Index))); }
public override async Task <IDisplayResult> UpdateAsync(OpenIdValidationSettings settings, BuildEditorContext context) { var user = _httpContextAccessor.HttpContext?.User; if (user == null || !await _authorizationService.AuthorizeAsync(user, Permissions.ManageValidationSettings)) { return(null); } if (context.GroupId == SettingsGroupId) { var model = new OpenIdValidationSettingsViewModel(); await context.Updater.TryUpdateModelAsync(model, Prefix); settings.Authority = model.Authority?.Trim(); settings.Audience = model.Audience?.Trim(); settings.Tenant = model.Tenant; foreach (var result in await _validationService.ValidateSettingsAsync(settings)) { if (result != ValidationResult.Success) { var key = result.MemberNames.FirstOrDefault() ?? string.Empty; context.Updater.ModelState.AddModelError(key, result.ErrorMessage); } } // If the settings are valid, reload the current tenant. if (context.Updater.ModelState.IsValid) { await _shellHost.ReloadShellContextAsync(_shellSettings); } } return(await EditAsync(settings, context)); }