mirror of
https://github.com/CannedNet/CannedNet.git
synced 2026-10-25 15:09:23 -07:00
22 lines
641 B
C#
22 lines
641 B
C#
namespace CannedNet.Admin.Services;
|
|
|
|
public class AdminApiKeyHandler : DelegatingHandler
|
|
{
|
|
private readonly string _apiKey;
|
|
|
|
public AdminApiKeyHandler(IConfiguration config)
|
|
{
|
|
_apiKey = config.GetValue<string>("Admin:ApiKey")
|
|
?? config.GetValue<string>("AdminApiKey")
|
|
?? "";
|
|
}
|
|
|
|
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
|
{
|
|
if (!string.IsNullOrEmpty(_apiKey))
|
|
request.Headers.Add("X-Admin-Api-Key", _apiKey);
|
|
|
|
return await base.SendAsync(request, cancellationToken);
|
|
}
|
|
}
|