Remove `AttachAbpCustomChallengeErrors`.

pull/14554/head
maliming 3 years ago
parent 977416cc07
commit a83221f5dd
No known key found for this signature in database
GPG Key ID: 096224957E51C89E

@ -5,7 +5,6 @@ using OpenIddict.Server;
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 @@ public class AbpOpenIddictAspNetCoreModule : AbpModule
builder.AddEventHandler(AbpValidatePostLogoutRedirectUriParameter.Descriptor);
}
builder.AddEventHandler(AttachAbpCustomChallengeErrors.Descriptor);
builder.AddEventHandler(RemoveClaimsFromClientCredentialsGrantType.Descriptor);
services.ExecutePreConfiguredActions(builder);

@ -193,14 +193,18 @@ public partial class TokenController
ClientId = request.ClientId
});
var properties = new AuthenticationProperties(new Dictionary<string, string>
{
[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<string, string>
{
[OpenIddictServerAspNetCoreConstants.Properties.Error] = OpenIddictConstants.Errors.InvalidGrant,
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] =
nameof(SignInResult.RequiresTwoFactor),
},
parameters: new Dictionary<string, object>
{
["userId"] = user.Id.ToString("N"),
["twoFactorToken"] = twoFactorToken
});
return Forbid(properties, OpenIddictServerAspNetCoreDefaults.AuthenticationScheme);
}

@ -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<OpenIddictServerEvents.ProcessChallengeContext>
{
private static readonly List<string> CustomChallengeErrors = new List<string>()
{
"userId",
"twoFactorToken"
};
public static OpenIddictServerHandlerDescriptor Descriptor { get; }
= OpenIddictServerHandlerDescriptor.CreateBuilder<OpenIddictServerEvents.ProcessChallengeContext>()
.UseSingletonHandler<AttachAbpCustomChallengeErrors>()
.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<AuthenticationProperties>();
if (properties != null)
{
foreach (var property in properties.Items.Where(x => CustomChallengeErrors.Contains(x.Key)))
{
context.Response.SetParameter(property.Key, property.Value);
}
}
return default;
}
}
Loading…
Cancel
Save