Edit Records
This commit is contained in:
35
DiunaBI.UI.Shared/Handlers/AuthenticationHandler.cs
Normal file
35
DiunaBI.UI.Shared/Handlers/AuthenticationHandler.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using DiunaBI.UI.Shared.Services;
|
||||
|
||||
namespace DiunaBI.UI.Shared.Handlers;
|
||||
|
||||
public class AuthenticationHandler : DelegatingHandler
|
||||
{
|
||||
private readonly TokenProvider _tokenProvider;
|
||||
|
||||
public AuthenticationHandler(TokenProvider tokenProvider)
|
||||
{
|
||||
_tokenProvider = tokenProvider;
|
||||
}
|
||||
|
||||
protected override async Task<HttpResponseMessage> SendAsync(
|
||||
HttpRequestMessage request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
// Get token from TokenProvider
|
||||
var token = _tokenProvider.Token;
|
||||
|
||||
Console.WriteLine($"🔐 AuthenticationHandler: Token = {(string.IsNullOrEmpty(token) ? "NULL" : $"{token[..Math.Min(20, token.Length)]}...")}");
|
||||
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
{
|
||||
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
|
||||
Console.WriteLine($"🔐 AuthenticationHandler: Added Bearer token to request");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"🔐 AuthenticationHandler: No token available, request will be unauthorized");
|
||||
}
|
||||
|
||||
return await base.SendAsync(request, cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user