Eliassen.AspNetCore.JwtAuthentication 0.1.81

There is a newer version of this package available.
See the version list below for details.
dotnet add package Eliassen.AspNetCore.JwtAuthentication --version 0.1.81                
NuGet\Install-Package Eliassen.AspNetCore.JwtAuthentication -Version 0.1.81                
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="Eliassen.AspNetCore.JwtAuthentication" Version="0.1.81" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Eliassen.AspNetCore.JwtAuthentication --version 0.1.81                
#r "nuget: Eliassen.AspNetCore.JwtAuthentication, 0.1.81"                
#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.
// Install Eliassen.AspNetCore.JwtAuthentication as a Cake Addin
#addin nuget:?package=Eliassen.AspNetCore.JwtAuthentication&version=0.1.81

// Install Eliassen.AspNetCore.JwtAuthentication as a Cake Tool
#tool nuget:?package=Eliassen.AspNetCore.JwtAuthentication&version=0.1.81                

Eliassen.AspNetCore.JwtAuthentication

Summary

This assembly contains methods for configuring JWT Bearer authentication for ASP.Net Core and SwaggerGen (OpenAPI3)

Getting started

To use these extensions, first add a reference to the Eliassen.AspNetCore.JwtAuthentication package in your project. Then, add the following namespaces to your IOC registation code:

using Eliassen.AspNetCore.JwtAuthentication;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

Next, configure your JWT Bearer authentication and SwaggerGen services in your IServiceCollection using the extension methods:

public void ConfigureServices(IServiceCollection services)
{
    services.TryAddJwtBearerServices(configuration);
}

where configuration is your IConfiguration instance.

These extensions will configure JWT Bearer authentication and add SwaggerGen services for OAuth2 using the configuration sections specified in the JwtBearerOptions and OAuth2SwaggerOptions classes.

Configuration

The JWT Bearer authentication configuration is specified in the JwtBearerOptions class. The OAuth2SwaggerOptions class specifies the configuration for SwaggerGen services for OAuth2.

The configuration for JWT Bearer authentication is specified in the jwtBearerConfigurationSection parameter of the TryAddJwtBearerAuthentication method. The configuration for SwaggerGen services for OAuth2 is specified in the oAuth2SwaggerConfigurationSection parameter of the TryAddJwtBearerSwaggerGen method.

By default, the JwtBearerDefaults.AuthenticationScheme and OAuth2SwaggerOptions.DefaultScheme values are used for the default authentication scheme and the default scheme for SwaggerGen services, respectively.

Example

Here is an example of how to use the extension methods to configure JWT Bearer authentication and SwaggerGen services in an ASP.NET 8.0 project:

public void ConfigureServices(IServiceCollection services)
{
    services.AddControllers();

    services.TryAddJwtBearerServices(configuration);

    services.AddSwaggerGen(c =>
    {
        c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
    });
}

This code adds the JwtBearerAuthentication and SwaggerGen services to the IServiceCollection using the TryAddJwtBearerServices method. It also adds a Swagger documentation for an API with a version 1.

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Eliassen.AspNetCore.JwtAuthentication:

Package Downloads
Eliassen.Common.AspNetCore

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.85 50 10/10/2024
0.1.84 43 10/10/2024
0.1.83 47 9/27/2024
0.1.82 147 8/23/2024
0.1.81 105 8/1/2024
0.1.81-dev-gh-pipline.3 47 8/1/2024