mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-19 10:08:04 +08:00
转移.net core 3.1,为.NET 5做准备
This commit is contained in:
22
OpenAuth.Identity/Quickstart/Home/ErrorViewModel.cs
Normal file
22
OpenAuth.Identity/Quickstart/Home/ErrorViewModel.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
// 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 OpenAuth.IdentityServer.Quickstart.Home
|
||||
{
|
||||
public class ErrorViewModel
|
||||
{
|
||||
public ErrorViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public ErrorViewModel(string error)
|
||||
{
|
||||
Error = new ErrorMessage { Error = error };
|
||||
}
|
||||
|
||||
public ErrorMessage Error { get; set; }
|
||||
}
|
||||
}
|
64
OpenAuth.Identity/Quickstart/Home/HomeController.cs
Normal file
64
OpenAuth.Identity/Quickstart/Home/HomeController.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
// 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 System.Threading.Tasks;
|
||||
using IdentityServer4.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace OpenAuth.IdentityServer.Quickstart.Home
|
||||
{
|
||||
[SecurityHeaders]
|
||||
[AllowAnonymous]
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly IIdentityServerInteractionService _interaction;
|
||||
private readonly IHostEnvironment _environment;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public HomeController(IIdentityServerInteractionService interaction, IHostEnvironment environment, ILogger<HomeController> 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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows the error page
|
||||
/// </summary>
|
||||
public async Task<IActionResult> 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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user