Compare commits
No commits in common. "786016344b0a63b2f105e14cb96bf5bd3b25055a" and "13964b9f7f2de228aac7966d1bf8d976eea78d83" have entirely different histories.
786016344b
...
13964b9f7f
10 changed files with 47 additions and 131 deletions
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
|
@ -12,10 +12,8 @@
|
|||
"DOTNET",
|
||||
"ecdsa",
|
||||
"envsubst",
|
||||
"Hsts",
|
||||
"Newtonsoft",
|
||||
"Npgsql",
|
||||
"PKCE",
|
||||
"postit",
|
||||
"pschneider",
|
||||
"SLNDIR",
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ public partial class Settings : ViewModelBase
|
|||
RedirectUri = Authentication.RedirectUri,
|
||||
Scope = string.Join(' ', MergeScopes(this.Authentication.Scopes)),
|
||||
TokenClientCredentialStyle = IdentityModel.Client.ClientCredentialStyle.PostBody,
|
||||
PostLogoutRedirectUri = Authentication.Authority,
|
||||
PostLogoutRedirectUri = "https//yavsc.pschneider.fr",
|
||||
// PKCE is enabled by default when no client_secret is provided.
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -791,12 +791,12 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
|||
{
|
||||
if (userId == null || code == null)
|
||||
{
|
||||
return this.ErrorView<AccountController>("Error: userId or code is null.");
|
||||
return View("Error");
|
||||
}
|
||||
var user = await _userManager.FindByIdAsync(userId);
|
||||
if (user == null)
|
||||
{
|
||||
return this.ErrorView<AccountController>("Error: user not found.");
|
||||
return View("Error");
|
||||
}
|
||||
IdentityResult result = null;
|
||||
try
|
||||
|
|
@ -819,12 +819,12 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
|||
{
|
||||
if (userId == null || code == null)
|
||||
{
|
||||
return this.ErrorView<AccountController>("Error: userId or code is null.");
|
||||
return View("Error");
|
||||
}
|
||||
var user = await _userManager.FindByIdAsync(userId);
|
||||
if (user == null)
|
||||
{
|
||||
return this.ErrorView<AccountController>("Error: user not found.");
|
||||
return View("Error");
|
||||
}
|
||||
bool result = false;
|
||||
try
|
||||
|
|
@ -837,7 +837,7 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
|||
_logger.LogError(ex.StackTrace);
|
||||
_logger.LogError(ex.Message);
|
||||
}
|
||||
return result ? View("EmailConfirmed") : this.ErrorView<AccountController>("Error confirming two factor token.");
|
||||
return View(result ? "EmailConfirmed" : "Error");
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
using System.Security.Claims;
|
||||
using System.IO;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
|
@ -489,7 +490,12 @@ namespace Yavsc.Controllers
|
|||
: message == ManageMessageId.Error ? "An error has occurred."
|
||||
: "";
|
||||
var user = await GetCurrentUserAsync();
|
||||
if (user == null)
|
||||
{
|
||||
return View("Error");
|
||||
}
|
||||
var userLogins = await _userManager.GetLoginsAsync(user);
|
||||
|
||||
ViewBag.ShowRemoveButton = user.PasswordHash != null || userLogins.Count > 1;
|
||||
|
||||
return View(new ManageLoginsViewModel
|
||||
|
|
@ -516,7 +522,15 @@ namespace Yavsc.Controllers
|
|||
public async Task<ActionResult> LinkLoginCallback()
|
||||
{
|
||||
var user = await GetCurrentUserAsync();
|
||||
if (user == null)
|
||||
{
|
||||
return View("Error");
|
||||
}
|
||||
var info = await _signInManager.GetExternalLoginInfoAsync(User.GetUserId());
|
||||
if (info == null)
|
||||
{
|
||||
return RedirectToAction(nameof(ManageLogins), new { Message = ManageMessageId.Error });
|
||||
}
|
||||
var result = await _userManager.AddLoginAsync(user, info);
|
||||
var message = result.Succeeded ? ManageMessageId.AddLoginSuccess : ManageMessageId.Error;
|
||||
return RedirectToAction(nameof(ManageLogins), new { Message = message });
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ using System.Collections.Generic;
|
|||
using System;
|
||||
using Yavsc;
|
||||
using Yavsc.Extensions;
|
||||
using Yavsc.Models;
|
||||
|
||||
namespace IdentityServerHost.Quickstart.UI
|
||||
{
|
||||
|
|
@ -54,10 +53,9 @@ namespace IdentityServerHost.Quickstart.UI
|
|||
{
|
||||
return View("Index", vm);
|
||||
}
|
||||
return this.ErrorView<ConsentController>("No consent request matching request: " + returnUrl);
|
||||
}
|
||||
|
||||
|
||||
return View("Error");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the consent screen postback
|
||||
|
|
@ -90,8 +88,8 @@ namespace IdentityServerHost.Quickstart.UI
|
|||
{
|
||||
return View("Index", result.ViewModel);
|
||||
}
|
||||
return this.ErrorView<ConsentController>($"ReturnUrl: {model}, result: {result}" );
|
||||
|
||||
|
||||
return View("Error");
|
||||
}
|
||||
|
||||
/*****************************************/
|
||||
|
|
@ -172,6 +170,11 @@ namespace IdentityServerHost.Quickstart.UI
|
|||
{
|
||||
return CreateConsentViewModel(model, returnUrl, request);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogError("No consent request matching request: {0}", returnUrl);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -196,7 +199,7 @@ namespace IdentityServerHost.Quickstart.UI
|
|||
vm.IdentityScopes = request.ValidatedResources.Resources.IdentityResources.Select(x => CreateScopeViewModel(x, vm.ScopesConsented.Contains(x.Name) || model == null)).ToArray();
|
||||
|
||||
var apiScopes = new List<ScopeViewModel>();
|
||||
foreach (var parsedScope in request.ValidatedResources.ParsedScopes)
|
||||
foreach(var parsedScope in request.ValidatedResources.ParsedScopes)
|
||||
{
|
||||
var apiScope = request.ValidatedResources.Resources.FindApiScope(parsedScope.ParsedName);
|
||||
if (apiScope != null)
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ using Microsoft.AspNetCore.Authorization;
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Access;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
|
|
@ -50,7 +49,7 @@ namespace Yavsc.Controllers
|
|||
if (string.IsNullOrWhiteSpace(userCode)) return View("UserCodeCapture");
|
||||
|
||||
var vm = await BuildViewModelAsync(userCode);
|
||||
if (vm == null) return this.ErrorView<DeviceController>($"ViewModel is null! userCodeParamName: {userCodeParamName}, userCode: {userCode}" );;
|
||||
if (vm == null) return View("Error");
|
||||
|
||||
vm.ConfirmUserCode = true;
|
||||
return View("UserCodeConfirmation", vm);
|
||||
|
|
@ -61,7 +60,7 @@ namespace Yavsc.Controllers
|
|||
public async Task<IActionResult> UserCodeCapture(string userCode)
|
||||
{
|
||||
var vm = await BuildViewModelAsync(userCode);
|
||||
if (vm == null) return this.ErrorView<DeviceController>($"UserCodeCapture: ViewModel is null! userCode: {userCode}" );
|
||||
if (vm == null) return View("Error");
|
||||
|
||||
return View("UserCodeConfirmation", vm);
|
||||
}
|
||||
|
|
@ -73,20 +72,7 @@ namespace Yavsc.Controllers
|
|||
if (model == null) throw new ArgumentNullException(nameof(model));
|
||||
|
||||
var result = await ProcessConsent(model);
|
||||
if (result.HasValidationError)
|
||||
{
|
||||
if (HttpContext.RequestServices.GetRequiredService<IHostEnvironment>().IsDevelopment())
|
||||
{
|
||||
throw new InvalidOperationException("Device Authorization Input validation error: " + result.ValidationError);
|
||||
}
|
||||
|
||||
return View("Error",
|
||||
new ErrorViewModel {
|
||||
RequestId = HttpContext.TraceIdentifier,
|
||||
Description = "Device Authorization Input validation error: " + result.ValidationError
|
||||
}
|
||||
);
|
||||
}
|
||||
if (result.HasValidationError) return View("Error");
|
||||
|
||||
return View("Success");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,24 +15,18 @@ namespace Yavsc.Controllers
|
|||
public class HomeController : Controller
|
||||
{
|
||||
readonly ApplicationDbContext _dbContext;
|
||||
readonly ILogger<HomeController> _logger;
|
||||
private readonly bool _isDevelopment;
|
||||
|
||||
readonly IHtmlLocalizer _localizer;
|
||||
|
||||
private SiteSettings siteSettings;
|
||||
public HomeController(ILogger<HomeController> logger,
|
||||
IHtmlLocalizer<HomeController> localizer,
|
||||
ApplicationDbContext context,
|
||||
IOptions<SiteSettings> settingsOptions,
|
||||
IWebHostEnvironment env
|
||||
)
|
||||
IOptions<SiteSettings> settingsOptions)
|
||||
{
|
||||
_localizer = localizer;
|
||||
_dbContext = context;
|
||||
siteSettings = settingsOptions.Value;
|
||||
_logger = logger;
|
||||
_isDevelopment = env.IsDevelopment();
|
||||
|
||||
}
|
||||
|
||||
public async Task<IActionResult> Index(string id)
|
||||
|
|
@ -105,44 +99,18 @@ namespace Yavsc.Controllers
|
|||
|
||||
public IActionResult Error()
|
||||
{
|
||||
if (_isDevelopment)
|
||||
var feature = this.HttpContext.Features.Get<IExceptionHandlerFeature>();
|
||||
if (feature == null) return View();
|
||||
var errorType = feature?.Error;
|
||||
if (errorType == null) return View();
|
||||
if (errorType is NotSupportedException notSupported)
|
||||
{
|
||||
_logger.LogInformation(
|
||||
"Home/Error requested in Development. This endpoint is disabled because DeveloperExceptionPage should handle unhandled exceptions.");
|
||||
|
||||
return NotFound(
|
||||
"In Development, /Home/Error is disabled. Unhandled exceptions are rendered by DeveloperExceptionPage.");
|
||||
return View(new ErrorViewModel {
|
||||
Description = notSupported.Message,
|
||||
RequestId = this.HttpContext.TraceIdentifier
|
||||
});
|
||||
}
|
||||
|
||||
var errorViewModel = new ErrorViewModel
|
||||
{
|
||||
RequestId = HttpContext.TraceIdentifier
|
||||
};
|
||||
|
||||
var exceptionHandlerPathFeature =
|
||||
HttpContext.Features.Get<IExceptionHandlerPathFeature>();
|
||||
|
||||
if (exceptionHandlerPathFeature is null)
|
||||
{
|
||||
_logger.LogWarning(
|
||||
"Home/Error called without IExceptionHandlerPathFeature in non-development environment.");
|
||||
|
||||
return View("~/Views/Shared/Error.cshtml", errorViewModel);
|
||||
}
|
||||
|
||||
if (exceptionHandlerPathFeature?.Error is FileNotFoundException)
|
||||
{
|
||||
errorViewModel.Description = "The file was not found.";
|
||||
}
|
||||
|
||||
if (exceptionHandlerPathFeature?.Path == "/")
|
||||
{
|
||||
errorViewModel.Description ??= string.Empty;
|
||||
errorViewModel.Description += " Page: Home.";
|
||||
}
|
||||
|
||||
|
||||
return View("~/Views/Shared/Error.cshtml", errorViewModel);
|
||||
return View("~/Views/Shared/Error.cshtml", feature?.Error);
|
||||
}
|
||||
public IActionResult Status(int id)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -967,12 +967,12 @@ public static class HostingExtensions
|
|||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
await app.MigrateDatabaseAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
app.UseHsts();
|
||||
logger.LogInformation("⨝ Running in production mode. Ensure the database is migrated.");
|
||||
logger.LogInformation("Running in production mode. Ensure the database is migrated.");
|
||||
await app.MigrateDatabaseAsync();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using Yavsc.Models;
|
||||
|
||||
public static class ErrorViewHelpers
|
||||
{
|
||||
public static IActionResult ErrorView<T>(this Controller controller, string message)
|
||||
{
|
||||
var logger = controller.HttpContext.RequestServices.GetRequiredService<ILoggerFactory>()
|
||||
.CreateLogger<T>();
|
||||
|
||||
logger.LogError(message);
|
||||
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
||||
|
||||
if (!controller.ModelState.IsValid)
|
||||
{
|
||||
foreach (var modelState in controller.ModelState.Values)
|
||||
{
|
||||
foreach (var error in modelState.Errors)
|
||||
{
|
||||
logger.LogError("ModelState error: {0}", error.ErrorMessage);
|
||||
foreach (var key in controller.ModelState.Keys)
|
||||
{
|
||||
logger.LogError("ModelState key: {0}", key);
|
||||
dictionary.Add(key,
|
||||
string.Join("\n",
|
||||
controller.ModelState[key].Errors.Select( e => e.ErrorMessage).ToArray()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (controller.HttpContext.Request.Headers.ContainsKey("Accept")
|
||||
&& controller.HttpContext.Request.Headers["Accept"].ToString().Contains("application/json"))
|
||||
{
|
||||
return controller.Json(new
|
||||
{
|
||||
RequestId = controller.HttpContext.TraceIdentifier,
|
||||
Description = message,
|
||||
ModelErrors = dictionary
|
||||
});
|
||||
}
|
||||
|
||||
return controller.View("Error",
|
||||
new ErrorViewModel
|
||||
{
|
||||
RequestId = controller.HttpContext.TraceIdentifier,
|
||||
Description = message,
|
||||
ModelErrors = dictionary
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -7,5 +7,4 @@ public class ErrorViewModel
|
|||
|
||||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
|
||||
public Dictionary<string, string> ModelErrors { get; set; }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue