Initial version

This commit is contained in:
2026-06-09 22:27:38 +02:00
parent 5afbf3b01c
commit 5ff2ac8941
57 changed files with 2343 additions and 98 deletions
@@ -0,0 +1,35 @@
using Grpc.Core;
using Grpc.Core.Interceptors;
using EonaCat.gRPC.Proto;
using Microsoft.AspNetCore.Http;
namespace EonaCat.gRPC.Client.Helpers;
public class AuthHeaderInterceptor : Interceptor
{
private readonly IHttpContextAccessor _httpContextAccessor;
public AuthHeaderInterceptor(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
public override AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(TRequest request, ClientInterceptorContext<TRequest, TResponse> context,
AsyncUnaryCallContinuation<TRequest, TResponse> continuation)
{
var metadata = new Metadata();
//var authResponse = AuthService.Authenticate();
var authResponse = new AuthenticationResponse();
metadata.Add("authorization", $"Bearer {authResponse.AccessToken}");
metadata.Add("expiry", $"{authResponse.ExpiresIn}");
var userIdentity = _httpContextAccessor.HttpContext?.User.Identity;
if (userIdentity is { IsAuthenticated: true, Name: { } })
metadata.Add("User", userIdentity.Name);
var callOptions = context.Options.WithHeaders(metadata);
context = new ClientInterceptorContext<TRequest, TResponse>(context.Method, context.Host, callOptions);
return base.AsyncUnaryCall(request, context, continuation);
}
}