63 lines
2.3 KiB
C#
63 lines
2.3 KiB
C#
using CloudBuilder.Core.Application.Builders;
|
|
using CloudBuilder.Core.Application.Options;
|
|
using CloudBuilder.Core.Application.Packs;
|
|
using CloudBuilder.Core.Extensions;
|
|
using CloudBuilder.Core.Service;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
|
|
namespace CloudBuilder.Core.DependencyInjection.Service
|
|
{
|
|
[PackLevel(20)]
|
|
public class ServicePack : CloudBuilderPack
|
|
{
|
|
|
|
/// <summary>
|
|
/// 获取 模块级别
|
|
/// </summary>
|
|
public override PackLevel Level => PackLevel.Business;
|
|
|
|
/// <summary>
|
|
/// 获取 模块启动顺序,模块启动的顺序先按级别启动,级别内部再按此顺序启动
|
|
/// </summary>
|
|
public override int Order => 2;
|
|
|
|
/// <summary>
|
|
/// 将服务添加到依赖注入服务容器中
|
|
/// </summary>
|
|
/// <param name="services">依赖注入服务容器</param>
|
|
/// <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();
|
|
|
|
var types = allAssemblies
|
|
.SelectMany(a => a.DefinedTypes)
|
|
.Select(type => type.AsType())
|
|
.Where(type => type != baseType && type.HasImplementedRawGeneric(baseType))
|
|
.Where(x => x.IsClass).ToList();
|
|
|
|
|
|
foreach (var implementType in types)
|
|
{
|
|
services.TryAddScoped(implementType.GetInterfaces().FirstOrDefault(), implementType);
|
|
}
|
|
|
|
// IAuthService authRequest = ServiceProvider.GetService<IAuthService>()!;
|
|
|
|
return services;
|
|
}
|
|
|
|
|
|
}
|
|
} |