arminius_server_client/handlers/
auth.rs1mod tests;
8
9use arminius_lib_component::{
10 Component, ServerState,
11 error::{InternalServerError, MatrixApiError, ResultExt as _},
12};
13use arminius_lib_reqwest::setup_insecure_reqwest_client;
14use axum::{Json, Router, extract::State, routing::get};
15use reqwest::StatusCode;
16use ruma::api::error::ErrorKind;
17
18#[derive(MatrixApiError, thiserror::Error, Debug)]
20enum AuthMetadataError {
21 #[error(transparent)]
24 InternalServerError(#[from] InternalServerError),
25 #[matrix_api_error(status_code = StatusCode::NOT_FOUND, error_kind = ErrorKind::Unrecognized)]
29 #[error("Legacy authentication is in use on this homeserver.")]
30 NoAuthData,
31}
32
33async fn auth_metadata(
44 state: State<ServerState>,
45) -> Result<Json<serde_json::Map<String, serde_json::Value>>, AuthMetadataError> {
46 let Some(openid_configuration_url) = state.config.oidc_well_known.as_ref() else {
47 return Err(AuthMetadataError::NoAuthData);
48 };
49
50 let req = setup_insecure_reqwest_client(&state.config)
51 .unrecoverable_error("Could not set up Reqwest client. Invalid proxy setup?")?
52 .get(openid_configuration_url.clone());
53 let resp = req.send().await.unrecoverable_error("OIDC well known request failed")?;
54 let auth_metadata = resp.json().await.unrecoverable_error("OIDC well known response error")?;
55
56 Ok(Json(auth_metadata))
57}
58
59#[derive(Debug)]
61pub struct AuthComponent;
62
63impl Component for AuthComponent {
64 fn router() -> Router<ServerState> {
65 Router::new()
66 .route("/_matrix/client/v1/auth_metadata", get(auth_metadata))
67 .route("/_matrix/client/unstable/org.matrix.msc2965/auth_metadata", get(auth_metadata))
68 }
69}