1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-29 22:01:14 +03:00

Legacy login via m.login.sso

This commit is contained in:
Quentin Gliech
2022-05-19 17:00:26 +02:00
parent 57e16e217d
commit 033d60eb73
18 changed files with 1165 additions and 164 deletions

View File

@ -23,6 +23,10 @@ pub enum PostAuthAction {
#[serde(deserialize_with = "serde_with::rust::display_fromstr::deserialize")]
data: i64,
},
ContinueCompatSsoLogin {
#[serde(deserialize_with = "serde_with::rust::display_fromstr::deserialize")]
data: i64,
},
ChangePassword,
}
@ -32,10 +36,16 @@ impl PostAuthAction {
PostAuthAction::ContinueAuthorizationGrant { data }
}
#[must_use]
pub fn continue_compat_sso_login(data: i64) -> Self {
PostAuthAction::ContinueCompatSsoLogin { data }
}
#[must_use]
pub fn go_next(&self) -> axum::response::Redirect {
match self {
Self::ContinueAuthorizationGrant { data } => ContinueAuthorizationGrant(*data).go(),
Self::ContinueCompatSsoLogin { data } => CompatLoginSsoComplete(*data).go(),
Self::ChangePassword => AccountPassword.go(),
}
}
@ -161,6 +171,13 @@ impl Login {
}
}
#[must_use]
pub fn and_continue_compat_sso_login(data: i64) -> Self {
Self {
post_auth_action: Some(PostAuthAction::continue_compat_sso_login(data)),
}
}
/// Get a reference to the login's post auth action.
#[must_use]
pub fn post_auth_action(&self) -> Option<&PostAuthAction> {
@ -387,3 +404,31 @@ pub struct CompatRefresh;
impl SimpleRoute for CompatRefresh {
const PATH: &'static str = "/_matrix/client/:version/refresh";
}
/// `POST /_matrix/client/v3/login/sso/redirect`
pub struct CompatLoginSsoRedirect;
impl SimpleRoute for CompatLoginSsoRedirect {
const PATH: &'static str = "/_matrix/client/:version/login/sso/redirect";
}
/// `POST /_matrix/client/v3/login/sso/redirect/:idp`
pub struct CompatLoginSsoRedirectIdp;
impl SimpleRoute for CompatLoginSsoRedirectIdp {
const PATH: &'static str = "/_matrix/client/:version/login/sso/redirect/:idp";
}
/// `GET|POST /complete-compat-sso/:id`
pub struct CompatLoginSsoComplete(pub i64);
impl Route for CompatLoginSsoComplete {
type Query = ();
fn route() -> &'static str {
"/complete-compat-sso/:grant_id"
}
fn path(&self) -> std::borrow::Cow<'static, str> {
format!("/complete-compat-sso/{}", self.0).into()
}
}

View File

@ -46,6 +46,10 @@ pub trait Route {
fn go(&self) -> axum::response::Redirect {
axum::response::Redirect::to(&self.relative_url())
}
fn go_absolute(&self, base: &Url) -> axum::response::Redirect {
axum::response::Redirect::to(self.absolute_url(base).as_str())
}
}
pub trait SimpleRoute {

View File

@ -31,6 +31,13 @@ impl UrlBuilder {
destination.absolute_url(&self.base)
}
pub fn absolute_redirect<U>(&self, destination: &U) -> axum::response::Redirect
where
U: Route,
{
destination.go_absolute(&self.base)
}
/// Create a new [`UrlBuilder`] from a base URL
#[must_use]
pub fn new(base: Url) -> Self {