feat: Implement oauth token revocation

This commit is contained in:
Ginger
2026-04-30 10:49:03 -04:00
parent 3dc4c7d4fc
commit ee73a2b36d
5 changed files with 63 additions and 16 deletions
+5
View File
@@ -144,3 +144,8 @@ pub struct TokenResponse {
pub enum TokenType {
Bearer,
}
#[derive(Deserialize)]
pub struct RevokeTokenRequest {
pub token: String,
}
+24
View File
@@ -306,6 +306,30 @@ impl Service {
}
}
pub async fn revoke_token(&self, token: String) -> Result<()> {
let (user_id, device_id) = if let Ok(refresh_token_info) = self
.db
.refreshtoken_refreshtokeninfo
.get(&token)
.await
.deserialized::<RefreshTokenInfo>()
{
(refresh_token_info.user_id, refresh_token_info.device_id)
} else if let Some(user) = self.services.users.find_from_token(&token).await {
user
} else {
return Err!("Invalid token");
};
// This will also call [`Self::remove_session`]
self.services
.users
.remove_device(&user_id, &device_id)
.await;
Ok(())
}
async fn create_session(
&self,
authorizing_user: OwnedUserId,