api
This commit is contained in:
1 parent
3a1a0ca7ef
commit
6bce1d9330
9 files changed
+167
-13
No files matched your search
@@ -55,6 +55,42 @@ namespace uWine.Api.Controllers
|
||||
return Ok(new { access_token = token });
|
||||
}
|
||||
|
||||
[HttpGet("active")]
|
||||
public IActionResult IsActive()
|
||||
{
|
||||
if (!Request.Headers.ContainsKey("Authorization"))
|
||||
return Unauthorized("Authorization header missing");
|
||||
|
||||
var authHeader = Request.Headers["Authorization"].ToString();
|
||||
|
||||
if (!authHeader.StartsWith("Bearer "))
|
||||
return Unauthorized("Invalid auth scheme");
|
||||
|
||||
var token = authHeader.Substring("Bearer ".Length).Trim();
|
||||
var jwtSettings = _configuration.GetSection("JwtSettings");
|
||||
|
||||
var tokenHandler = new JwtSecurityTokenHandler();
|
||||
var key = Encoding.UTF8.GetBytes(jwtSettings["Secret"]);
|
||||
try
|
||||
{
|
||||
tokenHandler.ValidateToken(token, new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuerSigningKey = true,
|
||||
IssuerSigningKey = new SymmetricSecurityKey(key),
|
||||
ValidateIssuer = true,
|
||||
ValidIssuer = jwtSettings["Issuer"],
|
||||
ValidateAudience = true,
|
||||
ValidAudience = jwtSettings["Audience"],
|
||||
ClockSkew = TimeSpan.Zero // No clock skew for simplicity
|
||||
}, out SecurityToken validatedToken);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return Unauthorized("Invalid token");
|
||||
}
|
||||
|
||||
return Ok(new { active = true });
|
||||
}
|
||||
|
||||
private string GenerateJwtToken(User user)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user