Added an authorization header bearer token extraction demo.

This commit is contained in:
2026-10-09 16:46:28 +02:00
parent 18e142ec91
commit 7fb3abc93d
6 changed files with 236 additions and 1 deletions
+28
View File
@@ -6,6 +6,21 @@ use crate::{
domain::Token,
};
pub async fn get_by_access_token_hash<'e, E>(
executor: E,
access_token_hash: &[u8],
) -> Result<Option<Token>, RepositoryError>
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let token = db::get_by_access_token_hash(executor, access_token_hash)
.await?
.map(decode)
.transpose()?;
Ok(token)
}
pub async fn issue<'e, E>(executor: E, token: Token) -> Result<(), RepositoryError>
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
@@ -42,6 +57,19 @@ where
Ok(db::revoke(executor, token_hash).await?)
}
fn decode(token: TokenRow) -> Result<Token, RepositoryError> {
Ok(Token {
id: token.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,
refreshed_at: token.refreshed_at,
revoked_at: token.revoked_at,
created_at: token.created_at,
})
}
fn encode(token: Token) -> TokenRow {
TokenRow {
id: token.id,