1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-11-20 12:02:22 +03:00

Working legacy login endpoint

This commit is contained in:
Quentin Gliech
2022-05-12 18:47:13 +02:00
parent 1ebdd0b731
commit 1aff98bdb3
14 changed files with 615 additions and 25 deletions

View File

@@ -0,0 +1,82 @@
// Copyright 2022 The Matrix.org Foundation C.I.C.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use async_trait::async_trait;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use super::ConfigurationSection;
fn default_homeserver() -> String {
"localhost:8008".to_string()
}
/// Configuration related to the Matrix homeserver
#[serde_as]
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct MatrixConfig {
/// Time-to-live of a CSRF token in seconds
#[serde(default = "default_homeserver")]
pub homeserver: String,
}
impl Default for MatrixConfig {
fn default() -> Self {
Self {
homeserver: default_homeserver(),
}
}
}
#[async_trait]
impl ConfigurationSection<'_> for MatrixConfig {
fn path() -> &'static str {
"matrix"
}
async fn generate() -> anyhow::Result<Self> {
Ok(Self::default())
}
fn test() -> Self {
Self::default()
}
}
#[cfg(test)]
mod tests {
use figment::Jail;
use super::*;
#[test]
fn load_config() {
Jail::expect_with(|jail| {
jail.create_file(
"config.yaml",
r#"
matrix:
homeserver: matrix.org
"#,
)?;
let config = MatrixConfig::load_from_file("config.yaml")?;
assert_eq!(config.homeserver, "matrix.org".to_string());
Ok(())
});
}
}

View File

@@ -21,6 +21,7 @@ mod csrf;
mod database;
mod email;
mod http;
mod matrix;
mod secrets;
mod telemetry;
mod templates;
@@ -31,6 +32,7 @@ pub use self::{
database::DatabaseConfig,
email::{EmailConfig, EmailSmtpMode, EmailTransportConfig},
http::HttpConfig,
matrix::MatrixConfig,
secrets::{Encrypter, SecretsConfig},
telemetry::{
MetricsConfig, MetricsExporterConfig, Propagator, TelemetryConfig, TracingConfig,
@@ -73,6 +75,10 @@ pub struct RootConfig {
/// Application secrets
pub secrets: SecretsConfig,
/// Configuration related to the homeserver
#[serde(default)]
pub matrix: MatrixConfig,
}
#[async_trait]
@@ -91,6 +97,7 @@ impl ConfigurationSection<'_> for RootConfig {
csrf: CsrfConfig::generate().await?,
email: EmailConfig::generate().await?,
secrets: SecretsConfig::generate().await?,
matrix: MatrixConfig::generate().await?,
})
}
@@ -104,6 +111,7 @@ impl ConfigurationSection<'_> for RootConfig {
csrf: CsrfConfig::test(),
email: EmailConfig::test(),
secrets: SecretsConfig::test(),
matrix: MatrixConfig::test(),
}
}
}