2026-04-14 19:14:27 -04:00
|
|
|
mod register_client;
|
|
|
|
|
mod server_metadata;
|
2026-04-30 08:54:55 -04:00
|
|
|
mod token;
|
2026-04-14 19:14:27 -04:00
|
|
|
|
|
|
|
|
use axum::{
|
|
|
|
|
Json, Router,
|
2026-04-30 10:49:03 -04:00
|
|
|
extract::State,
|
2026-04-14 19:14:27 -04:00
|
|
|
routing::method_routing::{get, post},
|
|
|
|
|
};
|
2026-04-30 11:32:30 -04:00
|
|
|
use const_str::concat;
|
2026-04-14 19:14:27 -04:00
|
|
|
use serde_json::json;
|
|
|
|
|
pub(crate) use server_metadata::*;
|
|
|
|
|
|
2026-04-30 11:32:30 -04:00
|
|
|
const BASE_PATH: &str = concat!(conduwuit_core::ROUTE_PREFIX, "/oauth2/");
|
|
|
|
|
const AUTH_CODE_PATH: &str = "grant/authorization_code";
|
|
|
|
|
const JWKS_URI_PATH: &str = "client/keys.json";
|
|
|
|
|
const CLIENT_REGISTER_PATH: &str = "client/register";
|
|
|
|
|
const TOKEN_REVOKE_PATH: &str = "client/revoke";
|
|
|
|
|
const TOKEN_PATH: &str = "grant/token";
|
2026-04-14 19:14:27 -04:00
|
|
|
|
|
|
|
|
pub(crate) fn router() -> Router<crate::State> {
|
2026-04-30 08:54:55 -04:00
|
|
|
Router::new().nest(BASE_PATH, oauth_router())
|
|
|
|
|
// TODO(unspecced): used by old versions of the matrix-js-sdk
|
2026-04-30 10:49:03 -04:00
|
|
|
.route("/.well-known/openid-configuration", get(
|
|
|
|
|
async |State(services): State<crate::State>| {
|
|
|
|
|
Json(authorization_server_metadata(&services).await)
|
|
|
|
|
}
|
|
|
|
|
))
|
2026-04-30 08:54:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn oauth_router() -> Router<crate::State> {
|
2026-04-14 19:14:27 -04:00
|
|
|
Router::new()
|
2026-04-30 11:32:30 -04:00
|
|
|
.route(concat!("/", CLIENT_REGISTER_PATH), post(register_client::register_client_route))
|
2026-04-30 08:54:55 -04:00
|
|
|
// TODO(unspecced): used by old versions of the matrix-js-sdk
|
2026-04-30 11:32:30 -04:00
|
|
|
.route(concat!("/", JWKS_URI_PATH), get(async || Json(json!({"keys": []}))))
|
|
|
|
|
.route(concat!("/", TOKEN_PATH), post(token::token_route))
|
|
|
|
|
.route(concat!("/", TOKEN_REVOKE_PATH), post(token::revoke_token_route))
|
2026-04-14 19:14:27 -04:00
|
|
|
}
|