XiHan.Framework.Security.WebAuthn 5.0.0-rc.2

Prefix Reserved
This is a prerelease version of XiHan.Framework.Security.WebAuthn.
dotnet add package XiHan.Framework.Security.WebAuthn --version 5.0.0-rc.2
                    
NuGet\Install-Package XiHan.Framework.Security.WebAuthn -Version 5.0.0-rc.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="XiHan.Framework.Security.WebAuthn" Version="5.0.0-rc.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="XiHan.Framework.Security.WebAuthn" Version="5.0.0-rc.2" />
                    
Directory.Packages.props
<PackageReference Include="XiHan.Framework.Security.WebAuthn" />
                    
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 XiHan.Framework.Security.WebAuthn --version 5.0.0-rc.2
                    
#r "nuget: XiHan.Framework.Security.WebAuthn, 5.0.0-rc.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 XiHan.Framework.Security.WebAuthn@5.0.0-rc.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=XiHan.Framework.Security.WebAuthn&version=5.0.0-rc.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=XiHan.Framework.Security.WebAuthn&version=5.0.0-rc.2&prerelease
                    
Install as a Cake Tool

XiHan.Framework.Security.WebAuthn

关于

XiHan.Framework.Security.WebAuthn 是通行密钥(WebAuthn)的依赖方实现:生成注册与认证仪式的选项,核对浏览器交回的响应。适用于要做免密码、免用户名登录的应用。它是无状态的:挑战由应用保存到仪式结束,凭据由应用存储。

主要特性

  • 选项与响应和 WebAuthn Level 3 的 JSON 同形,浏览器用 parseCreationOptionsFromJSON 与 toJSON() 直接对接
  • 支持 ES256(P-256)、PS256、RS256,只依赖 System.Formats.Cbor 与 BCL 的密码学类型
  • 证明一律按 none 处理,不需要信任链与元数据服务
  • 失败以 Result 返回,带机读的原因;签名计数不增单独报告

如何使用

安装

dotnet add package XiHan.Framework.Security.WebAuthn --prerelease

使用

builder.AddXiHan(x => x.UseFeature<WebAuthnSecurityFeature>());

RelyingPartyId 与 Origins 必填:

{ "XiHan": { "Security": { "WebAuthn": { "RelyingPartyId": "example.com", "Origins": [ "https://example.com" ] } } } }

注册:生成选项交给浏览器,保存挑战;浏览器交回响应后核对,存下凭据。

var options = ceremonies.CreateRegistrationOptions(new WebAuthnUserEntity(userHandle, userName, displayName), existing);
// 保存 options.Challenge,把 options 发给浏览器
var registered = ceremonies.VerifyRegistration(response, savedChallenge);

认证:按响应的凭据 ID 找到存储的凭据(连同它所属用户的句柄),核对后更新签名计数。登录前已认出用户(先填账号、第二因素)时传入这个用户,凭据必须属于他;免用户名登录传 null,登录的用户取结果的 UserHandle。

var verified = ceremonies.VerifyAuthentication(response, savedChallenge, new WebAuthnStoredCredential(id, publicKey, signCount, ownerHandle), expectedUserHandle);

主要类型

此库提供的主要类型:

  • WebAuthnSecurityFeature:启用通行密钥的特性
  • WebAuthnOptions:配置项,对应 XiHan:Security:WebAuthn
  • WebAuthnCeremonies:选项生成与响应核对
  • WebAuthnCreationOptions / WebAuthnRequestOptions:交给浏览器的选项
  • WebAuthnRegistrationResponse / WebAuthnAuthenticationResponse:浏览器交回的响应
  • WebAuthnRegisteredCredential / WebAuthnStoredCredential / WebAuthnVerifiedAssertion:核对结果与存储的凭据

更多文档

相关包

反馈与贡献

XiHan.Framework.Security.WebAuthn 以 MIT 许可证 开源。欢迎到 GitHub 仓库 提交问题和贡献。

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 (1)

Showing the top 1 NuGet packages that depend on XiHan.Framework.Security.WebAuthn:

Package Downloads
XiHan.Framework.Testing

曦寒框架测试工具库

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
5.0.0-rc.2 0 11/15/2026
5.0.0-rc.1 113 11/13/2026
5.0.0-preview.3 69 11/11/2026