@jpgilldev / steid

steid/src/domain/repository/token_repo.rs
1.4 KBRaw
1use super::RepositoryResult;
2use crate::domain::{PersonalAccessToken, TokenHash, TokenId, UserId};
3
4/// Persistence for [`PersonalAccessToken`].
5pub trait TokenRepository: Send + Sync {
6 /// Looks a token up by the hash of what a client presented.
7 ///
8 /// By hash rather than by id, because a client presents the token itself and never
9 /// its id — this is the lookup that authentication actually performs, so it is the
10 /// one the storage layer has to make fast.
11 fn find_by_hash(
12 &self,
13 hash: &TokenHash,
14 ) -> impl Future<Output = RepositoryResult<Option<PersonalAccessToken>>> + Send;
15
16 /// Every token a user holds, newest first.
17 fn list_by_user(
18 &self,
19 user_id: &UserId,
20 ) -> impl Future<Output = RepositoryResult<Vec<PersonalAccessToken>>> + Send;
21
22 /// Inserts or replaces a token.
23 fn save(
24 &self,
25 token: &PersonalAccessToken,
26 ) -> impl Future<Output = RepositoryResult<()>> + Send;
27
28 /// Deletes a token, succeeding if there was nothing to delete.
29 ///
30 /// Revocation is a delete rather than a flag: a revoked token that lingers in the
31 /// table is a credential that stops working only as long as every read remembers to
32 /// check the flag. Nothing needs the history.
33 fn delete(&self, id: &TokenId) -> impl Future<Output = RepositoryResult<()>> + Send;
34}