work-flow/src/Workflow.Api/Services/CurrentUserContext.cs
向宁 fc4ecbbacc feat: add gRPC auth, condition comparators, seed data, EF migrations
- 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
2026-05-20 20:28:35 +08:00

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();
}
}