NICWebApi.Extensions.JWT
1.0.41
dotnet add package NICWebApi.Extensions.JWT --version 1.0.41
NuGet\Install-Package NICWebApi.Extensions.JWT -Version 1.0.41
<PackageReference Include="NICWebApi.Extensions.JWT" Version="1.0.41" />
<PackageVersion Include="NICWebApi.Extensions.JWT" Version="1.0.41" />
<PackageReference Include="NICWebApi.Extensions.JWT" />
paket add NICWebApi.Extensions.JWT --version 1.0.41
#r "nuget: NICWebApi.Extensions.JWT, 1.0.41"
#:package NICWebApi.Extensions.JWT@1.0.41
#addin nuget:?package=NICWebApi.Extensions.JWT&version=1.0.41
#tool nuget:?package=NICWebApi.Extensions.JWT&version=1.0.41
NICWebApi.Extensions.JWT
NICWebApi.Extensions.JWT 是独立的 JWT 认证与令牌工具库,提供标准 Options 配置、Bearer 认证注册、令牌生成/验证、refresh token 辅助和可选动态授权策略解析。
它不负责动态 API、统一返回格式、HTTP 请求日志、Swagger UI 登录模板、localStorage 令牌注入或业务认证拦截器。
快速开始
builder.Services.AddJwtAuthentication();
默认配置可直接用于本地开发;生产环境如果仍使用默认开发密钥会启动失败,必须通过配置或密钥管理系统覆盖 JWT:IssuerSigningKey。
读取当前用户声明:
using NICWebApi.Extensions.JWT.Extensions;
var userId = User.GetUserId();
var userName = User.GetUserName();
var tenantId = User.GetTenantId();
var roles = User.GetRoles();
生成令牌:
using NICWebApi.Extensions.JWT.Abstractions;
public sealed class TokenService
{
private readonly IJwtTokenService _jwt;
public TokenService(IJwtTokenService jwt)
{
_jwt = jwt;
}
public string Create(long userId)
{
return _jwt.CreateToken(new Dictionary<string, object>
{
["sub"] = userId.ToString()
});
}
}
可选动态授权策略
builder.Services.AddJwtAuthorizationPolicies<MyAuthorizeHandler>();
默认策略前缀为 WebAPI,可通过 JWT:PolicyPrefix 调整;企业项目也可以替换 IJwtPolicyNameParser 实现自己的策略命名规则。
更多内容:
| 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. |
-
net10.0
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 10.0.9)
-
net8.0
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 8.0.11)
-
net9.0
NuGet packages (1)
Showing the top 1 NuGet packages that depend on NICWebApi.Extensions.JWT:
| Package | Downloads |
|---|---|
|
NICWebApi.Extensions.AspNetCore
NICWebApi ASP.NET Core 一键集成扩展包,组合 DynamicAPI、RESTfulResult、JWT、Mapper、DependencyInjection、Http、RemoteRequest、Caching、Idempotency、Schedule、Messaging 和 OperationLogging 的默认注册。 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.41 | 155 | 7/7/2026 |