Implement SSO/OIDC support. (closes #7)

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk committed 2025-12-26 07:24:49 +00:00
1 parent d665a34f30
commit 11309062a2
23 files changed
+1959 -27

No files matched your search

+5
View File
@@ -1,6 +1,7 @@
use std::{fmt::Debug, mem, ops::Deref};
use axum::{body::Body, extract::FromRequest};
use axum_extra::extract::cookie::CookieJar;
use bytes::{BufMut, Bytes, BytesMut};
use ruma::{
CanonicalJsonObject, CanonicalJsonValue, DeviceId, OwnedDeviceId, OwnedServerName,
@@ -18,6 +19,9 @@ pub(crate) struct Args<T> {
/// Request struct body
pub(crate) body: T,
/// Cookies received from the useragent.
pub(crate) cookie: CookieJar,
/// Federation server authentication: X-Matrix origin
/// None when not a federation server.
pub(crate) origin: Option<OwnedServerName>,
@@ -110,6 +114,7 @@ where
let auth = auth::auth(services, &mut request, json_body.as_ref(), &T::METADATA).await?;
Ok(Self {
body: make_body::<T>(services, &mut request, json_body.as_mut(), &auth)?,
cookie: request.cookie,
origin: auth.origin,
sender_user: auth.sender_user,
sender_device: auth.sender_device,
+12 -2
View File
@@ -5,7 +5,7 @@ use ruma::{
client::uiaa::{AuthData, AuthFlow, AuthType, Jwt, UiaaInfo},
},
};
use tuwunel_core::{Err, Error, Result, err, utils};
use tuwunel_core::{Err, Error, Result, err, is_equal_to, utils};
use tuwunel_service::{Services, uiaa::SESSION_ID_LENGTH};
use crate::{Ruma, client::jwt};
@@ -67,9 +67,19 @@ where
| Some(ref json) => {
let sender_user = body
.sender_user
.as_ref()
.as_deref()
.ok_or_else(|| err!(Request(MissingToken("Missing access token."))))?;
// Skip UIAA for SSO/OIDC users.
if services
.users
.origin(sender_user)
.await
.is_ok_and(is_equal_to!("sso"))
{
return Ok(sender_user.to_owned());
}
uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH));
services
.uiaa
+4 -1
View File
@@ -1,6 +1,7 @@
use std::str;
use axum::{RequestExt, RequestPartsExt, extract::Path};
use axum_extra::extract::cookie::CookieJar;
use bytes::Bytes;
use http::request::Parts;
use serde::Deserialize;
@@ -17,6 +18,7 @@ pub(super) type UserId = SmallString<[u8; 48]>;
#[derive(Debug)]
pub(super) struct Request {
pub(super) cookie: CookieJar,
pub(super) path: Path<PathParams>,
pub(super) query: QueryParams,
pub(super) body: Bytes,
@@ -33,6 +35,7 @@ pub(super) async fn from(
let limited = request.with_limited_body();
let (mut parts, body) = limited.into_parts();
let cookie: CookieJar = parts.extract().await?;
let path: Path<PathParams> = parts.extract().await?;
let query = parts.uri.query().unwrap_or_default();
let query = serde_html_form::from_str(query)
@@ -44,5 +47,5 @@ pub(super) async fn from(
.await
.map_err(|e| err!(Request(TooLarge("Request body too large: {e}"))))?;
Ok(Request { path, query, body, parts })
Ok(Request { cookie, path, query, body, parts })
}