WebApiTools.Authentication.Bearer 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package WebApiTools.Authentication.Bearer --version 1.0.1
                    
NuGet\Install-Package WebApiTools.Authentication.Bearer -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WebApiTools.Authentication.Bearer" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WebApiTools.Authentication.Bearer" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="WebApiTools.Authentication.Bearer" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WebApiTools.Authentication.Bearer --version 1.0.1
                    
#r "nuget: WebApiTools.Authentication.Bearer, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package WebApiTools.Authentication.Bearer@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=WebApiTools.Authentication.Bearer&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=WebApiTools.Authentication.Bearer&version=1.0.1
                    
Install as a Cake Tool

Nuget Nuget

WebApiTools.Authentication.Bearer

This library provides extensions to easily configure JWT Bearer Authentication in your ASP.NET Core applications.

1. Quick Setup (Simplest)

If your configuration file contains a JwtOptions section, you can add authentication in one line:

var builder = WebApplication.CreateBuilder(args);

builder.AddJwtAuthentication();

var app = builder.Build();
app.UseCors();
app.UseJwtAuthentication();
app.UseHttpsRedirection();

2. Using Configuration Section Explicitly

If you want to be explicit about where the configuration comes from:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddJwtAuthentication(builder.Configuration);

var app = builder.Build();
app.UseCors();
app.UseJwtAuthentication();
app.UseHttpsRedirection();

3. Full Customization (Manual Options Binding)

If you prefer to configure JwtOptions programmatically:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddJwtAuthentication(options =>
{
    options.Issuer = "MyIssuer";
    options.Audience = "MyAudience";
    options.SecretKey = "SuperSecretKey123456";
    options.ExpirationInDays = 7;
    options.ValidateIssuer = true;
    options.ValidateAudience = true;
    options.ValidateLifetime = true;
    options.ValidateIssuerSigningKey = true;
});

var app = builder.Build();
app.UseCors();
app.UseJwtAuthentication();
app.UseHttpsRedirection();

JwtOptions Configuration

JwtOptions allows you to configure:

  • Issuer: The expected token issuer.
  • Audience: The expected token audience.
  • SecretKey: The symmetric security key used for signing tokens.
  • ExpirationInDays: Default token expiration.
  • ValidateIssuer: Whether to validate the issuer.
  • ValidateAudience: Whether to validate the audience.
  • ValidateLifetime: Whether to check token expiration.
  • ValidateIssuerSigningKey: Whether to validate the signing key.

Best Practices

  1. Always store SecretKey securely (use environment variables or secrets manager).
  2. Place app.UseJwtAuthentication(); before mapping endpoints.
  3. Use the simplest overload unless you need advanced customization.
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.4 248 12/25/2025
1.1.3 212 12/24/2025
1.1.2 222 11/27/2025
1.0.1 240 11/25/2025
1.0.0 239 8/17/2025

Update to NET 10. Refactor extension method.