Merge pull request #14545 from abpframework/AttachAbpCustomChallengeError

pull/14546/head
liangshiwei 3 years ago committed by GitHub
commit 953746d76c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

@ -0,0 +1,40 @@
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