Skip to content

Commit 4396ba1

Browse files
authored
Forward the login_hint upstream. (#4512)
2 parents ff4f0c8 + e3c7b80 commit 4396ba1

25 files changed

+155
-58
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1+
# Rust
12
target/
3+
4+
# Editors
5+
.idea
6+
.nova
7+
8+
# OS garbage
9+
.DS_Store

crates/cli/src/sync.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ pub async fn config_sync(
304304
.additional_authorization_parameters
305305
.into_iter()
306306
.collect(),
307+
forward_login_hint: provider.forward_login_hint,
307308
ui_order,
308309
},
309310
)

crates/config/src/sections/upstream_oauth2.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,4 +565,11 @@ pub struct Provider {
565565
/// Orders of the keys are not preserved.
566566
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
567567
pub additional_authorization_parameters: BTreeMap<String, String>,
568+
569+
/// Whether the `login_hint` should be forwarded to the provider in the
570+
/// authorization request.
571+
///
572+
/// Defaults to `false`.
573+
#[serde(default)]
574+
pub forward_login_hint: bool,
568575
}

crates/data-model/src/upstream_oauth2/provider.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ pub struct UpstreamOAuthProvider {
241241
pub disabled_at: Option<DateTime<Utc>>,
242242
pub claims_imports: ClaimsImports,
243243
pub additional_authorization_parameters: Vec<(String, String)>,
244+
pub forward_login_hint: bool,
244245
}
245246

246247
impl PartialOrd for UpstreamOAuthProvider {

crates/handlers/src/admin/v1/upstream_oauth_links/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ mod test_utils {
4747
userinfo_endpoint_override: None,
4848
jwks_uri_override: None,
4949
additional_authorization_parameters: Vec::new(),
50+
forward_login_hint: false,
5051
ui_order: 0,
5152
}
5253
}

crates/handlers/src/upstream_oauth2/authorize.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use hyper::StatusCode;
1212
use mas_axum_utils::{cookies::CookieJar, record_error};
1313
use mas_data_model::UpstreamOAuthProvider;
1414
use mas_oidc_client::requests::authorization_code::AuthorizationRequestData;
15-
use mas_router::UrlBuilder;
15+
use mas_router::{PostAuthAction, UrlBuilder};
1616
use mas_storage::{
1717
BoxClock, BoxRepository, BoxRng,
1818
upstream_oauth2::{UpstreamOAuthProviderRepository, UpstreamOAuthSessionRepository},
@@ -92,6 +92,21 @@ pub(crate) async fn get(
9292
data = data.with_response_mode(response_mode.into());
9393
}
9494

95+
// Forward the raw login hint upstream for the provider to handle however it
96+
// sees fit
97+
if provider.forward_login_hint {
98+
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);
106+
}
107+
}
108+
}
109+
95110
let data = if let Some(methods) = lazy_metadata.pkce_methods().await? {
96111
data.with_code_challenge_methods_supported(methods)
97112
} else {

crates/handlers/src/upstream_oauth2/cache.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ mod tests {
426426
disabled_at: None,
427427
claims_imports: UpstreamOAuthProviderClaimsImports::default(),
428428
additional_authorization_parameters: Vec::new(),
429+
forward_login_hint: false,
429430
};
430431

431432
// Without any override, it should just use discovery

crates/handlers/src/upstream_oauth2/link.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,7 @@ mod tests {
983983
pkce_mode: mas_data_model::UpstreamOAuthProviderPkceMode::Auto,
984984
response_mode: None,
985985
additional_authorization_parameters: Vec::new(),
986+
forward_login_hint: false,
986987
ui_order: 0,
987988
},
988989
)

crates/handlers/src/views/login.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ mod test {
498498
pkce_mode: mas_data_model::UpstreamOAuthProviderPkceMode::Auto,
499499
response_mode: None,
500500
additional_authorization_parameters: Vec::new(),
501+
forward_login_hint: false,
501502
ui_order: 0,
502503
},
503504
)
@@ -539,6 +540,7 @@ mod test {
539540
pkce_mode: mas_data_model::UpstreamOAuthProviderPkceMode::Auto,
540541
response_mode: None,
541542
additional_authorization_parameters: Vec::new(),
543+
forward_login_hint: false,
542544
ui_order: 1,
543545
},
544546
)

crates/storage-pg/.sqlx/query-585a1e78834c953c80a0af9215348b0f551b16f4cb57c022b50212cfc3d8431f.json

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)