Add AuthController with /auth/me user info endpoint
Introduced AuthController secured with [Authorize] attribute. Provides a GET /auth/me endpoint that returns the authenticated user's identity details and claims.
This commit is contained in:
24
Controllers/AuthController.cs
Normal file
24
Controllers/AuthController.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace FakeNTLMServer.Controllers
|
||||||
|
{
|
||||||
|
[ApiController]
|
||||||
|
[Route("[controller]")]
|
||||||
|
[Authorize]
|
||||||
|
public class AuthController : ControllerBase
|
||||||
|
{
|
||||||
|
[HttpGet("me")]
|
||||||
|
public IActionResult GetMe()
|
||||||
|
{
|
||||||
|
var identity = User.Identity;
|
||||||
|
return Ok(new
|
||||||
|
{
|
||||||
|
identity?.Name,
|
||||||
|
identity?.AuthenticationType,
|
||||||
|
identity?.IsAuthenticated,
|
||||||
|
Claims = User.Claims.Select(claim => new { claim.Type, claim.Value })
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user