Да.Вы можете отключить / обработать Challenge
, а также другие события, такие как TokenValidated
, MessageReceived
и AuthenticationFailed
, установив свойство Events
JwtBearerOptions
и предоставив свои собственные методы, как показано ниже:
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
#region Custom Code Added Here
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters();
//Override the JWT Events
options.Events = new JwtBearerEvents()
{
OnChallenge = context =>
{
//custom logic goes here. At the end of your logic make sure that you
//"Handle" the response by calling HandleResponse, and return a 0.
context.HandleResponse();
return Task.FromResult(0);
}
};
});
#endregion
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}