17 lines
591 B
C#
17 lines
591 B
C#
|
|
namespace IdentityShroud.Core;
|
||
|
|
|
||
|
|
public class JwtSignerFactory(IEnumerable<IJwtSigner> signers) : IJwtSignerFactory
|
||
|
|
{
|
||
|
|
private readonly IReadOnlyDictionary<JwtSigAlgName, IJwtSigner> _signers = signers
|
||
|
|
.SelectMany(s => s.Algorithms.Select(alg => (alg, signer: s)))
|
||
|
|
.ToDictionary(x => x.alg, x => x.signer);
|
||
|
|
|
||
|
|
public IJwtSigner Create(JwtSigAlgName algorithm)
|
||
|
|
{
|
||
|
|
if (_signers.TryGetValue(algorithm, out var signer))
|
||
|
|
return signer;
|
||
|
|
|
||
|
|
throw new NotSupportedException($"JWT signing algorithm '{algorithm}' is not registered.");
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|