42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
using EnvelopeGenerator.Application.Contracts;
|
|
using EnvelopeGenerator.Application.Services;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Security.Claims;
|
|
|
|
namespace EnvelopeGenerator.Web.Controllers.Test
|
|
{
|
|
[ApiController]
|
|
[Route("api/test/[controller]")]
|
|
public class TestAuthController : ControllerBase
|
|
{
|
|
private readonly IJWTService<string> _authService;
|
|
|
|
public TestAuthController(IJWTService<string> authService)
|
|
{
|
|
_authService = authService;
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult ProvideToken([FromQuery] string value)
|
|
{
|
|
var token = _authService.GenerateToken(value);
|
|
return Ok(token);
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult GetSecurityToken([FromQuery] string token)
|
|
{
|
|
var sToken = _authService.ReadSecurityToken(token);
|
|
return Ok(sToken);
|
|
}
|
|
|
|
[HttpGet("Username")]
|
|
[Authorize]
|
|
public IActionResult Getname()
|
|
{
|
|
var username = User.Claims?.FirstOrDefault(c => c.Type == ClaimTypes.Name)?.Value;
|
|
return Ok(username);
|
|
}
|
|
}
|
|
} |