Added route to test token authentication

dashboard
Pat Hartl 2023-01-05 01:06:30 -06:00
parent f7d068d340
commit c18cb1d94b
1 changed files with 13 additions and 2 deletions

View File

@ -1,4 +1,5 @@
using LANCommander.Data.Models; using LANCommander.Data.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
@ -68,7 +69,7 @@ namespace LANCommander.Controllers.Api
return Ok(new return Ok(new
{ {
Token = new JwtSecurityTokenHandler().WriteToken(token), AccessToken = new JwtSecurityTokenHandler().WriteToken(token),
RefreshToken = refreshToken, RefreshToken = refreshToken,
Expiration = token.ValidTo Expiration = token.ValidTo
}); });
@ -77,6 +78,15 @@ namespace LANCommander.Controllers.Api
return RedirectToAction("Index", "Home"); return RedirectToAction("Index", "Home");
} }
[HttpPost("Validate")]
public IActionResult Validate()
{
if (User != null && User.Identity != null && User.Identity.IsAuthenticated)
return Ok();
else
return Unauthorized();
}
[HttpPost("Refresh")] [HttpPost("Refresh")]
public async Task<IActionResult> Refresh(TokenModel token) public async Task<IActionResult> Refresh(TokenModel token)
{ {
@ -109,7 +119,8 @@ namespace LANCommander.Controllers.Api
return Ok(new return Ok(new
{ {
AccessToken = new JwtSecurityTokenHandler().WriteToken(newAccessToken), AccessToken = new JwtSecurityTokenHandler().WriteToken(newAccessToken),
RefreshToken = newRefreshToken RefreshToken = newRefreshToken,
Expiration = newAccessToken.ValidTo
}); });
} }