Skip to content

Commit 0770693

Browse files
committed
remove prefix when forwarding the login_hint
1 parent 46eb75f commit 0770693

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

crates/handlers/src/upstream_oauth2/authorize.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
// SPDX-License-Identifier: AGPL-3.0-only
55
// Please see LICENSE in the repository root for full details.
66

7+
use std::sync::Arc;
8+
79
use axum::{
810
extract::{Path, Query, State},
911
response::{IntoResponse, Redirect},
1012
};
1113
use hyper::StatusCode;
1214
use mas_axum_utils::{cookies::CookieJar, record_error};
13-
use mas_data_model::UpstreamOAuthProvider;
15+
use mas_data_model::{UpstreamOAuthProvider, oauth2::LoginHint};
16+
use mas_matrix::HomeserverConnection;
1417
use mas_oidc_client::requests::authorization_code::AuthorizationRequestData;
1518
use mas_router::{PostAuthAction, UrlBuilder};
1619
use mas_storage::{
@@ -66,6 +69,7 @@ pub(crate) async fn get(
6669
cookie_jar: CookieJar,
6770
Path(provider_id): Path<Ulid>,
6871
Query(query): Query<OptionalPostAuthAction>,
72+
State(homeserver): State<Arc<dyn HomeserverConnection>>,
6973
) -> Result<impl IntoResponse, RouteError> {
7074
let provider = repo
7175
.upstream_oauth_provider()
@@ -96,13 +100,11 @@ pub(crate) async fn get(
96100
// sees fit
97101
if provider.forward_login_hint {
98102
if let Some(PostAuthAction::ContinueAuthorizationGrant { id }) = &query.post_auth_action {
99-
if let Some(login_hint) = repo
100-
.oauth2_authorization_grant()
101-
.lookup(*id)
102-
.await?
103-
.and_then(|grant| grant.login_hint)
104-
{
105-
data = data.with_login_hint(login_hint);
103+
if let Some(grant) = repo.oauth2_authorization_grant().lookup(*id).await? {
104+
match grant.parse_login_hint(homeserver.homeserver()) {
105+
LoginHint::MXID(mxid) => data = data.with_login_hint(mxid.to_string()),
106+
LoginHint::None => (),
107+
}
106108
}
107109
}
108110
}

0 commit comments

Comments
 (0)