RA.Utilities.Authentication.JwtBearer 10.0.0

Prefix Reserved
dotnet add package RA.Utilities.Authentication.JwtBearer --version 10.0.0
                    
NuGet\Install-Package RA.Utilities.Authentication.JwtBearer -Version 10.0.0
                    
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="RA.Utilities.Authentication.JwtBearer" Version="10.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RA.Utilities.Authentication.JwtBearer" Version="10.0.0" />
                    
Directory.Packages.props
<PackageReference Include="RA.Utilities.Authentication.JwtBearer" />
                    
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 RA.Utilities.Authentication.JwtBearer --version 10.0.0
                    
#r "nuget: RA.Utilities.Authentication.JwtBearer, 10.0.0"
                    
#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 RA.Utilities.Authentication.JwtBearer@10.0.0
                    
#: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=RA.Utilities.Authentication.JwtBearer&version=10.0.0
                    
Install as a Cake Addin
#tool nuget:?package=RA.Utilities.Authentication.JwtBearer&version=10.0.0
                    
Install as a Cake Tool

RA.Utilities.Authentication.JwtBearer

NuGet version Codecov NuGet Downloads Documentation GitHub license

RA.Utilities.Authentication.JwtBearer is a utility library that simplifies the configuration of JWT Bearer authentication in ASP.NET Core. It solves the problem of having complex, hardcoded authentication setup in your Program.cs by allowing you to configure everything from your appsettings.json file.

This approach reduces boilerplate code and makes your authentication settings easier to manage across different environments.

Getting started

Install the package via the .NET CLI:

dotnet add package RA.Utilities.Authentication.JwtBearer

🔗 Dependencies

Usage

In your Program.cs (for minimal APIs) or Startup.cs, use the AddJwtBearerAuthentication extension method to configure authentication and authorization services.

Program.cs (ASP.NET Core 6+)

using RA.Utilities.Authentication.JwtBearer.Extensions;

var builder = WebApplication.CreateBuilder(args);

// 1. Add and configure JWT Bearer authentication using settings from IConfiguration.
// This single call reads from "appsettings.json" and registers authentication services.
builder.Services.AddJwtBearerAuthentication(builder.Configuration);

var app = builder.Build();

// 2. Add the authentication and authorization middleware.
app.UseAuth(); // This is a convenience method for app.UseAuthentication() and app.UseAuthorization().

app.MapGet("/", () => "Hello World!");

app.Run();

Configuration

This library reads JWT Bearer options from the Authentication:Schemes:Bearer section of your configuration file (e.g., appsettings.json).

Here is an example appsettings.json configuration:

{
  "Authentication": {
    "Schemes": {
      "Bearer": {
        "Authority": "https://your-identity-provider.com/",
        "Audience": "your-api-audience",
        "TokenValidationParameters": {
          "ValidateIssuer": true,
          "ValidateAudience": true,
          "ValidateLifetime": true,
          "ValidateIssuerSigningKey": true,
          "ClockSkewInSeconds": 30,
          "IssuerSigningKeyString": "your-super-secret-key-that-is-long-enough-for-the-algorithm"
        }
      }
    }
  }
}

When using an identity provider (Authority), you typically don't need to specify ValidIssuer, ValidAudience, or IssuerSigningKey as these are discovered from the metadata endpoint. The example above shows settings for validating a self-issued token.

The library automatically binds these settings to JwtBearerOptions. It also provides special handling for:

  • ClockSkewInSeconds: Converts this integer value into a TimeSpan for TokenValidationParameters.ClockSkew.
  • IssuerSigningKeyString: Converts this string into a SymmetricSecurityKey for TokenValidationParameters.IssuerSigningKey.

Additional documentation

For more information on how this package fits into the larger RA.Utilities ecosystem, please see the main repository documentation.

Contributing

Contributions are welcome! If you have a suggestion or find a bug, please open an issue to discuss it.

Pull Request Process

  1. Fork the Repository: Start by forking the RA.Utilities repository.
  2. Create a Branch: Create a new branch for your feature or bug fix from the main branch. Please use a descriptive name (e.g., feature/add-claim-support or fix/readme-typo).
  3. Make Your Changes: Write your code, ensuring it adheres to the existing coding style. Add or update XML documentation for any new public APIs.
  4. Update README: If you are adding new functionality, please update the README.md file accordingly.
  5. Submit a Pull Request: Push your branch to your fork and open a pull request to the main branch of the original repository. Provide a clear description of the changes you have made.

Coding Standards

  • Follow the existing coding style and conventions used in the project.
  • Ensure all public members are documented with clear XML comments.
  • Keep changes focused. A pull request should address a single feature or bug.

Thank you for contributing!

Product Compatible and additional computed target framework versions.
.NET 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
10.0.0 185 11/25/2025
10.0.0-rc.2 95 10/31/2025
1.0.0 185 11/24/2025
1.0.0-preview.6.3 240 11/16/2025