Added user apps and token resources.

This commit is contained in:
2026-10-07 22:50:18 +02:00
parent 1f1f027368
commit 9038120734
47 changed files with 1940 additions and 29 deletions
+56
View File
@@ -0,0 +1,56 @@
use chrono::{DateTime, Utc};
use super::RepositoryError;
use crate::{
database::{dtos::TokenRow, tokens as db},
domain::Token,
};
pub async fn issue<'e, E>(executor: E, token: Token) -> Result<(), RepositoryError>
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
Ok(db::issue(executor, encode(token)).await?)
}
pub async fn rotate_refresh_token<'e, E>(
executor: E,
old_refresh_hash: &[u8],
access_token_hash: &[u8],
refresh_token_hash: &[u8],
access_expires_at: DateTime<Utc>,
refresh_expires_at: DateTime<Utc>,
) -> Result<bool, RepositoryError>
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
Ok(db::rotate_refresh_token(
executor,
old_refresh_hash,
access_token_hash,
refresh_token_hash,
access_expires_at,
refresh_expires_at,
)
.await?)
}
pub async fn revoke<'e, E>(executor: E, token_hash: &[u8]) -> Result<(), RepositoryError>
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
Ok(db::revoke(executor, token_hash).await?)
}
fn encode(token: Token) -> TokenRow {
TokenRow {
id: token.id,
app_id: token.app_id,
access_token_hash: token.access_token_hash,
refresh_token_hash: token.refresh_token_hash,
access_expires_at: token.access_expires_at,
refresh_expires_at: token.refresh_expires_at,
revoked_at: token.revoked_at,
created_at: token.created_at,
}
}