No authenticationScheme was specified 🟪 .NET

InvalidOperationException: No authenticationScheme was specified, and there was no DefaultChallengeScheme found

[Authorize] triggered a challenge, but no authentication handler/default scheme is configured.

Seen on: .NET

Meaning

AddAuthentication() was called without a default scheme, or not called at all, or UseAuthentication is missing. Specify a default scheme or set schemes on [Authorize].

Common causes

  • AddAuthentication() without default scheme
  • Authentication handler not registered (AddJwtBearer/AddCookie)
  • UseAuthentication/UseAuthorization order wrong

⚡ Quick fix

  1. Use AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
  2. Register the handler
  3. Call app.UseAuthentication() before app.UseAuthorization()

Detailed fix by platform

C#

  1. csharp
    builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer();
    app.UseAuthentication();
    app.UseAuthorization();

How to diagnose

  1. Registration — Schemes configured?
  2. Middleware — Order

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.