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

data-model: simplify the oauth2 clients

This commit is contained in:
Quentin Gliech
2022-12-07 14:46:08 +01:00
parent 6d82199910
commit 92d6f5b087
12 changed files with 46 additions and 80 deletions

View File

@ -28,7 +28,7 @@ use crate::{Clock, DatabaseInconsistencyError, LookupError, PostgresqlBackend};
skip_all,
fields(
session.id = %session.data,
client.id = %session.client.data,
client.id = %session.client.id,
user.id = %session.browser_session.user.id,
access_token.id,
),

View File

@ -36,7 +36,7 @@ use crate::{Clock, DatabaseInconsistencyError, PostgresqlBackend};
#[tracing::instrument(
skip_all,
fields(
client.id = %client.data,
%client.id,
grant.id,
),
err(Debug),
@ -46,7 +46,7 @@ pub async fn new_authorization_grant(
executor: impl PgExecutor<'_>,
mut rng: impl Rng + Send,
clock: &Clock,
client: Client<PostgresqlBackend>,
client: Client,
redirect_uri: Url,
scope: Scope,
code: Option<AuthorizationCode>,
@ -97,7 +97,7 @@ pub async fn new_authorization_grant(
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)
"#,
Uuid::from(id),
Uuid::from(client.data),
Uuid::from(client.id),
redirect_uri.to_string(),
scope.to_string(),
state,
@ -498,7 +498,7 @@ pub async fn lookup_grant_by_code(
skip_all,
fields(
grant.id = %grant.data,
client.id = %grant.client.data,
client.id = %grant.client.id,
session.id,
user_session.id = %browser_session.id,
user.id = %browser_session.user.id,
@ -552,7 +552,7 @@ pub async fn derive_session(
skip_all,
fields(
grant.id = %grant.data,
client.id = %grant.client.data,
client.id = %grant.client.id,
session.id = %session.data,
user_session.id = %session.browser_session.id,
user.id = %session.browser_session.user.id,
@ -592,7 +592,7 @@ pub async fn fulfill_grant(
skip_all,
fields(
grant.id = %grant.data,
client.id = %grant.client.data,
client.id = %grant.client.id,
),
err(Debug),
)]
@ -622,7 +622,7 @@ pub async fn give_consent_to_grant(
skip_all,
fields(
grant.id = %grant.data,
client.id = %grant.client.data,
client.id = %grant.client.id,
),
err(Debug),
)]

View File

@ -28,7 +28,7 @@ use ulid::Ulid;
use url::Url;
use uuid::Uuid;
use crate::{Clock, LookupError, PostgresqlBackend};
use crate::{Clock, LookupError};
// XXX: response_types & contacts
#[derive(Debug)]
@ -90,11 +90,11 @@ impl LookupError for ClientFetchError {
}
}
impl TryInto<Client<PostgresqlBackend>> for OAuth2ClientLookup {
impl TryInto<Client> for OAuth2ClientLookup {
type Error = ClientFetchError;
#[allow(clippy::too_many_lines)] // TODO: refactor some of the field parsing
fn try_into(self) -> Result<Client<PostgresqlBackend>, Self::Error> {
fn try_into(self) -> Result<Client, Self::Error> {
let redirect_uris: Result<Vec<Url>, _> =
self.redirect_uris.iter().map(|s| s.parse()).collect();
let redirect_uris = redirect_uris.map_err(|source| ClientFetchError::ParseUrl {
@ -226,7 +226,7 @@ impl TryInto<Client<PostgresqlBackend>> for OAuth2ClientLookup {
let id = Ulid::from(self.oauth2_client_id);
Ok(Client {
data: id,
id,
client_id: id.to_string(),
encrypted_client_secret: self.encrypted_client_secret,
redirect_uris,
@ -253,7 +253,7 @@ impl TryInto<Client<PostgresqlBackend>> for OAuth2ClientLookup {
pub async fn lookup_clients(
executor: impl PgExecutor<'_>,
ids: impl IntoIterator<Item = Ulid> + Send,
) -> Result<HashMap<Ulid, Client<PostgresqlBackend>>, ClientFetchError> {
) -> Result<HashMap<Ulid, Client>, ClientFetchError> {
let ids: Vec<Uuid> = ids.into_iter().map(Uuid::from).collect();
let res = sqlx::query_as!(
OAuth2ClientLookup,
@ -289,9 +289,9 @@ pub async fn lookup_clients(
.fetch_all(executor)
.await?;
let clients: Result<HashMap<Ulid, Client<PostgresqlBackend>>, _> = res
let clients: Result<HashMap<Ulid, Client>, _> = res
.into_iter()
.map(|r| r.try_into().map(|c: Client<PostgresqlBackend>| (c.data, c)))
.map(|r| r.try_into().map(|c: Client| (c.id, c)))
.collect();
clients
@ -305,7 +305,7 @@ pub async fn lookup_clients(
pub async fn lookup_client(
executor: impl PgExecutor<'_>,
id: Ulid,
) -> Result<Client<PostgresqlBackend>, ClientFetchError> {
) -> Result<Client, ClientFetchError> {
let res = sqlx::query_as!(
OAuth2ClientLookup,
r#"
@ -353,7 +353,7 @@ pub async fn lookup_client(
pub async fn lookup_client_by_client_id(
executor: impl PgExecutor<'_>,
client_id: &str,
) -> Result<Client<PostgresqlBackend>, ClientFetchError> {
) -> Result<Client, ClientFetchError> {
let id: Ulid = client_id.parse()?;
lookup_client(executor, id).await
}

View File

@ -21,20 +21,20 @@ use sqlx::PgExecutor;
use ulid::Ulid;
use uuid::Uuid;
use crate::{Clock, PostgresqlBackend};
use crate::Clock;
#[tracing::instrument(
skip_all,
fields(
%user.id,
client.id = %client.data,
%client.id,
),
err(Debug),
)]
pub async fn fetch_client_consent(
executor: impl PgExecutor<'_>,
user: &User,
client: &Client<PostgresqlBackend>,
client: &Client,
) -> Result<Scope, anyhow::Error> {
let scope_tokens: Vec<String> = sqlx::query_scalar!(
r#"
@ -43,7 +43,7 @@ pub async fn fetch_client_consent(
WHERE user_id = $1 AND oauth2_client_id = $2
"#,
Uuid::from(user.id),
Uuid::from(client.data),
Uuid::from(client.id),
)
.fetch_all(executor)
.await?;
@ -60,8 +60,8 @@ pub async fn fetch_client_consent(
skip_all,
fields(
%user.id,
client.id = %client.data,
scope = scope.to_string(),
%client.id,
%scope,
),
err(Debug),
)]
@ -70,7 +70,7 @@ pub async fn insert_client_consent(
mut rng: impl Rng + Send,
clock: &Clock,
user: &User,
client: &Client<PostgresqlBackend>,
client: &Client,
scope: &Scope,
) -> Result<(), anyhow::Error> {
let now = clock.now();
@ -93,7 +93,7 @@ pub async fn insert_client_consent(
"#,
&ids,
Uuid::from(user.id),
Uuid::from(client.data),
Uuid::from(client.id),
&tokens,
now,
)

View File

@ -40,7 +40,7 @@ pub mod refresh_token;
session.id = %session.data,
user.id = %session.browser_session.user.id,
user_session.id = %session.browser_session.id,
client.id = %session.client.data,
client.id = %session.client.id,
),
err(Debug),
)]

View File

@ -32,7 +32,7 @@ use crate::{Clock, DatabaseInconsistencyError, LookupError, PostgresqlBackend};
session.id = %session.data,
user.id = %session.browser_session.user.id,
user_session.id = %session.browser_session.id,
client.id = %session.client.data,
client.id = %session.client.id,
refresh_token.id,
),
err(Debug),