qckdev.AspNetCore.Authentication.JwtBearer 0.3.0-net10.1581

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

NuGet Version Quality Gate Code Coverage Azure Pipelines Status

qckdev.AspNetCore.Authentication.JwtBearer

Provides tools to configure JWT bearer authentication.


    {
      "OAuth2": {
        "Code": {
          "Key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
          "AccessExpireSeconds": 60
        },
        "Token": {
          "Key": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy",
          "AccessExpireSeconds": 86400
        }
      }
    }


    using Microsoft.AspNetCore.Authentication;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.IdentityModel.Tokens;
    using System.Text;

    sealed class JwtTokenConfiguration
    {
        public string Key { get; set; } = string.Empty;
        public double? AccessExpireSeconds { get; set; }
    }

    public static AuthenticationBuilder AddJwtBearer(this AuthenticationBuilder builder, string authenticationScheme, JwtTokenConfiguration configuration)
    {
        var key = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(configuration.Key));

        builder.Services.AddScoped<IJwtGeneratorService, JwtGeneratorService>();
        return builder.AddJwtBearer(authenticationScheme,
            options =>
            {
                options.RequireHttpsMetadata = false;
                options.SaveToken = true;
                options.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey = key,
                    ValidateAudience = false,
                    ValidateIssuer = false,
                    ValidateLifetime = true,
                    ClockSkew = TimeSpan.Zero
                };
            },
            moreOptions =>
            {
                moreOptions.TokenLifeTimespan = (configuration.AccessExpireSeconds.HasValue ? TimeSpan.FromSeconds(configuration.AccessExpireSeconds.Value) : (TimeSpan?)null);
            }
        );
    }
    

    using Microsoft.AspNetCore.Authentication.JwtBearer;
    using Microsoft.Extensions.Options;
    using qckdev.AspNetCore.Authentication.JwtBearer;
    using qckdev.Authentication.JwtBearer;
    using System.Security.Claims;

    sealed class JwtGeneratorService : IJwtGeneratorService
    {

        IOptionsMonitor<JwtBearerOptions> JwtOptionsMonitor { get; }
        IOptionsMonitor<JwtBearerMoreOptions> JwtMoreOptionsMonitor { get; }


        public JwtGeneratorService(IOptionsMonitor<JwtBearerOptions> jwtOptionsMonitor, IOptionsMonitor<JwtBearerMoreOptions> jwtMoreOptionsMonitor)
        {
            this.JwtOptionsMonitor = jwtOptionsMonitor;
            this.JwtMoreOptionsMonitor = jwtMoreOptionsMonitor;
        }

        public Task<JwtToken> CreateTokenAsync(string scheme, string userName, IEnumerable<string> roles, IEnumerable<Claim> claims)
        {
            var jwtOptions = JwtOptionsMonitor.Get(scheme);
            var jwtMoreOptions = JwtMoreOptionsMonitor.Get(scheme);

            return Task.FromResult(
                JwtGenerator.CreateToken(jwtOptions.TokenValidationParameters.IssuerSigningKey, userName, roles, claims, jwtMoreOptions.TokenLifeTimespan)
            );
        }

    }


    using Microsoft.AspNetCore.Authentication.JwtBearer;
    using Microsoft.AspNetCore.Authorization;
    using Microsoft.Extensions.Configuration;

    const string AUTHENTICATIONSCHEME_CODE = "Code";
    const string AUTHENTICATIONSCHEME_TOKEN = "Bearer";

    var jwtCodeConfiguration = Configuration.GetSection("OAuth2:Code").Get<JwtTokenConfiguration>();
    var jwtTokenConfiguration = Configuration.GetSection("OAuth2:Token").Get<JwtTokenConfiguration>();

    services.AddAuthentication(AUTHENTICATIONSCHEME_CODE)
        .AddJwtBearer(AUTHENTICATIONSCHEME_CODE, jwtCodeConfiguration);
    services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
        .AddJwtBearer(AUTHENTICATIONSCHEME_TOKEN, jwtTokenConfiguration);

Testing

This library includes comprehensive integration tests covering token validation, signature verification, and expiration handling.

8 integration tests validate the complete JWT Bearer authentication pipeline:

  • Public endpoint access
  • Challenge response (401 Unauthorized)
  • Valid and expired tokens
  • Token format validation
  • Bearer scheme and claims handling

For detailed testing documentation, see Integration Testing Guide.


## 🤝 Contributing
Issues and pull requests are welcome! See the contribution guidelines (coming soon).

## 📜 License
This project is licensed under the terms of the [MIT License](LICENSE).
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
0.3.0-net10.1581 36 3/5/2026
0.3.0-net10.1560 43 3/5/2026
0.3.0-net10.1552 41 3/1/2026
0.3.0-net10.1550 43 2/28/2026
0.3.0-net10.1541 43 2/28/2026
0.3.0-net10.1532 42 2/28/2026
0.3.0-net10.1530 44 2/28/2026
0.2.0-alpha 525 8/19/2022
0.1.0-alpha 304 2/14/2022