feat: Unterstützung für Token-Beschreibungen im JwtSignatureHandler hinzugefügt

- Methoden eingeführt, um Token-Beschreibungen im DI-Container zu konfigurieren und zu registrieren.
- Überladungen zu `AddJwtSignatureHandler` hinzugefügt, um sowohl konfigurationsbasierte als auch Inline-Token-Beschreibungen zu unterstützen.
This commit is contained in:
Developer 02 2025-01-06 16:32:32 +01:00
parent 8850ac4ac9
commit 592b949f57

View File

@ -61,8 +61,23 @@ namespace DigitalData.Core.Security
return services.AddSingleton(sp => Options.Create(descriptor));
}
public static IServiceCollection AddJwtSignatureHandler<TPrincipal>(this IServiceCollection services, Func<TPrincipal, IDictionary<string, object>>? claimsMapper = null, Func<TPrincipal, ClaimsIdentity>? subjectMapper = null) => services
.AddClaimDescriptor(claimsMapper: claimsMapper, subjectMapper: subjectMapper)
.AddSingleton<IJwtSignatureHandler<TPrincipal>, JwtSignatureHandler<TPrincipal>>();
public static IServiceCollection AddTokenDescriptions(this IServiceCollection services, IConfiguration configuration)
=> services.Configure<IEnumerable<TokenDescription>>(configuration);
public static IServiceCollection AddTokenDescriptions(this IServiceCollection services, params TokenDescription[] tokenDescriptions)
=> services.AddSingleton<IOptions<IEnumerable<TokenDescription>>>(Options.Create(tokenDescriptions));
public static IServiceCollection AddJwtSignatureHandler<TPrincipal>(this IServiceCollection services, Func<TPrincipal, IDictionary<string, object>>? claimsMapper = null, Func<TPrincipal, ClaimsIdentity>? subjectMapper = null, IConfiguration? tokenDescriptionconfig = null, params TokenDescription[]? tokenDescriptions)
{
if (tokenDescriptionconfig is not null)
services.AddTokenDescriptions(tokenDescriptionconfig);
if (tokenDescriptions is not null)
services.AddTokenDescriptions(tokenDescriptions);
return services
.AddClaimDescriptor(claimsMapper: claimsMapper, subjectMapper: subjectMapper)
.AddSingleton<IJwtSignatureHandler<TPrincipal>, JwtSignatureHandler<TPrincipal>>();
}
}
}