refactor(JWT): Ungenutzte Schnittstelle und Controller entfernt
This commit is contained in:
parent
28fdf0a115
commit
aa918d875d
@ -1,24 +0,0 @@
|
|||||||
using Microsoft.IdentityModel.Tokens;
|
|
||||||
using System.IdentityModel.Tokens.Jwt;
|
|
||||||
using System.Security.Claims;
|
|
||||||
using System.Security.Cryptography;
|
|
||||||
|
|
||||||
namespace EnvelopeGenerator.Application.Contracts
|
|
||||||
{
|
|
||||||
public interface IJWTService<TClaimValue>
|
|
||||||
{
|
|
||||||
public static SymmetricSecurityKey GenerateSecurityKey(int byteSize = 32)
|
|
||||||
{
|
|
||||||
using var rng = RandomNumberGenerator.Create();
|
|
||||||
var randomBytes = new byte[byteSize];
|
|
||||||
rng.GetBytes(randomBytes);
|
|
||||||
var securityKey = new SymmetricSecurityKey(randomBytes);
|
|
||||||
|
|
||||||
return securityKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
string GenerateToken(TClaimValue claimValue);
|
|
||||||
|
|
||||||
JwtSecurityToken? ReadSecurityToken(string token);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,42 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user