DurnyklyYol/DurnyklyYol.MiddleTier/JWT/WebApiAuthenticationControl...

30 lines
955 B
C#
Raw Normal View History

2024-09-02 10:07:25 +00:00
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Security;
using DevExpress.ExpressApp.Security.Authentication;
using DevExpress.ExpressApp.Security.Authentication.ClientServer;
using Microsoft.AspNetCore.Mvc;
namespace DurnyklyYol.WebApi.JWT;
[ApiController]
[Route("api/[controller]")]
// This is a JWT authentication service sample.
public class AuthenticationController : ControllerBase {
readonly IAuthenticationTokenProvider tokenProvider;
public AuthenticationController(IAuthenticationTokenProvider tokenProvider) {
this.tokenProvider = tokenProvider;
}
[HttpPost("Authenticate")]
public IActionResult Authenticate(
[FromBody]
AuthenticationStandardLogonParameters logonParameters
) {
try {
return Ok(tokenProvider.Authenticate(logonParameters));
}
catch(AuthenticationException ex) {
return Unauthorized(ex.GetJson());
}
}
}