add logout for refreshTokens
All checks were successful
Build and Deploy API / build-and-deploy (push) Successful in 8s
All checks were successful
Build and Deploy API / build-and-deploy (push) Successful in 8s
This commit is contained in:
@@ -39,7 +39,8 @@ builder.Services.AddAuthentication(options => {
|
|||||||
ValidateIssuerSigningKey = true,
|
ValidateIssuerSigningKey = true,
|
||||||
ValidIssuer = "agologum",
|
ValidIssuer = "agologum",
|
||||||
ValidAudience = "agologum",
|
ValidAudience = "agologum",
|
||||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key))
|
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key)),
|
||||||
|
ClockSkew = TimeSpan.Zero
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -67,10 +67,10 @@ public class AuthController : ControllerBase {
|
|||||||
|
|
||||||
[Authorize] // authorize is handled by middleware
|
[Authorize] // authorize is handled by middleware
|
||||||
[HttpPost("logout")]
|
[HttpPost("logout")]
|
||||||
public ActionResult Logout() {
|
public async Task<ActionResult> Logout(string refreshTokenString) {
|
||||||
// dummy endpoint
|
// revoke refresh token
|
||||||
// logout happens upon client-side jwt removal
|
bool success = await jwt_.RevokeRefreshToken(refreshTokenString);
|
||||||
// TODO: expire all refresh tokens
|
if(!success) return NotFound();
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +106,6 @@ public class AuthController : ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
// refresh tokens
|
|
||||||
// email verification
|
// email verification
|
||||||
// password reset
|
// password reset
|
||||||
// oh hell naw 2FA I do not care enough
|
// oh hell naw 2FA I do not care enough
|
||||||
|
|||||||
@@ -69,4 +69,12 @@ public class JwtService {
|
|||||||
return await db_.Users.FindAsync(id);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user