From 429bf596a1c59340987a675b56c87b26b371a447 Mon Sep 17 00:00:00 2001 From: maliming <6908465+maliming@users.noreply.github.com> Date: Thu, 13 Aug 2020 10:19:23 +0800 Subject: [PATCH 1/2] Add Identity service error page to account module. --- .../AbpAccountWebIdentityServerModule.cs | 9 ++++- .../Pages/Account/Error.cshtml | 24 ++++++++++++ .../Pages/Account/Error.cshtml.cs | 37 +++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml create mode 100644 modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml.cs diff --git a/modules/account/src/Volo.Abp.Account.Web.IdentityServer/AbpAccountWebIdentityServerModule.cs b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/AbpAccountWebIdentityServerModule.cs index 273659fd69..bf76e1dbe3 100644 --- a/modules/account/src/Volo.Abp.Account.Web.IdentityServer/AbpAccountWebIdentityServerModule.cs +++ b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/AbpAccountWebIdentityServerModule.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Identity; +using IdentityServer4.Configuration; +using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Identity.AspNetCore; using Volo.Abp.IdentityServer; @@ -33,6 +34,12 @@ namespace Volo.Abp.Account.Web options.FileSets.AddEmbedded(); }); + Configure(options => + { + options.UserInteraction.ConsentUrl = "/Consent"; + options.UserInteraction.ErrorUrl = "/Account/Error"; + }); + //TODO: Try to reuse from AbpIdentityAspNetCoreModule context.Services .AddAuthentication(o => diff --git a/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml new file mode 100644 index 0000000000..2b43f1527c --- /dev/null +++ b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml @@ -0,0 +1,24 @@ +@page +@using Localization.Resources.AbpUi +@using Microsoft.AspNetCore.Mvc.Localization +@model Volo.Abp.Account.Web.Pages.Account.ErrorModel +@inject IHtmlLocalizer L +@{ + var errorMessage = Model.ErrorMessage.Error; + var errorDetails = Model.ErrorMessage.ErrorDescription; + if (errorDetails.IsNullOrEmpty()) + { + errorDetails = errorMessage; + errorMessage = L["Error"].Value + "!"; + } +} + +

+ @errorMessage +

+ +
+

+ @errorDetails +

+
diff --git a/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml.cs b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml.cs new file mode 100644 index 0000000000..bae4eb380e --- /dev/null +++ b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml.cs @@ -0,0 +1,37 @@ +using System.Threading.Tasks; +using IdentityServer4.Models; +using IdentityServer4.Services; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; +using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; + +namespace Volo.Abp.Account.Web.Pages.Account +{ + public class ErrorModel : AbpPageModel + { + public ErrorMessage ErrorMessage { get; set; } + + private readonly IIdentityServerInteractionService _interaction; + private readonly IWebHostEnvironment _environment; + + public ErrorModel(IIdentityServerInteractionService interaction, IWebHostEnvironment environment) + { + _interaction = interaction; + _environment = environment; + } + + public async Task OnGet(string errorId) + { + ErrorMessage = await _interaction.GetErrorContextAsync(errorId); + + if (ErrorMessage != null) + { + if (!_environment.IsDevelopment()) + { + // Only show in development + ErrorMessage.ErrorDescription = null; + } + } + } + } +} From daf7febe7c87ff8ec81927b6d5bb18778afe0ee4 Mon Sep 17 00:00:00 2001 From: maliming <6908465+maliming@users.noreply.github.com> Date: Thu, 13 Aug 2020 10:30:44 +0800 Subject: [PATCH 2/2] Handle ErrorMessage is null. --- .../Pages/Account/Error.cshtml.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml.cs b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml.cs index bae4eb380e..90622f7dc3 100644 --- a/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml.cs +++ b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Error.cshtml.cs @@ -22,7 +22,10 @@ namespace Volo.Abp.Account.Web.Pages.Account public async Task OnGet(string errorId) { - ErrorMessage = await _interaction.GetErrorContextAsync(errorId); + ErrorMessage = await _interaction.GetErrorContextAsync(errorId) ?? new ErrorMessage + { + Error = L["Error"] + }; if (ErrorMessage != null) {