Crping.AuthPolicy.JWT 0.8.0

dotnet add package Crping.AuthPolicy.JWT --version 0.8.0
                    
NuGet\Install-Package Crping.AuthPolicy.JWT -Version 0.8.0
                    
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="Crping.AuthPolicy.JWT" Version="0.8.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Crping.AuthPolicy.JWT" Version="0.8.0" />
                    
Directory.Packages.props
<PackageReference Include="Crping.AuthPolicy.JWT" />
                    
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 Crping.AuthPolicy.JWT --version 0.8.0
                    
#r "nuget: Crping.AuthPolicy.JWT, 0.8.0"
                    
#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 Crping.AuthPolicy.JWT@0.8.0
                    
#: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=Crping.AuthPolicy.JWT&version=0.8.0
                    
Install as a Cake Addin
#tool nuget:?package=Crping.AuthPolicy.JWT&version=0.8.0
                    
Install as a Cake Tool

Crping.AuthPolicy.JWT

基于 JWT Bearer 的身份认证策略授权,并支持用户访问日志,授权调试

版本更新说明


0.8.0

2026年8月15日 星期六

  • [安全] PasswordHasher 加固:空盐/空哈希的畸形 PBKDF2 存储值(如 PBKDF2$1000$cw==$)拒绝验证,防验证绕过
  • [新增] PBKDF2 迭代次数可配置:AuthOptions.PasswordHashIterations(默认 100000,AuthConfig 启动期校验 (0, 1000000]),旧哈希因迭代次数随存储格式内嵌而不受影响
  • [新增] AuthPolicyHandler 授权失败分级日志:未认证记 Debug、验证拒绝记 Warning(含策略/Method/Path/UserId/UserType/IP),便于排查 403
  • [新增] AuthConfig 启动期校验 Expires > 0,防止签出立即过期的令牌
  • [修复] UserIdentity.Roles 转换改用文化不变的 ToLowerInvariant(原 ToLower 受区域设置影响)
  • [重构] 密码哈希实现移入 JWT.Common 的 PasswordHasher(UserLoginHandler 保留同名转发,公共 API 不变);DAL 不再引用 JWT 项目
  • [重构] AuthPolicyProvider 三策略启动期静态缓存,消除授权中间件每请求重复分配
  • [测试] 新增 82 个单元测试;测试项目迁移至 xunit.v3 纯 MTP 模式(配合根目录 global.json,dotnet test 可直接运行)

0.7.0

2026年8月15日 星期六

  • [安全] 密码哈希升级为 PBKDF2(16 字节随机盐 + 10 万迭代 + 恒定时间比较),兼容旧 SHA256 并登录后自动重哈希,迭代次数上限 100 万
  • [安全] JwtSecret 强制 UTF8 编码并校验最小 32 字节;TokenValidationParameters 增加 ValidAlgorithms 仅接受 HS256
  • [修复] Role Claim 读写统一为 AuthClaimTypes.Role,配合 MapInboundClaims=false,修复角色恒为空的问题
  • [修复] 纯 IPv6 客户端 RemoteIpAddress.MapToIPv4 抛异常 → 按 IsIPv4MappedToIPv6 分流,避免 500
  • [修改] UserIdentity.Expires 由 int(分钟)改为 DateTime(UTC 过期时间戳)
  • [重构] 自定义 AuthPolicyProvider 统一策略解析,GetPolicyAsync 未知策略名返回 null,移除 AddPolicy 死代码
  • [重构] VerifyPolicy 去泛型;HttpContext 空安全、DateTime.UtcNow、静态 JwtSecurityTokenHandler
  • [依赖] 移除 NETCore.Encrypt(根除 Newtonsoft.Json 12.0.1 高危漏洞),改用 FrameworkReference Microsoft.AspNetCore.App

0.6.0

2026年3月4日 星期三

  • [修改] 将所有使用 RequestInfo 的方法参数改为使用 UserRequest
  • [删除] 删除了 RequestInfo.cs 文件
  • [添加] 新增了 UserRequest.cs 文件,包含更多用户请求相关的属性
  • [修改] 更新了多个接口和实现类,以适配新的 UserRequest 模型
  • [修改] 更新了 AdminDom 和 MemberDom 中的授权方法
  • [修改] 更新了 JWT 相关的验证和处理逻辑

0.5.0

2026年1月8日 星期四
  • UserLoginHandler新增方法GetAuthOptions

0.4.0

2026年1月8日 星期四
  • 升级为 .net10

0.3.0

2024年11月19日 星期二
  • 升级为 .net9

0.1.0

2024年4月5日 星期五
  • 授权策略验证依赖注入
Product Compatible and additional computed target framework versions.
.NET 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.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Crping.AuthPolicy.JWT:

Package Downloads
Crping.AuthPolicy.JWT.DI

Package Description

Crping.AuthPolicy.DAL

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.8.0 371 9/13/2026
0.7.0 263 8/15/2026
0.4.0 271 1/8/2026
0.3.0 376 11/19/2024
0.1.0 527 4/5/2024