简体   繁体   English

将自定义令牌 RequestValidator 添加到 ASP.NET(不是核心)

[英]Add Custom Token RequestValidator to ASP.NET (not Core)

I would like to replace the default request token validator with a custom validator.我想用自定义验证器替换默认请求令牌验证器。 The IdentityServer documentation for this indicates that the custom validator is registered in ASP.NET Core Startup.cs ConfigureServices(), but the application I'm working with is ASP.NET/.NET 4.5. IdentityServer 文档表明自定义验证器已在 ASP.NET Core Startup.cs ConfigureServices() 中注册,但我正在使用的应用程序是 ASP.NET/.NET 4.5。

How can I register the custom validator in an ASP.NET application?如何在 ASP.NET 应用程序中注册自定义验证器?

// My understanding is that this how I would add my validator with Core.
public void ConfigureServices(IServiceCollection services)
{
    var builder = services.AddIdentityServer()
        .AddCustomTokenRequestValidator<MyCustomRequestValidator>();
}

It is very easy.这很容易。 In the startup.cs > ConfigureService You can specify which validator you want use.startup.cs > ConfigureService中,您可以指定要使用的验证器。 I use JWT authentication for a project code is following:我对项目代码使用 JWT 身份验证如下:

// Jwt Authentication
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
  {
       options.TokenValidationParameters = new TokenValidationParameters
        {
                ValidateIssuerSigningKey = true,
                IssuerSigningKey = new SymmetricSecurityKey(key),
                ValidateIssuer = false,
                ValidateActor = false,
        };
   });

Note: for this piece of code I used the library注意:对于这段代码,我使用了库

using Microsoft.AspNetCore.Authentication.JwtBearer;

I wish this helped.我希望这有帮助。 If you need further help you can add more details to your question I will help you.如果您需要进一步的帮助,您可以在您的问题中添加更多详细信息,我会帮助您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM