check user validation in Asp.net core with jwt authorization

前端 未结 2 485
暗喜
暗喜 2021-01-16 03:15

I implemented Microsoft Identity and JWT in my web api, a client can login and get a JWT token and store it in the application. since the expiration of the token the user

2条回答
  •  逝去的感伤
    2021-01-16 03:55

    Another option is to implement and register your own SecurityTokenValidator. To do so you need to create a class implemented ISecurityTokenValidator interface:

    //using Microsoft.IdentityModel.Tokens
    
    public class CustomValidator : ISecurityTokenValidator
    {
       //interface implementation
       ...
    }
    

    and register it as an additional token validator via JwtBearerOptions.SecurityTokenValidators property:

    services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
        .AddJwtBearer( options => {
    
            options.SecurityTokenValidators.Add(new CustomValidator()) 
        });
    

提交回复
热议问题