JWT Authentication Configuration in DotNet 7
Shehryar Khan
Shehryar Khan
August 01, 2022
1 min

Table Of Contents

JWT Authentication Configuration Before .Net 7
Simplified JWT Configuration


Microsoft Announced .Net 7 Preview 5 with some great improvements. Here’s what’s new in Preview 5.

  • JWT Authentication Improvements and Automatic configuration.
  • Minimal API’s parameter binding support for argument list simplification.

I just installed Preview 5 to check JWT Authentication Configuration. If you also want to update your existing project to .Net 7 preview 5, here’s the quick way.

Update all Microsoft.AspNetCore.* package references to 7.0.0-preview.5.*.
Update all Microsoft.Extensions.* package references to 7.0.0-preview.5.*.

JWT Authentication Configuration Before .Net 7

Microsoft Stated they have received feedbacks that Configuring JWT in ASP.NET Core project is one of the hardest part of writing API. It required many steps including adding middleware at startup process & configuring services.

.Net Team knows the importance of JWT configuration in securing API that’s why they improved & simplified the process of configuring JWT Authentication in ASP.NET Core project.

Simplified JWT Configuration

Authentication options can now be configured automatically directly from the configuration system, due to the addition of a default configuration section when configuring via the new Authentication property on WebApplicationBuilder

var builder = WebApplication.CreateBuilder(args);

builder.Authentication.AddJwtBearer(); // New property

var app = builder.Build();

Setting up JWT Authentication using this new property will automatically add required middleware in a same way that WebApplicationBuilder does for routing.

On top of that, individual authentication schemes will set options parameters from appsettings.json automatically. That always help developers to configure parameters between development & production environment.

Here’s how appsettings.json file will look after adding authentication options.

  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
  "AllowedHosts": "*",
  "Authentication": {
    "DefaultScheme" : "JwtBearer",
    "Schemes": {
      "JwtBearer": {
        "Audiences": [ "http://localhost:5000", "https://localhost:5001" ],
        "ClaimsIssuer": "user-jwt-here"

It’s all about configuring JWT using .Net 7 preview 5. I haven’t tested other improvements coming with preview 5 but I can say that this improvement will really help developers to save their project setup time.

If you want to read about what’s coming with .Net 7. Please check this.

Related Articles:

What’s coming with .NET 7?

What is the Future of .NET?


Shehryar Khan

Shehryar Khan

Full-Stack .NET Developer

I'm passionate about learning new technologies as well as mentoring and helping others get started with their programming career. This blog is my way of giving back to the Community.



Social Media


Related Posts

What’s coming with .NET 7 ?
July 28, 2022
3 min
© 2022, All Rights Reserved.

Quick Links

Advertise with usContact Us

Social Media