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

Table Of Contents

01
Introduction
02
JWT Authentication Configuration Before .Net 7
03
Simplified JWT Configuration

Introduction

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?


Tags

#dotnet7#jwt#featured
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.

Expertise

.NET
ASP.NET
React

Social Media

instagramtwitterwebsite

Related Posts

Features
What’s coming with .NET 7 ?
July 28, 2022
3 min
Dart Tips & Tricks
Android
Exploring Android MenuProvider API With Activity & Fragment | Example
September 04, 2023
3 min
Dart Tips & Tricks
Dart
Dart Programming list collection tips & tricks
August 30, 2023
2 min
C# 11
C#
What's New in C# 11 | 12 Features with Code Examples
August 23, 2022
2 min
© 2023, All Rights Reserved.

Quick Links

Advertise with usContact Us

Social Media