diff --git a/Controllers/AuthController.cs b/Controllers/AuthController.cs index eb704c5..a2fc353 100644 --- a/Controllers/AuthController.cs +++ b/Controllers/AuthController.cs @@ -1,24 +1,57 @@ -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -namespace FakeNTLMServer.Controllers +namespace FakeNTLMServer.Controllers; + +[ApiController] +[Route("[controller]")] +public class AuthController : ControllerBase { - [ApiController] - [Route("[controller]")] [Authorize] - public class AuthController : ControllerBase + [HttpGet("me")] + public IActionResult GetMe() { - [HttpGet("me")] - public IActionResult GetMe() + var identity = User.Identity; + return Ok(new { - var identity = User.Identity; - return Ok(new - { - identity?.Name, - identity?.AuthenticationType, - identity?.IsAuthenticated, - Claims = User.Claims.Select(claim => new { claim.Type, claim.Value }) - }); - } + identity?.Name, + identity?.AuthenticationType, + identity?.IsAuthenticated, + Claims = User.Claims.Select(claim => new { claim.Type, claim.Value }) + }); + } + + /// + /// NTLM/Negotiate login endpoint. + /// Triggers the NTLM handshake (401 → challenge → response) and returns authenticated user info. + /// + [Authorize] + [HttpGet("login")] + public IActionResult Login() + { + var identity = User.Identity; + + if (identity is null || !identity.IsAuthenticated) + return Unauthorized(new { Message = "NTLM authentication failed." }); + + return Ok(new + { + Message = "NTLM authentication successful.", + identity.Name, + identity.AuthenticationType, + identity.IsAuthenticated, + Claims = User.Claims.Select(claim => new { claim.Type, claim.Value }) + }); + } + + [Authorize] + [HttpGet("status")] + public IActionResult Status() + { + return Ok(new + { + User.Identity?.Name, + User.Identity?.AuthenticationType + }); } } \ No newline at end of file