From a83221f5dd0d7304c997903437951cc58f2120c6 Mon Sep 17 00:00:00 2001 From: maliming Date: Sun, 6 Nov 2022 17:37:41 +0800 Subject: [PATCH] Remove `AttachAbpCustomChallengeErrors`. --- .../AbpOpenIddictAspNetCoreModule.cs | 2 - .../Controllers/TokenController.Password.cs | 20 ++++++---- .../AttachAbpCustomChallengeErrors.cs | 40 ------------------- 3 files changed, 12 insertions(+), 50 deletions(-) delete mode 100644 modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Handlers/AttachAbpCustomChallengeErrors.cs diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/AbpOpenIddictAspNetCoreModule.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/AbpOpenIddictAspNetCoreModule.cs index 76d780104ba..e8196627ce2 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/AbpOpenIddictAspNetCoreModule.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/AbpOpenIddictAspNetCoreModule.cs @@ -5,7 +5,6 @@ using Volo.Abp.AspNetCore.MultiTenancy; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; using Volo.Abp.Modularity; -using Volo.Abp.OpenIddict.Handlers; using Volo.Abp.OpenIddict.WildcardDomains; using Volo.Abp.Security.Claims; @@ -130,7 +129,6 @@ private void AddOpenIddictServer(IServiceCollection services) builder.AddEventHandler(AbpValidatePostLogoutRedirectUriParameter.Descriptor); } - builder.AddEventHandler(AttachAbpCustomChallengeErrors.Descriptor); builder.AddEventHandler(RemoveClaimsFromClientCredentialsGrantType.Descriptor); services.ExecutePreConfiguredActions(builder); diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs index 49d415c927e..74fa358e3cc 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs @@ -193,14 +193,18 @@ await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext ClientId = request.ClientId }); - var properties = new AuthenticationProperties(new Dictionary - { - [OpenIddictServerAspNetCoreConstants.Properties.Error] = OpenIddictConstants.Errors.InvalidGrant, - [OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = nameof(SignInResult.RequiresTwoFactor), - - ["userId"] = user.Id.ToString("N"), - ["twoFactorToken"] = twoFactorToken - }); + var properties = new AuthenticationProperties( + items: new Dictionary + { + [OpenIddictServerAspNetCoreConstants.Properties.Error] = OpenIddictConstants.Errors.InvalidGrant, + [OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = + nameof(SignInResult.RequiresTwoFactor), + }, + parameters: new Dictionary + { + ["userId"] = user.Id.ToString("N"), + ["twoFactorToken"] = twoFactorToken + }); return Forbid(properties, OpenIddictServerAspNetCoreDefaults.AuthenticationScheme); } diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Handlers/AttachAbpCustomChallengeErrors.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Handlers/AttachAbpCustomChallengeErrors.cs deleted file mode 100644 index 1bea7d839be..00000000000 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Handlers/AttachAbpCustomChallengeErrors.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authentication; -using OpenIddict.Server; - -namespace Volo.Abp.OpenIddict.Handlers; - -public class AttachAbpCustomChallengeErrors : IOpenIddictServerHandler -{ - private static readonly List CustomChallengeErrors = new List() - { - "userId", - "twoFactorToken" - }; - - public static OpenIddictServerHandlerDescriptor Descriptor { get; } - = OpenIddictServerHandlerDescriptor.CreateBuilder() - .UseSingletonHandler() - .SetOrder(OpenIddictServerHandlers.AttachDefaultChallengeError.Descriptor.Order + 1) - .SetType(OpenIddictServerHandlerType.Custom) - .Build(); - - public ValueTask HandleAsync(OpenIddictServerEvents.ProcessChallengeContext context) - { - Check.NotNull(context, nameof(context)); - - var properties = context.Transaction.Properties[typeof(AuthenticationProperties).FullName!].As(); - if (properties != null) - { - foreach (var property in properties.Items.Where(x => CustomChallengeErrors.Contains(x.Key))) - { - context.Response.SetParameter(property.Key, property.Value); - } - } - - return default; - } -}