1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-29 22:01:14 +03:00

Handle legacy /logout

This commit is contained in:
Quentin Gliech
2022-05-13 09:54:08 +02:00
parent 1aff98bdb3
commit 660b2d5232
7 changed files with 289 additions and 133 deletions

View File

@ -129,7 +129,7 @@ pub async fn lookup_active_compat_access_token(
Ok((token, user))
}
#[tracing::instrument(skip(conn, password))]
#[tracing::instrument(skip(conn, password, token))]
pub async fn compat_login(
conn: impl Acquire<'_, Database = Postgres>,
username: &str,
@ -200,3 +200,27 @@ pub async fn compat_login(
txn.commit().await.context("could not commit transaction")?;
Ok((token, user))
}
#[tracing::instrument(skip_all)]
pub async fn compat_logout(
executor: impl PgExecutor<'_>,
token: &str,
) -> Result<(), anyhow::Error> {
let res = sqlx::query!(
r#"
UPDATE compat_access_tokens
SET deleted_at = NOW()
WHERE token = $1 AND deleted_at IS NULL
"#,
token,
)
.execute(executor)
.await
.context("could not update compat access token")?;
match res.rows_affected() {
1 => Ok(()),
0 => anyhow::bail!("no row affected"),
_ => anyhow::bail!("too many row affected"),
}
}