ASP.NET Core › Authentication

How does JWT bearer authentication validate an incoming token, and what claims does TokenValidationParameters check?

Advanced

Answer

The JWT bearer handler extracts the token from the Authorization: Bearer header, verifies its cryptographic signature against the configured signing key, and validates standard claims per TokenValidationParameters -- expiration (exp), not-before (nbf), issuer (iss must match ValidIssuer), and audience (aud must match ValidAudience) -- rejecting the request with 401 if any check fails, all before the request reaches your endpoint code.
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
    .AddJwtBearer(options => {
        options.TokenValidationParameters = new TokenValidationParameters {
            ValidateIssuerSigningKey = true,
            IssuerSigningKey = new SymmetricSecurityKey(key),
            ValidateIssuer = true, ValidIssuer = "myapp",
            ValidateAudience = true, ValidAudience = "myapp-api",
            ValidateLifetime = true
        };
    });
Real-world example A stateless microservices API validates every incoming JWT's signature and claims on each request without any server-side session lookup, letting it scale horizontally without shared session state.

Common follow-ups: How do you fetch signing keys dynamically from an identity provider's JWKS endpoint instead of hardcoding them?;What happens if ClockSkew isn't configured for distributed systems with slightly different clocks?