Skip to content

Commit 096ce60

Browse files
committed
Add a configuration for forwarding the login hint to the upstream provider.
1 parent 691c055 commit 096ce60

21 files changed

+135
-60
lines changed

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/upstream_oauth2/authorize.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,16 @@ pub(crate) async fn get(
9494

9595
// Forward the raw login hint upstream for the provider to handle however it
9696
// sees fit
97-
if let Some(PostAuthAction::ContinueAuthorizationGrant { id }) = &query.post_auth_action {
98-
if let Some(grant) = repo.oauth2_authorization_grant().lookup(*id).await? {
99-
data.login_hint = grant.login_hint;
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+
}
100107
}
101108
}
102109

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.

crates/storage-pg/.sqlx/query-72de26d5e3c56f4b0658685a95b45b647bb6637e55b662a5a548aa3308c62a8a.json

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)