Feature/Auth: implement user authentication #3

Merged
homeburger merged 48 commits from feature/auth into main 2026-03-22 20:52:22 -05:00
3 changed files with 14 additions and 6 deletions
Showing only changes of commit 7e02d3cfe1 - Show all commits

View File

@@ -39,7 +39,8 @@ builder.Services.AddAuthentication(options => {
ValidateIssuerSigningKey = true,
ValidIssuer = "agologum",
ValidAudience = "agologum",
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key))
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key)),
ClockSkew = TimeSpan.Zero
};
});

View File

@@ -67,10 +67,10 @@ public class AuthController : ControllerBase {
[Authorize] // authorize is handled by middleware
[HttpPost("logout")]
public ActionResult Logout() {
// dummy endpoint
// logout happens upon client-side jwt removal
// TODO: expire all refresh tokens
public async Task<ActionResult> Logout(string refreshTokenString) {
// revoke refresh token
bool success = await jwt_.RevokeRefreshToken(refreshTokenString);
if(!success) return NotFound();
return Ok();
}
@@ -106,7 +106,6 @@ public class AuthController : ControllerBase {
}
// TODO
// refresh tokens
// email verification
// password reset
// oh hell naw 2FA I do not care enough

View File

@@ -69,4 +69,12 @@ public class JwtService {
return await db_.Users.FindAsync(id);
}
public async Task<bool> RevokeRefreshToken(string refreshTokenString) {
var refreshToken = await db_.RefreshTokens.FirstOrDefaultAsync(u => u.Token == refreshTokenString);
if(refreshToken == null) return false;
refreshToken.IsRevoked = true;
await db_.SaveChangesAsync();
return true;
}
}