diff --git a/Quickstart/Account/AccountController.cs b/Controllers/AccountController.cs similarity index 100% rename from Quickstart/Account/AccountController.cs rename to Controllers/AccountController.cs diff --git a/Quickstart/Consent/ConsentController.cs b/Controllers/ConsentController.cs similarity index 100% rename from Quickstart/Consent/ConsentController.cs rename to Controllers/ConsentController.cs diff --git a/Quickstart/Diagnostics/DiagnosticsController.cs b/Controllers/DiagnosticsController.cs similarity index 100% rename from Quickstart/Diagnostics/DiagnosticsController.cs rename to Controllers/DiagnosticsController.cs diff --git a/Quickstart/Account/ExternalController.cs b/Controllers/ExternalController.cs similarity index 100% rename from Quickstart/Account/ExternalController.cs rename to Controllers/ExternalController.cs diff --git a/Quickstart/Grants/GrantsController.cs b/Controllers/GrantsController.cs similarity index 100% rename from Quickstart/Grants/GrantsController.cs rename to Controllers/GrantsController.cs diff --git a/Controllers/HomeController.cs b/Controllers/HomeController.cs index fcf2603..271fae1 100644 --- a/Controllers/HomeController.cs +++ b/Controllers/HomeController.cs @@ -3,13 +3,27 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; +using IdentityServer4.Services; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; using nuget_host.Models; namespace nuget_host.Controllers { public class HomeController : Controller { + private readonly IIdentityServerInteractionService _interaction; + private readonly ILogger _logger; + IHostingEnvironment _environment; + + public HomeController(IIdentityServerInteractionService interaction, Microsoft.AspNetCore.Hosting.IHostingEnvironment environment, ILogger logger) + { + _interaction = interaction; + _environment = environment; + _logger = logger; + } + public IActionResult Index() { return View(); @@ -37,9 +51,28 @@ namespace nuget_host.Controllers } - public IActionResult Error() + /// + /// Shows the error page + /// + public async Task Error(string errorId) { - return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + var vm = new ErrorViewModel(); + + // retrieve error details from identityserver + var message = await _interaction.GetErrorContextAsync(errorId); + if (message != null) + { + vm.Error = message; + + if (!_environment.IsDevelopment()) + { + // only show in development + message.ErrorDescription = null; + } + } + + return View("Error", vm); } + } } diff --git a/Quickstart/Extensions.cs b/Extensions/Extensions.cs similarity index 100% rename from Quickstart/Extensions.cs rename to Extensions/Extensions.cs diff --git a/Quickstart/Account/AccountOptions.cs b/Models/Account/AccountOptions.cs similarity index 100% rename from Quickstart/Account/AccountOptions.cs rename to Models/Account/AccountOptions.cs diff --git a/Quickstart/Account/ExternalProvider.cs b/Models/Account/ExternalProvider.cs similarity index 100% rename from Quickstart/Account/ExternalProvider.cs rename to Models/Account/ExternalProvider.cs diff --git a/Quickstart/Account/LoggedOutViewModel.cs b/Models/Account/LoggedOutViewModel.cs similarity index 100% rename from Quickstart/Account/LoggedOutViewModel.cs rename to Models/Account/LoggedOutViewModel.cs diff --git a/Quickstart/Account/LoginInputModel.cs b/Models/Account/LoginInputModel.cs similarity index 100% rename from Quickstart/Account/LoginInputModel.cs rename to Models/Account/LoginInputModel.cs diff --git a/Quickstart/Account/LoginViewModel.cs b/Models/Account/LoginViewModel.cs similarity index 100% rename from Quickstart/Account/LoginViewModel.cs rename to Models/Account/LoginViewModel.cs diff --git a/Quickstart/Account/LogoutInputModel.cs b/Models/Account/LogoutInputModel.cs similarity index 100% rename from Quickstart/Account/LogoutInputModel.cs rename to Models/Account/LogoutInputModel.cs diff --git a/Quickstart/Account/LogoutViewModel.cs b/Models/Account/LogoutViewModel.cs similarity index 100% rename from Quickstart/Account/LogoutViewModel.cs rename to Models/Account/LogoutViewModel.cs diff --git a/Quickstart/Account/RedirectViewModel.cs b/Models/Account/RedirectViewModel.cs similarity index 100% rename from Quickstart/Account/RedirectViewModel.cs rename to Models/Account/RedirectViewModel.cs diff --git a/Quickstart/Consent/ConsentInputModel.cs b/Models/Consent/ConsentInputModel.cs similarity index 100% rename from Quickstart/Consent/ConsentInputModel.cs rename to Models/Consent/ConsentInputModel.cs diff --git a/Quickstart/Consent/ConsentOptions.cs b/Models/Consent/ConsentOptions.cs similarity index 100% rename from Quickstart/Consent/ConsentOptions.cs rename to Models/Consent/ConsentOptions.cs diff --git a/Quickstart/Consent/ConsentViewModel.cs b/Models/Consent/ConsentViewModel.cs similarity index 100% rename from Quickstart/Consent/ConsentViewModel.cs rename to Models/Consent/ConsentViewModel.cs diff --git a/Quickstart/Consent/ParsedScopes.cs b/Models/Consent/ParsedScopes.cs similarity index 100% rename from Quickstart/Consent/ParsedScopes.cs rename to Models/Consent/ParsedScopes.cs diff --git a/Quickstart/Consent/ProcessConsentResult.cs b/Models/Consent/ProcessConsentResult.cs similarity index 100% rename from Quickstart/Consent/ProcessConsentResult.cs rename to Models/Consent/ProcessConsentResult.cs diff --git a/Quickstart/Consent/QSAuthorizationRequest.cs b/Models/Consent/QSAuthorizationRequest.cs similarity index 100% rename from Quickstart/Consent/QSAuthorizationRequest.cs rename to Models/Consent/QSAuthorizationRequest.cs diff --git a/Quickstart/Consent/ScopeViewModel.cs b/Models/Consent/ScopeViewModel.cs similarity index 100% rename from Quickstart/Consent/ScopeViewModel.cs rename to Models/Consent/ScopeViewModel.cs diff --git a/Quickstart/Consent/ValidatedResource.cs b/Models/Consent/ValidatedResource.cs similarity index 100% rename from Quickstart/Consent/ValidatedResource.cs rename to Models/Consent/ValidatedResource.cs diff --git a/Quickstart/Device/DeviceAuthorizationInputModel.cs b/Models/Device/DeviceAuthorizationInputModel.cs similarity index 100% rename from Quickstart/Device/DeviceAuthorizationInputModel.cs rename to Models/Device/DeviceAuthorizationInputModel.cs diff --git a/Quickstart/Device/DeviceAuthorizationViewModel.cs b/Models/Device/DeviceAuthorizationViewModel.cs similarity index 100% rename from Quickstart/Device/DeviceAuthorizationViewModel.cs rename to Models/Device/DeviceAuthorizationViewModel.cs diff --git a/Quickstart/Device/DeviceController.cs b/Models/Device/DeviceController.cs similarity index 100% rename from Quickstart/Device/DeviceController.cs rename to Models/Device/DeviceController.cs diff --git a/Quickstart/Diagnostics/DiagnosticsViewModel.cs b/Models/Diagnostic/DiagnosticsViewModel.cs similarity index 100% rename from Quickstart/Diagnostics/DiagnosticsViewModel.cs rename to Models/Diagnostic/DiagnosticsViewModel.cs diff --git a/Models/ErrorViewModel.cs b/Models/ErrorViewModel.cs index 1ab3aa4..fd46706 100644 --- a/Models/ErrorViewModel.cs +++ b/Models/ErrorViewModel.cs @@ -1,4 +1,5 @@ using System; +using IdentityServer4.Models; namespace nuget_host.Models { @@ -7,5 +8,18 @@ namespace nuget_host.Models public string RequestId { get; set; } public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + + + public ErrorViewModel() + { + } + + public ErrorViewModel(string error) + { + Error = new ErrorMessage { Error = error }; + } + + public ErrorMessage Error { get; set; } + } } \ No newline at end of file diff --git a/Quickstart/Grants/GrantsViewModel.cs b/Models/Grants/GrantsViewModel.cs similarity index 100% rename from Quickstart/Grants/GrantsViewModel.cs rename to Models/Grants/GrantsViewModel.cs diff --git a/Quickstart/SecurityHeadersAttribute.cs b/Models/SecurityHeadersAttribute.cs similarity index 100% rename from Quickstart/SecurityHeadersAttribute.cs rename to Models/SecurityHeadersAttribute.cs diff --git a/Quickstart/TestUsers.cs b/Models/TestUsers.cs similarity index 100% rename from Quickstart/TestUsers.cs rename to Models/TestUsers.cs diff --git a/Quickstart/Home/ErrorViewModel.cs b/Quickstart/Home/ErrorViewModel.cs deleted file mode 100644 index a29a21a..0000000 --- a/Quickstart/Home/ErrorViewModel.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) Brock Allen & Dominick Baier. All rights reserved. -// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. - - -using IdentityServer4.Models; - -namespace IdentityServerHost.Quickstart.UI -{ - public class ErrorViewModel - { - public ErrorViewModel() - { - } - - public ErrorViewModel(string error) - { - Error = new ErrorMessage { Error = error }; - } - - public ErrorMessage Error { get; set; } - } -} \ No newline at end of file diff --git a/Quickstart/Home/HomeController.cs b/Quickstart/Home/HomeController.cs deleted file mode 100644 index 871c637..0000000 --- a/Quickstart/Home/HomeController.cs +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) Brock Allen & Dominick Baier. All rights reserved. -// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. - - -using IdentityServer4.Services; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; -using System.Threading.Tasks; - -namespace IdentityServerHost.Quickstart.UI -{ - [SecurityHeaders] - [AllowAnonymous] - public class HomeController : Controller - { - private readonly IIdentityServerInteractionService _interaction; - private readonly ILogger _logger; - IHostingEnvironment _environment; - - public HomeController(IIdentityServerInteractionService interaction, Microsoft.AspNetCore.Hosting.IHostingEnvironment environment, ILogger logger) - { - _interaction = interaction; - _environment = environment; - _logger = logger; - } - - public IActionResult Index() - { - if (_environment.IsDevelopment()) - { - // only show in development - return View(); - } - - _logger.LogInformation("Homepage is disabled in production. Returning 404."); - return NotFound(); - } - - /// - /// Shows the error page - /// - public async Task Error(string errorId) - { - var vm = new ErrorViewModel(); - - // retrieve error details from identityserver - var message = await _interaction.GetErrorContextAsync(errorId); - if (message != null) - { - vm.Error = message; - - if (!_environment.IsDevelopment()) - { - // only show in development - message.ErrorDescription = null; - } - } - - return View("Error", vm); - } - } -} \ No newline at end of file