From dc76bbca02892a2db235d002704a229866d5dc67 Mon Sep 17 00:00:00 2001 From: mcalinghee Date: Thu, 15 May 2025 17:36:36 +0200 Subject: [PATCH] remove prefix when forwarding the login_hint --- .../handlers/src/upstream_oauth2/authorize.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/crates/handlers/src/upstream_oauth2/authorize.rs b/crates/handlers/src/upstream_oauth2/authorize.rs index 43403c137..11ec9cea1 100644 --- a/crates/handlers/src/upstream_oauth2/authorize.rs +++ b/crates/handlers/src/upstream_oauth2/authorize.rs @@ -4,13 +4,16 @@ // SPDX-License-Identifier: AGPL-3.0-only // Please see LICENSE in the repository root for full details. +use std::sync::Arc; + use axum::{ extract::{Path, Query, State}, response::{IntoResponse, Redirect}, }; use hyper::StatusCode; use mas_axum_utils::{cookies::CookieJar, record_error}; -use mas_data_model::UpstreamOAuthProvider; +use mas_data_model::{UpstreamOAuthProvider, oauth2::LoginHint}; +use mas_matrix::HomeserverConnection; use mas_oidc_client::requests::authorization_code::AuthorizationRequestData; use mas_router::{PostAuthAction, UrlBuilder}; use mas_storage::{ @@ -66,6 +69,7 @@ pub(crate) async fn get( cookie_jar: CookieJar, Path(provider_id): Path, Query(query): Query, + State(homeserver): State>, ) -> Result { let provider = repo .upstream_oauth_provider() @@ -96,13 +100,11 @@ pub(crate) async fn get( // sees fit if provider.forward_login_hint { if let Some(PostAuthAction::ContinueAuthorizationGrant { id }) = &query.post_auth_action { - if let Some(login_hint) = repo - .oauth2_authorization_grant() - .lookup(*id) - .await? - .and_then(|grant| grant.login_hint) - { - data = data.with_login_hint(login_hint); + if let Some(grant) = repo.oauth2_authorization_grant().lookup(*id).await? { + match grant.parse_login_hint(homeserver.homeserver()) { + LoginHint::MXID(mxid) => data = data.with_login_hint(mxid.to_string()), + LoginHint::None => (), + } } } }