Added an authorization header bearer token extraction demo.
This commit is contained in:
@@ -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>,
|
||||
|
||||
Reference in New Issue
Block a user