1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-11-20 12:02:22 +03:00

Tidy up upstream linking templates

This commit is contained in:
Quentin Gliech
2022-11-24 17:00:50 +01:00
parent fcb6190a56
commit 07636dd9e7
12 changed files with 155 additions and 35 deletions

View File

@@ -34,7 +34,10 @@ use mas_storage::{
},
LookupResultExt,
};
use mas_templates::{EmptyContext, TemplateContext, Templates, UpstreamExistingLinkContext};
use mas_templates::{
EmptyContext, TemplateContext, Templates, UpstreamExistingLinkContext, UpstreamRegister,
UpstreamSuggestLink,
};
use serde::Deserialize;
use sqlx::PgPool;
use thiserror::Error;
@@ -174,7 +177,7 @@ pub(crate) async fn get(
(Some(user_session), None) => {
// Session not linked, but user logged in: suggest linking account
let ctx = EmptyContext
let ctx = UpstreamSuggestLink::new(link.id)
.with_session(user_session)
.with_csrf(csrf_token.form_value());
@@ -193,7 +196,7 @@ pub(crate) async fn get(
(None, None) => {
// Session not linked and used not logged in: suggest creating an
// account or logging in an existing user
let ctx = EmptyContext.with_csrf(csrf_token.form_value());
let ctx = UpstreamRegister::new(link.id).with_csrf(csrf_token.form_value());
templates.render_upstream_oauth2_do_register(&ctx).await?
}

View File

@@ -48,10 +48,10 @@ pub(crate) async fn post(
txn.commit().await?;
let destination = if let Some(action) = form {
mas_router::Login::and_then(action)
action.go_next()
} else {
mas_router::Login::default()
mas_router::Login::default().go()
};
Ok((cookie_jar, destination.go()))
Ok((cookie_jar, destination))
}

View File

@@ -47,12 +47,27 @@ impl OptionalPostAuthAction {
let grant = Box::new(grant.into());
Ok(Some(PostAuthContext::ContinueAuthorizationGrant { grant }))
}
Some(PostAuthAction::ContinueCompatSsoLogin { data }) => {
let login = get_compat_sso_login_by_id(conn, *data).await?;
let login = Box::new(login.into());
Ok(Some(PostAuthContext::ContinueCompatSsoLogin { login }))
}
Some(PostAuthAction::ChangePassword) => Ok(Some(PostAuthContext::ChangePassword)),
Some(PostAuthAction::LinkUpstream { id }) => {
let (link, provider_id, _user_id) =
mas_storage::upstream_oauth2::lookup_link(&mut *conn, *id).await?;
let provider =
mas_storage::upstream_oauth2::lookup_provider(&mut *conn, provider_id).await?;
let provider = Box::new(provider);
let link = Box::new(link);
Ok(Some(PostAuthContext::LinkUpstream { provider, link }))
}
None => Ok(None),
}
}