Developer 02 a2c74cbdd9 feat: Refaktorierung von ClientEvents zur Verwendung eines Delegaten für öffentliche Schlüsselaktualisierungen
- Ersetzt `Action<string, string, string, ILogger?>` durch den `ClientEvent`-Delegaten für eine bessere Struktur.
- `ClientEvent`-Delegaten mit `AuthClient`-Referenz eingeführt, um öffentliche Schlüssel direkt zu aktualisieren.
2025-03-06 16:48:47 +01:00

46 lines
1.5 KiB
C#

using DigitalData.Auth.Client;
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.Logging;
namespace DigitalData.Auth.Client;
public class ClientParams
{
public string Url { get; set; } = string.Empty;
private readonly Lazy<IRetryPolicy?> _lazyRetryPolicy;
/// <summary>
/// Controls when the client attempts to reconnect and how many times it does so.
/// </summary>
public IRetryPolicy? RetryPolicy => _lazyRetryPolicy.Value;
/// <summary>
/// To simplify the assignment of <seealso cref="RetryPolicy"/>
/// </summary>
public Func<RetryContext, TimeSpan?>? NextRetryDelay { get; set; }
/// <summary>
/// To be able to serilize the simple <seealso cref="RetryPolicy"/>
/// </summary>
public TimeSpan? RetryDelay { get; set; }
public ClientEvent OnMessageReceived = delegate { };
internal void TriggerOnMessageReceived(AuthClient client, string issuer, string audience, string key, ILogger? logger = null)
=> OnMessageReceived(client, issuer, audience, key, logger);
public ClientParams()
{
_lazyRetryPolicy = new(() =>
{
if (RetryDelay is not null)
return new RetryPolicy(ctx => RetryDelay);
else if(NextRetryDelay is not null)
return new RetryPolicy(NextRetryDelay);
return null;
});
}
public IEnumerable<AsymmetricPublicKey> PublicKeys { get; init; } = new List<AsymmetricPublicKey>();
}