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

Move public base URL from oauth2 config to http config

This commit is contained in:
Quentin Gliech
2022-02-01 09:34:17 +01:00
parent f96c5b0cec
commit c0e5b66ea4
15 changed files with 166 additions and 74 deletions

View File

@@ -17,6 +17,7 @@ use std::path::PathBuf;
use async_trait::async_trait;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use url::Url;
use super::ConfigurationSection;
@@ -24,6 +25,10 @@ fn default_http_address() -> String {
"[::]:8080".into()
}
fn default_public_base() -> Url {
"http://[::]:8080".parse().unwrap()
}
fn http_address_example_1() -> &'static str {
"[::1]:8080"
}
@@ -54,6 +59,9 @@ pub struct HttpConfig {
/// the static files embedded in the server binary
#[serde(default)]
pub web_root: Option<PathBuf>,
/// Public URL base from where the authentication service is reachable
pub public_base: Url,
}
impl Default for HttpConfig {
@@ -61,6 +69,7 @@ impl Default for HttpConfig {
Self {
address: default_http_address(),
web_root: None,
public_base: default_public_base(),
}
}
}

View File

@@ -126,15 +126,8 @@ impl OAuth2ClientConfig {
}
}
fn default_oauth2_issuer() -> Url {
"http://[::]:8080".parse().unwrap()
}
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct OAuth2Config {
#[serde(default = "default_oauth2_issuer")]
pub issuer: Url,
#[serde(default)]
pub clients: Vec<OAuth2ClientConfig>,
@@ -143,13 +136,6 @@ pub struct OAuth2Config {
}
impl OAuth2Config {
#[must_use]
pub fn discovery_url(&self) -> Url {
self.issuer
.join(".well-known/openid-configuration")
.expect("could not build discovery url")
}
pub async fn key_store(&self) -> anyhow::Result<StaticKeystore> {
let mut store = StaticKeystore::new();
@@ -251,7 +237,6 @@ impl ConfigurationSection<'_> for OAuth2Config {
};
Ok(Self {
issuer: default_oauth2_issuer(),
clients: Vec::new(),
keys: vec![rsa_key, ecdsa_key],
})
@@ -291,7 +276,6 @@ impl ConfigurationSection<'_> for OAuth2Config {
};
Self {
issuer: default_oauth2_issuer(),
clients: Vec::new(),
keys: vec![rsa_key, ecdsa_key],
}
@@ -331,7 +315,6 @@ mod tests {
NaiDiepgUJ2GI5eq2V8D8nahRANCAARMK9aKUd/H28qaU+0qvS6bSJItzAge1VHn
OhBAAUVci1RpmUA+KdCL5sw9nadAEiONeiGr+28RYHZmlB9qXnjC
-----END PRIVATE KEY-----
issuer: https://example.com
clients:
- client_id: public
client_auth_method: none
@@ -372,7 +355,6 @@ mod tests {
let config = OAuth2Config::load_from_file("config.yaml")?;
assert_eq!(config.issuer, "https://example.com".parse().unwrap());
assert_eq!(config.clients.len(), 5);
assert_eq!(config.clients[0].client_id, "public");