using AsbCloudApp.Data; using AsbCloudApp.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; namespace AsbCloudWebApi.Controllers { [Route("/auth")] [ApiController] public class AuthController : ControllerBase { private readonly IAuthService authService; public AuthController(IAuthService authService) { this.authService = authService; } /// /// Аутентификация пользователя /// /// /// новый токен /// логин и пароль не подходят [AllowAnonymous] [HttpPost("login")] [SwaggerOperation(OperationId = "logiin")] [ProducesResponseType(typeof(UserTokenDto), (int)System.Net.HttpStatusCode.OK)] public IActionResult Login([FromBody] AuthDto auth) { var userToken = authService.Login(auth.Login, auth.Password); if (userToken is null) BadRequest();//"wrong login or password" return Ok(userToken); } /// /// Продление срока действия токена /// /// новый токен [Authorize] [HttpGet("refresh")] public IActionResult Refresh() { var newToken = authService.Refresh(User); return Ok(newToken); } } }