This commit is contained in:
owenchen committed 2026-08-20 13:23:26 +08:00
1 parent 3461a2e921
commit ddfbd7d0f2
17 files changed
+523 -241

No files matched your search

@@ -49,6 +49,8 @@ namespace CloudBuilder.Core.Application.Options
/// </summary>
public RedisOptions Redis { get; set; }
public WebAuthnOptions WebAuthn { get; set; }
///// <summary>
///// 获取或设置 Swagger选项
///// </summary>
@@ -67,6 +67,14 @@ namespace CloudBuilder.Core.Application.Options
options.Redis = redis;
}
// WebAuthnOptions
section = _configuration.GetSection("CloudBuilder:WebAuthn");
WebAuthnOptions webAuthn = section.Get<WebAuthnOptions>();
if (webAuthn != null)
{
options.WebAuthn = webAuthn;
}
//// SwaggerOptions
//section = _configuration.GetSection("CloudBuilder:Swagger");
//SwaggerOptions swagger = section.Get<SwaggerOptions>();
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CloudBuilder.Core.Application.Options
{
/// <summary>
/// Plain-old-data wrapper for the credential fields we persist on
/// SecurityUser. The frontend never sees this type.
/// </summary>
public class StoredBiometricCredential
{
public byte[] CredentialId { get; set; } = Array.Empty<byte>();
public byte[] PublicKey { get; set; } = Array.Empty<byte>();
}
public class WebAuthnOptions
{
/// <summary>
/// Relying Party ID — the registrable domain suffix of the
/// origin's host. For dev: "localhost". For production:
/// </summary>
public string RpId { get; set; } = "localhost";
/// <summary>
/// Human-readable relying-party name. Shown in the OS biometric
/// prompt ("Use Cloud Builder to sign in to localhost").
/// </summary>
public string RpName { get; set; } = "Cloud Builder";
/// <summary>
/// The full origin (scheme + host + port) the user is loading
/// the page from. Fido2NetLib verifies the attestation/assertion
/// origin matches this exactly. Must be HTTPS in production
/// (localhost is exempt).
/// </summary>
public string Origin { get; set; } = "http://localhost:8080";
/// <summary>
/// WebAuthn ceremony timeout in milliseconds. Default 60s.
/// </summary>
public int TimeoutMs { get; set; } = 60000;
}
}
@@ -16,19 +16,20 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Fido2" Version="4.0.1" />
<PackageReference Include="Fido2.AspNet" Version="4.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.0" />
<PackageReference Include="ClosedXML" Version="0.102.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.0" />
@@ -1,4 +1,5 @@
using CloudBuilder.Core.Application.Builders;
using CloudBuilder.Core.Application.Options;
using CloudBuilder.Core.Application.Packs;
using CloudBuilder.Core.Extensions;
using CloudBuilder.Core.Service;
@@ -28,6 +29,14 @@ namespace CloudBuilder.Core.DependencyInjection.Service
/// <returns></returns>
public override IServiceCollection AddServices(IServiceCollection services, CloudBuilderBuilder builder)
{
services.AddFido2(options =>
{
// 你的配置:RelyingParty 配置,必须填写
options.ServerDomain = builder.CloudBuilderOptions.WebAuthn.RpId; // 例如 localhost 或者正式域名
options.ServerName = builder.CloudBuilderOptions.WebAuthn.RpName;
// 可选:限制origin
options.Origins = new HashSet<string> { builder.CloudBuilderOptions.WebAuthn.Origin };
});
var baseType = typeof(IService);
var allAssemblies = CloudBuilderBuilder.GetAssemblies();
@@ -1,4 +1,5 @@
using CloudBuilder.Core.Application.Builders;
using CloudBuilder.Core.Application.Options;
using CloudBuilder.Core.DatabaseAccessor;
using CloudBuilder.Core.DependencyInjection.Form;
using CloudBuilder.Core.Extensions;
@@ -22,7 +23,7 @@ namespace Microsoft.Extensions.DependencyInjection
{
IConfiguration configuration = GetConfiguration();
services.AddSingleton(configuration);
services.Configure<WebAuthnOptions>(configuration.GetSection("CloudBuilder:WebAuthn"));
CloudBuilderBuilder builder = new CloudBuilderBuilder(services, configuration);
builder.AddPack();