- gRPC auth service for token validation - Value comparator system (string, numeric, boolean, datetime, collection) - Condition evaluator with strategy chain - Form definition and data improvements - Workflow instance/task endpoints updated - Seed data and EF design-time factory - Test coverage for comparators and handlers
35 lines
1010 B
C#
35 lines
1010 B
C#
using System.Security.Claims;
|
|
using Workflow.Domain.Common;
|
|
|
|
namespace Workflow.Api.Services;
|
|
|
|
public class CurrentUserContext : ICurrentUserContext
|
|
{
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
|
|
public CurrentUserContext(IHttpContextAccessor httpContextAccessor)
|
|
{
|
|
_httpContextAccessor = httpContextAccessor;
|
|
}
|
|
|
|
public Guid GetUserId()
|
|
{
|
|
var httpContext = _httpContextAccessor.HttpContext;
|
|
if (httpContext?.User?.Identity?.IsAuthenticated == true)
|
|
{
|
|
var userIdClaim = httpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)
|
|
?? httpContext.User.FindFirstValue("user_id")
|
|
?? "system";
|
|
|
|
return Guid.TryParse(userIdClaim, out var userId) ? userId : Guid.Empty;
|
|
}
|
|
return Guid.Empty;
|
|
}
|
|
|
|
public string? GetIPAddress()
|
|
{
|
|
var httpContext = _httpContextAccessor.HttpContext;
|
|
return httpContext?.Connection?.RemoteIpAddress?.ToString();
|
|
}
|
|
}
|