You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-08-06 06:02:40 +03:00
Use dynamic filters on upstream OAuth 2.0 providers
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "\n INSERT INTO upstream_oauth_providers (\n upstream_oauth_provider_id,\n issuer,\n human_name,\n brand_name,\n scope,\n token_endpoint_auth_method,\n token_endpoint_signing_alg,\n client_id,\n encrypted_client_secret,\n claims_imports,\n authorization_endpoint_override,\n token_endpoint_override,\n jwks_uri_override,\n discovery_mode,\n pkce_mode,\n additional_parameters,\n created_at\n ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9,\n $10, $11, $12, $13, $14, $15, $16, $17)\n ON CONFLICT (upstream_oauth_provider_id) \n DO UPDATE\n SET\n issuer = EXCLUDED.issuer,\n human_name = EXCLUDED.human_name,\n brand_name = EXCLUDED.brand_name,\n scope = EXCLUDED.scope,\n token_endpoint_auth_method = EXCLUDED.token_endpoint_auth_method,\n token_endpoint_signing_alg = EXCLUDED.token_endpoint_signing_alg,\n disabled_at = NULL,\n client_id = EXCLUDED.client_id,\n encrypted_client_secret = EXCLUDED.encrypted_client_secret,\n claims_imports = EXCLUDED.claims_imports,\n authorization_endpoint_override = EXCLUDED.authorization_endpoint_override,\n token_endpoint_override = EXCLUDED.token_endpoint_override,\n jwks_uri_override = EXCLUDED.jwks_uri_override,\n discovery_mode = EXCLUDED.discovery_mode,\n pkce_mode = EXCLUDED.pkce_mode,\n additional_parameters = EXCLUDED.additional_parameters\n RETURNING created_at\n ",
|
"query": "\n INSERT INTO upstream_oauth_providers (\n upstream_oauth_provider_id,\n issuer,\n human_name,\n brand_name,\n scope,\n token_endpoint_auth_method,\n token_endpoint_signing_alg,\n client_id,\n encrypted_client_secret,\n claims_imports,\n authorization_endpoint_override,\n token_endpoint_override,\n jwks_uri_override,\n discovery_mode,\n pkce_mode,\n additional_parameters,\n created_at\n ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9,\n $10, $11, $12, $13, $14, $15, $16, $17)\n ON CONFLICT (upstream_oauth_provider_id)\n DO UPDATE\n SET\n issuer = EXCLUDED.issuer,\n human_name = EXCLUDED.human_name,\n brand_name = EXCLUDED.brand_name,\n scope = EXCLUDED.scope,\n token_endpoint_auth_method = EXCLUDED.token_endpoint_auth_method,\n token_endpoint_signing_alg = EXCLUDED.token_endpoint_signing_alg,\n disabled_at = NULL,\n client_id = EXCLUDED.client_id,\n encrypted_client_secret = EXCLUDED.encrypted_client_secret,\n claims_imports = EXCLUDED.claims_imports,\n authorization_endpoint_override = EXCLUDED.authorization_endpoint_override,\n token_endpoint_override = EXCLUDED.token_endpoint_override,\n jwks_uri_override = EXCLUDED.jwks_uri_override,\n discovery_mode = EXCLUDED.discovery_mode,\n pkce_mode = EXCLUDED.pkce_mode,\n additional_parameters = EXCLUDED.additional_parameters\n RETURNING created_at\n ",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
{
|
{
|
||||||
@@ -34,5 +34,5 @@
|
|||||||
false
|
false
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"hash": "94fd87e99088671b6a20bb7b9a3838ecce8df564257b348adf22f2e9356e6dae"
|
"hash": "9aa8fa3a6277f67b2bf5a5ea5429a61e7997ff4f3e8d0dc772448a1f97e1e390"
|
||||||
}
|
}
|
@@ -31,8 +31,11 @@ use ulid::Ulid;
|
|||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
iden::UpstreamOAuthProviders, pagination::QueryBuilderExt, tracing::ExecuteExt, DatabaseError,
|
filter::{Filter, StatementExt},
|
||||||
DatabaseInconsistencyError,
|
iden::UpstreamOAuthProviders,
|
||||||
|
pagination::QueryBuilderExt,
|
||||||
|
tracing::ExecuteExt,
|
||||||
|
DatabaseError, DatabaseInconsistencyError,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// An implementation of [`UpstreamOAuthProviderRepository`] for a PostgreSQL
|
/// An implementation of [`UpstreamOAuthProviderRepository`] for a PostgreSQL
|
||||||
@@ -174,6 +177,19 @@ impl TryFrom<ProviderLookup> for UpstreamOAuthProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Filter for UpstreamOAuthProviderFilter<'_> {
|
||||||
|
fn generate_condition(&self, _has_joins: bool) -> impl sea_query::IntoCondition {
|
||||||
|
sea_query::Condition::all().add_option(self.enabled().map(|enabled| {
|
||||||
|
Expr::col((
|
||||||
|
UpstreamOAuthProviders::Table,
|
||||||
|
UpstreamOAuthProviders::DisabledAt,
|
||||||
|
))
|
||||||
|
.is_null()
|
||||||
|
.eq(enabled)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<'c> UpstreamOAuthProviderRepository for PgUpstreamOAuthProviderRepository<'c> {
|
impl<'c> UpstreamOAuthProviderRepository for PgUpstreamOAuthProviderRepository<'c> {
|
||||||
type Error = DatabaseError;
|
type Error = DatabaseError;
|
||||||
@@ -429,7 +445,7 @@ impl<'c> UpstreamOAuthProviderRepository for PgUpstreamOAuthProviderRepository<'
|
|||||||
created_at
|
created_at
|
||||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9,
|
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9,
|
||||||
$10, $11, $12, $13, $14, $15, $16, $17)
|
$10, $11, $12, $13, $14, $15, $16, $17)
|
||||||
ON CONFLICT (upstream_oauth_provider_id)
|
ON CONFLICT (upstream_oauth_provider_id)
|
||||||
DO UPDATE
|
DO UPDATE
|
||||||
SET
|
SET
|
||||||
issuer = EXCLUDED.issuer,
|
issuer = EXCLUDED.issuer,
|
||||||
@@ -676,14 +692,7 @@ impl<'c> UpstreamOAuthProviderRepository for PgUpstreamOAuthProviderRepository<'
|
|||||||
ProviderLookupIden::AdditionalParameters,
|
ProviderLookupIden::AdditionalParameters,
|
||||||
)
|
)
|
||||||
.from(UpstreamOAuthProviders::Table)
|
.from(UpstreamOAuthProviders::Table)
|
||||||
.and_where_option(filter.enabled().map(|enabled| {
|
.apply_filter(filter)
|
||||||
Expr::col((
|
|
||||||
UpstreamOAuthProviders::Table,
|
|
||||||
UpstreamOAuthProviders::DisabledAt,
|
|
||||||
))
|
|
||||||
.is_null()
|
|
||||||
.eq(enabled)
|
|
||||||
}))
|
|
||||||
.generate_pagination(
|
.generate_pagination(
|
||||||
(
|
(
|
||||||
UpstreamOAuthProviders::Table,
|
UpstreamOAuthProviders::Table,
|
||||||
@@ -726,14 +735,7 @@ impl<'c> UpstreamOAuthProviderRepository for PgUpstreamOAuthProviderRepository<'
|
|||||||
.count(),
|
.count(),
|
||||||
)
|
)
|
||||||
.from(UpstreamOAuthProviders::Table)
|
.from(UpstreamOAuthProviders::Table)
|
||||||
.and_where_option(filter.enabled().map(|enabled| {
|
.apply_filter(filter)
|
||||||
Expr::col((
|
|
||||||
UpstreamOAuthProviders::Table,
|
|
||||||
UpstreamOAuthProviders::DisabledAt,
|
|
||||||
))
|
|
||||||
.is_null()
|
|
||||||
.eq(enabled)
|
|
||||||
}))
|
|
||||||
.build_sqlx(PostgresQueryBuilder);
|
.build_sqlx(PostgresQueryBuilder);
|
||||||
|
|
||||||
let count: i64 = sqlx::query_scalar_with(&sql, arguments)
|
let count: i64 = sqlx::query_scalar_with(&sql, arguments)
|
||||||
|
Reference in New Issue
Block a user