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
<PackageReference Include="RA.Utilities.Authentication.JwtBearer" Version="10.0.0" />
<PackageVersion Include="RA.Utilities.Authentication.JwtBearer" Version="10.0.0" />
<PackageReference Include="RA.Utilities.Authentication.JwtBearer" />
paket add RA.Utilities.Authentication.JwtBearer --version 10.0.0
#r "nuget: RA.Utilities.Authentication.JwtBearer, 10.0.0"
#:package RA.Utilities.Authentication.JwtBearer@10.0.0
#addin nuget:?package=RA.Utilities.Authentication.JwtBearer&version=10.0.0
#tool nuget:?package=RA.Utilities.Authentication.JwtBearer&version=10.0.0
RA.Utilities.Authentication.JwtBearer
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 aTimeSpanforTokenValidationParameters.ClockSkew.IssuerSigningKeyString: Converts this string into aSymmetricSecurityKeyforTokenValidationParameters.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
- Fork the Repository: Start by forking the RA.Utilities repository.
- Create a Branch: Create a new branch for your feature or bug fix from the
mainbranch. Please use a descriptive name (e.g.,feature/add-claim-supportorfix/readme-typo). - Make Your Changes: Write your code, ensuring it adheres to the existing coding style. Add or update XML documentation for any new public APIs.
- Update README: If you are adding new functionality, please update the
README.mdfile accordingly. - Submit a Pull Request: Push your branch to your fork and open a pull request to the
mainbranch 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 | Versions 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. |
-
net10.0
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 10.0.0)
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 |