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
+25
View File
@@ -2,6 +2,31 @@ use chrono::{DateTime, Utc};
use super::{DatabaseError, dtos::TokenRow};
pub async fn get_by_access_token_hash<'e, E>(
executor: E,
access_token_hash: &[u8],
) -> Result<Option<TokenRow>, DatabaseError>
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let row = sqlx::query_as!(
TokenRow,
r#"
SELECT *
FROM tokens
WHERE access_token_hash = $1
AND access_expires_at > now()
AND revoked_at IS NULL
"#,
access_token_hash,
)
.fetch_optional(executor)
.await
.map_err(DatabaseError::from)?;
Ok(row)
}
pub async fn issue<'e, E>(executor: E, token: TokenRow) -> Result<(), DatabaseError>
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,