You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 line
956B

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

Powered by TurnKey Linux.