C# 将自定义令牌RequestValidator添加到ASP.NET(非核心)
我想用自定义验证器替换默认的请求令牌验证器。用于此的IdentityServer文档表明自定义验证器已在ASP.NET Core Startup.cs ConfigureServices()中注册,但我使用的应用程序是ASP.NET/.NET 4.5 如何在ASP.NET应用程序中注册自定义验证程序C# 将自定义令牌RequestValidator添加到ASP.NET(非核心),c#,.net,identityserver3,C#,.net,Identityserver3,我想用自定义验证器替换默认的请求令牌验证器。用于此的IdentityServer文档表明自定义验证器已在ASP.NET Core Startup.cs ConfigureServices()中注册,但我使用的应用程序是ASP.NET/.NET 4.5 如何在ASP.NET应用程序中注册自定义验证程序 // My understanding is that this how I would add my validator with Core. public void ConfigureServi
// My understanding is that this how I would add my validator with Core.
public void ConfigureServices(IServiceCollection services)
{
var builder = services.AddIdentityServer()
.AddCustomTokenRequestValidator<MyCustomRequestValidator>();
}
//我的理解是,这就是我将如何添加带核心的验证器。
public void配置服务(IServiceCollection服务)
{
var builder=services.AddIdentityServer()
.AddCustomTokenRequestValidator();
}
这很容易。在startup.cs
ConfigureService
中,您可以指定要使用的验证器。我对项目代码使用JWT身份验证,如下所示:
// Jwt Authentication
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(key),
ValidateIssuer = false,
ValidateActor = false,
};
});
注意:对于这段代码,我使用了库
使用Microsoft.AspNetCore.Authentication.JwtBearer代码>
我希望这有帮助。如果你需要进一步的帮助,你可以在你的问题中添加更多的细节,我会帮助你