You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-08-07 17:03:01 +03:00
Allow disabling registrations (#2553)
This commit is contained in:
@@ -19,7 +19,7 @@ use clap::Parser;
|
||||
use figment::Figment;
|
||||
use itertools::Itertools;
|
||||
use mas_config::{AppConfig, ClientsConfig, ConfigurationSection, UpstreamOAuth2Config};
|
||||
use mas_handlers::{ActivityTracker, CookieManager, HttpClientFactory, MetadataCache, SiteConfig};
|
||||
use mas_handlers::{ActivityTracker, CookieManager, HttpClientFactory, MetadataCache};
|
||||
use mas_listener::{server::Server, shutdown::ShutdownStream};
|
||||
use mas_matrix_synapse::SynapseConnection;
|
||||
use mas_router::UrlBuilder;
|
||||
@@ -37,7 +37,8 @@ use crate::{
|
||||
app_state::AppState,
|
||||
util::{
|
||||
database_pool_from_config, mailer_from_config, password_manager_from_config,
|
||||
policy_factory_from_config, register_sighup, templates_from_config,
|
||||
policy_factory_from_config, register_sighup, site_config_from_config,
|
||||
templates_from_config,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -138,14 +139,17 @@ impl Options {
|
||||
None,
|
||||
);
|
||||
|
||||
// Load and compile the templates
|
||||
let templates = templates_from_config(
|
||||
&config.templates,
|
||||
// Load the site configuration
|
||||
let site_config = site_config_from_config(
|
||||
&config.branding,
|
||||
&url_builder,
|
||||
&config.matrix.homeserver,
|
||||
)
|
||||
.await?;
|
||||
&config.matrix,
|
||||
&config.experimental,
|
||||
&config.passwords,
|
||||
);
|
||||
|
||||
// Load and compile the templates
|
||||
let templates =
|
||||
templates_from_config(&config.templates, &site_config, &url_builder).await?;
|
||||
|
||||
let http_client_factory = HttpClientFactory::new();
|
||||
|
||||
@@ -179,12 +183,6 @@ impl Options {
|
||||
// The upstream OIDC metadata cache
|
||||
let metadata_cache = MetadataCache::new();
|
||||
|
||||
let site_config = SiteConfig {
|
||||
tos_uri: config.branding.tos_uri.clone(),
|
||||
access_token_ttl: config.experimental.access_token_ttl,
|
||||
compat_token_ttl: config.experimental.compat_token_ttl,
|
||||
};
|
||||
|
||||
// Initialize the activity tracker
|
||||
// Activity is flushed every minute
|
||||
let activity_tracker = ActivityTracker::new(pool.clone(), Duration::from_secs(60));
|
||||
|
@@ -14,12 +14,15 @@
|
||||
|
||||
use clap::Parser;
|
||||
use figment::Figment;
|
||||
use mas_config::{BrandingConfig, ConfigurationSection, MatrixConfig, TemplatesConfig};
|
||||
use mas_config::{
|
||||
BrandingConfig, ConfigurationSection, ExperimentalConfig, MatrixConfig, PasswordsConfig,
|
||||
TemplatesConfig,
|
||||
};
|
||||
use mas_storage::{Clock, SystemClock};
|
||||
use rand::SeedableRng;
|
||||
use tracing::info_span;
|
||||
|
||||
use crate::util::templates_from_config;
|
||||
use crate::util::{site_config_from_config, templates_from_config};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
pub(super) struct Options {
|
||||
@@ -43,19 +46,22 @@ impl Options {
|
||||
let template_config = TemplatesConfig::extract(figment)?;
|
||||
let branding_config = BrandingConfig::extract(figment)?;
|
||||
let matrix_config = MatrixConfig::extract(figment)?;
|
||||
let experimental_config = ExperimentalConfig::extract(figment)?;
|
||||
let password_config = PasswordsConfig::extract(figment)?;
|
||||
|
||||
let clock = SystemClock::default();
|
||||
// XXX: we should disallow SeedableRng::from_entropy
|
||||
let mut rng = rand_chacha::ChaChaRng::from_entropy();
|
||||
let url_builder =
|
||||
mas_router::UrlBuilder::new("https://example.com/".parse()?, None, None);
|
||||
let templates = templates_from_config(
|
||||
&template_config,
|
||||
let site_config = site_config_from_config(
|
||||
&branding_config,
|
||||
&url_builder,
|
||||
&matrix_config.homeserver,
|
||||
)
|
||||
.await?;
|
||||
&matrix_config,
|
||||
&experimental_config,
|
||||
&password_config,
|
||||
);
|
||||
let templates =
|
||||
templates_from_config(&template_config, &site_config, &url_builder).await?;
|
||||
templates.check_render(clock.now(), &mut rng)?;
|
||||
|
||||
Ok(())
|
||||
|
@@ -24,7 +24,9 @@ use rand::{
|
||||
};
|
||||
use tracing::{info, info_span};
|
||||
|
||||
use crate::util::{database_pool_from_config, mailer_from_config, templates_from_config};
|
||||
use crate::util::{
|
||||
database_pool_from_config, mailer_from_config, site_config_from_config, templates_from_config,
|
||||
};
|
||||
|
||||
#[derive(Parser, Debug, Default)]
|
||||
pub(super) struct Options {}
|
||||
@@ -44,14 +46,17 @@ impl Options {
|
||||
None,
|
||||
);
|
||||
|
||||
// Load and compile the templates
|
||||
let templates = templates_from_config(
|
||||
&config.templates,
|
||||
// Load the site configuration
|
||||
let site_config = site_config_from_config(
|
||||
&config.branding,
|
||||
&url_builder,
|
||||
&config.matrix.homeserver,
|
||||
)
|
||||
.await?;
|
||||
&config.matrix,
|
||||
&config.experimental,
|
||||
&config.passwords,
|
||||
);
|
||||
|
||||
// Load and compile the templates
|
||||
let templates =
|
||||
templates_from_config(&config.templates, &site_config, &url_builder).await?;
|
||||
|
||||
let mailer = mailer_from_config(&config.email, &templates)?;
|
||||
mailer.test_connection().await?;
|
||||
|
@@ -17,13 +17,13 @@ use std::time::Duration;
|
||||
use anyhow::Context;
|
||||
use mas_config::{
|
||||
BrandingConfig, DatabaseConfig, EmailConfig, EmailSmtpMode, EmailTransportKind,
|
||||
PasswordsConfig, PolicyConfig, TemplatesConfig,
|
||||
ExperimentalConfig, MatrixConfig, PasswordsConfig, PolicyConfig, TemplatesConfig,
|
||||
};
|
||||
use mas_email::{MailTransport, Mailer};
|
||||
use mas_handlers::{passwords::PasswordManager, ActivityTracker};
|
||||
use mas_handlers::{passwords::PasswordManager, ActivityTracker, SiteConfig};
|
||||
use mas_policy::PolicyFactory;
|
||||
use mas_router::UrlBuilder;
|
||||
use mas_templates::{SiteBranding, TemplateLoadingError, Templates};
|
||||
use mas_templates::{TemplateLoadingError, Templates};
|
||||
use sqlx::{
|
||||
postgres::{PgConnectOptions, PgPoolOptions},
|
||||
ConnectOptions, PgConnection, PgPool,
|
||||
@@ -119,36 +119,37 @@ pub async fn policy_factory_from_config(
|
||||
.context("failed to load the policy")
|
||||
}
|
||||
|
||||
pub fn site_config_from_config(
|
||||
branding_config: &BrandingConfig,
|
||||
matrix_config: &MatrixConfig,
|
||||
experimental_config: &ExperimentalConfig,
|
||||
password_config: &PasswordsConfig,
|
||||
) -> SiteConfig {
|
||||
SiteConfig {
|
||||
access_token_ttl: experimental_config.access_token_ttl,
|
||||
compat_token_ttl: experimental_config.compat_token_ttl,
|
||||
server_name: matrix_config.homeserver.clone(),
|
||||
policy_uri: branding_config.policy_uri.clone(),
|
||||
tos_uri: branding_config.tos_uri.clone(),
|
||||
imprint: branding_config.imprint.clone(),
|
||||
password_login_enabled: password_config.enabled(),
|
||||
password_registration_enabled: password_config.enabled()
|
||||
&& experimental_config.password_registration_enabled,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn templates_from_config(
|
||||
config: &TemplatesConfig,
|
||||
branding: &BrandingConfig,
|
||||
site_config: &SiteConfig,
|
||||
url_builder: &UrlBuilder,
|
||||
server_name: &str,
|
||||
) -> Result<Templates, TemplateLoadingError> {
|
||||
let mut site_branding = SiteBranding::new(server_name);
|
||||
|
||||
if let Some(service_name) = branding.service_name.as_deref() {
|
||||
site_branding = site_branding.with_service_name(service_name);
|
||||
}
|
||||
|
||||
if let Some(policy_uri) = &branding.policy_uri {
|
||||
site_branding = site_branding.with_policy_uri(policy_uri.as_str());
|
||||
}
|
||||
|
||||
if let Some(tos_uri) = &branding.tos_uri {
|
||||
site_branding = site_branding.with_tos_uri(tos_uri.as_str());
|
||||
}
|
||||
|
||||
if let Some(imprint) = branding.imprint.as_deref() {
|
||||
site_branding = site_branding.with_imprint(imprint);
|
||||
}
|
||||
|
||||
Templates::load(
|
||||
config.path.clone(),
|
||||
url_builder.clone(),
|
||||
config.assets_manifest.clone(),
|
||||
config.translations_path.clone(),
|
||||
site_branding,
|
||||
site_config.templates_branding(),
|
||||
site_config.templates_features(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
Reference in New Issue
Block a user