Microsoft.AspNetCore.Authentication.JwtBearer
10.0.12
Prefix Reserved
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Microsoft.AspNetCore.Authentication.JwtBearer --version 10.0.12
NuGet\Install-Package Microsoft.AspNetCore.Authentication.JwtBearer -Version 10.0.12
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="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.12" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.12" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
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 Microsoft.AspNetCore.Authentication.JwtBearer --version 10.0.12
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Microsoft.AspNetCore.Authentication.JwtBearer, 10.0.12"
#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 Microsoft.AspNetCore.Authentication.JwtBearer@10.0.12
#: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=Microsoft.AspNetCore.Authentication.JwtBearer&version=10.0.12
#tool nuget:?package=Microsoft.AspNetCore.Authentication.JwtBearer&version=10.0.12
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
About
Microsoft.AspNetCore.Authentication.JwtBearer is a middleware component designed for ASP.NET Core applications. It facilitates JSON Web Token (JWT) authentication, enabling secure authentication for APIs and web services. This package allows you to validate JWT tokens issued by an authentication server, ensuring secure access to your application's resources.
Key Features
- Seamless integration with ASP.NET Core applications.
- Supports JSON Web Token (JWT) authentication.
- Enables secure authentication for APIs and web services.
- Flexible configuration options for token validation parameters.
- Works with .NET Core 3.0 and newer, as well as .NET Standard 2.1.
How to Use
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
using System.Text;
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = "your_issuer",
ValidAudience = "your_audience",
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("your_secret_key"))
};
});
// Other configurations...
}
For more detailed configuration options and advanced scenarios, please refer to the blog JWT Validation and Authorization in ASP.NET Core.
Main Types
The main types provided by this library are:
JwtBearerDefaults: Contains default values for JWT Bearer authentication.JwtBearerEvents: Events used to handle JWT Bearer authentication events.JwtBearerHandler: Handles JWT Bearer authentication requests.wtBearerOptions: Options for configuring JWT Bearer authentication.