Skip to main content

tuwunel_api_oidc/
routes.rs

1use axum::{
2	Router,
3	routing::{get, post},
4};
5use tuwunel_api::router::State;
6
7// Aliased to keep the subsystem visible where the sibling routes stay qualified.
8use crate::{
9	self as oidc, complete_route as oidc_complete, post_complete_route as oidc_post_complete,
10};
11
12/// Builds the OpenID Connect endpoint routes.
13///
14/// The returned router registers discovery, authorization and callback handlers.
15pub fn build() -> Router<State> {
16	let router = Router::new();
17
18	register_oidc_routes(router)
19}
20
21fn register_oidc_routes(router: Router<State>) -> Router<State> {
22	// OIDC server endpoints (next-gen auth, MSC2965/2964/2966/2967)
23	router
24		.route("/_tuwunel/oidc/registration", post(oidc::registration_route))
25		.route("/_tuwunel/oidc/authorize", get(oidc::authorize_route))
26		.route("/_tuwunel/oidc/_complete", get(oidc_complete).post(oidc_post_complete))
27		.route(
28			"/_tuwunel/oidc/native",
29			get(oidc::native_get_route).post(oidc::native_submit_route),
30		)
31		.route("/_tuwunel/oidc/token", post(oidc::token_route))
32		.route("/_tuwunel/oidc/device_authorization", post(oidc::device_authorization_route))
33		.route("/_tuwunel/oidc/device", get(oidc::get_device_route))
34		.route(
35			"/_tuwunel/oidc/device_callback",
36			get(oidc::get_device_callback_route).post(oidc::post_device_callback_route),
37		)
38		.route("/_tuwunel/oidc/revoke", post(oidc::revoke_route))
39		.route("/_tuwunel/oidc/jwks", get(oidc::jwks_route))
40		.route("/_tuwunel/oidc/userinfo", get(oidc::userinfo_route).post(oidc::userinfo_route))
41		.route("/_tuwunel/oidc/account.js", get(oidc::account_js_route))
42		.route("/_tuwunel/oidc/account.css", get(oidc::account_css_route))
43		.route(
44			"/_tuwunel/oidc/account_callback",
45			get(oidc::get_account_callback_route).post(oidc::post_account_callback_route),
46		)
47		.route("/_tuwunel/oidc/account", get(oidc::get_account_route))
48		.route("/_matrix/client/v1/auth_issuer", get(oidc::auth_issuer_route))
49		.route("/_matrix/client/v1/auth_metadata", get(oidc::openid_configuration_route))
50		.route(
51			"/_matrix/client/unstable/org.matrix.msc2965/auth_issuer",
52			get(oidc::auth_issuer_route),
53		)
54		.route(
55			"/_matrix/client/unstable/org.matrix.msc2965/auth_metadata",
56			get(oidc::openid_configuration_route),
57		)
58		.route("/.well-known/openid-configuration", get(oidc::openid_configuration_route))
59}