0

A little background for this question, we have configured an OnTokenValidated event for our preferred Authorization scheme in the following fashion.

public void ConfigureServices(IServiceCollection services)
{
    services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
        .AddJwtBearer(builder =>
        {
            builder.Events = new JwtBearerEvents
            {
                OnTokenValidated = ctx =>
                {
                    DoSomething(ctx);
                    return Task.CompletedTask;
                }
            }
        });
}

But there are some Controller actions where we don't want this event to be triggered. However we found that even if the controller has [AllowAnonymous], if a Bearer token is provided, the token will still be verified and this event is triggered.

Is there another mechanism to instruct the ASP.NET Core middleware to skip validating a token, even if it is provided?

Nino van der Mark
  • 622
  • 1
  • 9
  • 19

0 Answers0