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