Anit.Authentication.JwtBearer
10.0.0.2
dotnet add package Anit.Authentication.JwtBearer --version 10.0.0.2
NuGet\Install-Package Anit.Authentication.JwtBearer -Version 10.0.0.2
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="Anit.Authentication.JwtBearer" Version="10.0.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Anit.Authentication.JwtBearer" Version="10.0.0.2" />
<PackageReference Include="Anit.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 Anit.Authentication.JwtBearer --version 10.0.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Anit.Authentication.JwtBearer, 10.0.0.2"
#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 Anit.Authentication.JwtBearer@10.0.0.2
#: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=Anit.Authentication.JwtBearer&version=10.0.0.2
#tool nuget:?package=Anit.Authentication.JwtBearer&version=10.0.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Anit.Authentication.JwtBearer
提供生成 JwtBearer 身份令牌的语法糖。
功能特性
- 提供生成 JwtBearer 身份令牌的功能
- 自动从配置读取签名密钥
- 与 ASP.NET Core 认证系统集成
安装
Install-Package Anit.Authentication.JwtBearer
快速开始
配置依赖注入
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAnitAuthenticationJwtBearer();
var app = builder.Build();
// ...
使用示例
public class MyService(IJwtTokenGenerator tokenGenerator)
{
public (string AccessToken, int ExpiresIn) GenerateToken(string key, IEnumerable<Claim> claims)
{
return tokenGenerator.GenerateToken(key, claims, expireDays: 14);
}
public string GetAccessToken(string key, IEnumerable<Claim> claims)
{
return tokenGenerator.GetAccessToken(key, claims, expireDays: 14);
}
}
API 参考
IJwtTokenGenerator
IJwtTokenGenerator 接口定义了 JWT 令牌生成方法。
方法
GenerateToken(string key, IEnumerable<Claim> claims, int expireDays = 14): 生成包含访问令牌和过期时间的元组GetAccessToken(string key, IEnumerable<Claim> claims, int expireDays = 14): 仅返回访问令牌字符串
| Product | Versions 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. net9.0 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 10.0.1)
-
net8.0
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 8.0.22)
-
net9.0
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 9.0.11)
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.2 | 146 | 2/2/2026 |