Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

35 linhas
959B

  1. using System.Security.Claims;
  2. using Campaign_Tracker.Server.Authentication;
  3. using Microsoft.AspNetCore.Authorization;
  4. using Microsoft.AspNetCore.Mvc;
  5. namespace Campaign_Tracker.Server.Controllers;
  6. [ApiController]
  7. [Authorize]
  8. [Route("api/auth/session")]
  9. public sealed class AuthSessionController : ControllerBase
  10. {
  11. [HttpGet]
  12. public ActionResult<AuthSessionResponse> Get()
  13. {
  14. var roles = User.FindAll(ClaimTypes.Role)
  15. .Select(claim => claim.Value)
  16. .Distinct(StringComparer.OrdinalIgnoreCase)
  17. .ToArray();
  18. var userName = User.Identity?.Name
  19. ?? User.FindFirstValue(ClaimTypes.NameIdentifier)
  20. ?? "unknown";
  21. return Ok(new AuthSessionResponse(
  22. userName,
  23. roles,
  24. RoleWorkspaceResolver.ResolveWorkspacePath(roles)));
  25. }
  26. }
  27. public sealed record AuthSessionResponse(
  28. string UserName,
  29. string[] Roles,
  30. string WorkspacePath);

Powered by TurnKey Linux.