Configuring JWT Bearer Authentication
Wire up token validation in the pipeline.
The JWT Bearer Handler
ASP.NET Core validates incoming JWTs using the JWT Bearer authentication handler from the Microsoft.AspNetCore.Authentication.JwtBearer package.
It reads the token from the Authorization: Bearer ... header, validates it, and builds a ClaimsPrincipal.
dotnet add package Microsoft.AspNetCore.Authentication.JwtBearerAddAuthentication
Registration starts with AddAuthentication. You set the default scheme so the framework knows which handler to use when no scheme is specified.
JwtBearerDefaults.AuthenticationScheme is the string "Bearer".
builder.Services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer();All lessons in this course
- JWT Structure and Claims
- Configuring JWT Bearer Authentication
- Issuing Tokens
- Refresh Tokens and Expiry