Do not tie tokens to a user app.
This commit is contained in:
@@ -3,7 +3,6 @@ use uuid::Uuid;
|
||||
|
||||
pub struct TokenRow {
|
||||
pub id: Uuid,
|
||||
pub app_id: Uuid,
|
||||
pub access_token_hash: Vec<u8>,
|
||||
pub refresh_token_hash: Vec<u8>,
|
||||
pub access_expires_at: DateTime<Utc>,
|
||||
|
||||
@@ -9,13 +9,12 @@ where
|
||||
sqlx::query!(
|
||||
r#"
|
||||
INSERT INTO tokens (
|
||||
id, app_id, access_token_hash, refresh_token_hash,
|
||||
id, access_token_hash, refresh_token_hash,
|
||||
access_expires_at, refresh_expires_at, revoked_at, created_at
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
"#,
|
||||
token.id,
|
||||
token.app_id,
|
||||
token.access_token_hash,
|
||||
token.refresh_token_hash,
|
||||
token.access_expires_at,
|
||||
|
||||
@@ -4,7 +4,6 @@ use uuid::Uuid;
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct Token {
|
||||
pub id: Uuid,
|
||||
pub app_id: Uuid,
|
||||
pub access_token_hash: Vec<u8>,
|
||||
pub refresh_token_hash: Vec<u8>,
|
||||
pub access_expires_at: DateTime<Utc>,
|
||||
|
||||
@@ -45,7 +45,6 @@ where
|
||||
fn encode(token: Token) -> TokenRow {
|
||||
TokenRow {
|
||||
id: token.id,
|
||||
app_id: token.app_id,
|
||||
access_token_hash: token.access_token_hash,
|
||||
refresh_token_hash: token.refresh_token_hash,
|
||||
access_expires_at: token.access_expires_at,
|
||||
|
||||
@@ -40,7 +40,7 @@ async fn issue_token(
|
||||
}
|
||||
|
||||
let generated = generate_token_pair()?;
|
||||
repository::tokens::issue(&pool, token(client_id, &generated)).await?;
|
||||
repository::tokens::issue(&pool, token(&generated)).await?;
|
||||
|
||||
Ok(Json(token_response(
|
||||
generated.access_token,
|
||||
@@ -110,10 +110,9 @@ fn generate_token_pair() -> Result<GeneratedTokenPair, AppError> {
|
||||
})
|
||||
}
|
||||
|
||||
fn token(app_id: Uuid, generated: &GeneratedTokenPair) -> Token {
|
||||
fn token(generated: &GeneratedTokenPair) -> Token {
|
||||
Token {
|
||||
id: Uuid::new_v4(),
|
||||
app_id,
|
||||
access_token_hash: generated.access_token_hash.clone(),
|
||||
refresh_token_hash: generated.refresh_token_hash.clone(),
|
||||
access_expires_at: generated.access_expires_at,
|
||||
|
||||
Reference in New Issue
Block a user