Added initial authorization layer.
This commit is contained in:
@@ -3,6 +3,8 @@ use uuid::Uuid;
|
||||
|
||||
pub struct TokenRow {
|
||||
pub id: Uuid,
|
||||
pub user_id: Uuid,
|
||||
pub user_app_id: Option<Uuid>,
|
||||
pub access_token_hash: Vec<u8>,
|
||||
pub refresh_token_hash: Vec<u8>,
|
||||
pub access_expires_at: DateTime<Utc>,
|
||||
|
||||
@@ -12,7 +12,17 @@ where
|
||||
let row = sqlx::query_as!(
|
||||
TokenRow,
|
||||
r#"
|
||||
SELECT *
|
||||
SELECT
|
||||
id,
|
||||
user_id,
|
||||
user_app_id,
|
||||
access_token_hash,
|
||||
refresh_token_hash,
|
||||
access_expires_at,
|
||||
refresh_expires_at,
|
||||
refreshed_at,
|
||||
revoked_at,
|
||||
created_at
|
||||
FROM tokens
|
||||
WHERE access_token_hash = $1
|
||||
AND access_expires_at > now()
|
||||
@@ -34,12 +44,14 @@ where
|
||||
sqlx::query!(
|
||||
r#"
|
||||
INSERT INTO tokens (
|
||||
id, access_token_hash, refresh_token_hash,
|
||||
id, user_id, user_app_id, access_token_hash, refresh_token_hash,
|
||||
access_expires_at, refresh_expires_at, refreshed_at, revoked_at, created_at
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
||||
"#,
|
||||
token.id,
|
||||
token.user_id,
|
||||
token.user_app_id,
|
||||
token.access_token_hash,
|
||||
token.refresh_token_hash,
|
||||
token.access_expires_at,
|
||||
|
||||
Reference in New Issue
Block a user