Skip to content

Commit ee4d130

Browse files
authored
Add more options to deal with localpart conflicts on upstream OAuth 2.0 logins (#5295)
2 parents 3a342b6 + 7bfeef9 commit ee4d130

File tree

7 files changed

+572
-24
lines changed

7 files changed

+572
-24
lines changed

crates/cli/src/sync.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ fn map_import_on_conflict(
4545
mas_config::UpstreamOAuth2OnConflict::Add => {
4646
mas_data_model::UpstreamOAuthProviderOnConflict::Add
4747
}
48+
mas_config::UpstreamOAuth2OnConflict::Replace => {
49+
mas_data_model::UpstreamOAuthProviderOnConflict::Replace
50+
}
51+
mas_config::UpstreamOAuth2OnConflict::Set => {
52+
mas_data_model::UpstreamOAuthProviderOnConflict::Set
53+
}
4854
mas_config::UpstreamOAuth2OnConflict::Fail => {
4955
mas_data_model::UpstreamOAuthProviderOnConflict::Fail
5056
}

crates/config/src/sections/upstream_oauth2.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ impl ConfigurationSection for UpstreamOAuth2Config {
120120

121121
if matches!(
122122
provider.claims_imports.localpart.on_conflict,
123-
OnConflict::Add
123+
OnConflict::Add | OnConflict::Replace | OnConflict::Set
124124
) && !matches!(
125125
provider.claims_imports.localpart.action,
126126
ImportAction::Force | ImportAction::Require
127127
) {
128128
return Err(annotate(figment::Error::custom(
129-
"The field `action` must be either `force` or `require` when `on_conflict` is set to `add`",
130-
)).into());
129+
"The field `action` must be either `force` or `require` when `on_conflict` is set to `add`, `replace` or `set`",
130+
)).with_path("claims_imports.localpart").into());
131131
}
132132
}
133133

@@ -206,13 +206,20 @@ impl ImportAction {
206206
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default, JsonSchema)]
207207
#[serde(rename_all = "lowercase")]
208208
pub enum OnConflict {
209-
/// Fails the sso login on conflict
209+
/// Fails the upstream OAuth 2.0 login on conflict
210210
#[default]
211211
Fail,
212212

213-
/// Adds the oauth identity link, regardless of whether there is an existing
214-
/// link or not
213+
/// Adds the upstream OAuth 2.0 identity link, regardless of whether there
214+
/// is an existing link or not
215215
Add,
216+
217+
/// Replace any existing upstream OAuth 2.0 identity link
218+
Replace,
219+
220+
/// Adds the upstream OAuth 2.0 identity link *only* if there is no existing
221+
/// link for this provider on the matching user
222+
Set,
216223
}
217224

218225
impl OnConflict {

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,11 +415,18 @@ impl ImportAction {
415415
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
416416
#[serde(rename_all = "lowercase")]
417417
pub enum OnConflict {
418-
/// Fails the upstream OAuth 2.0 login
418+
/// Fails the upstream OAuth 2.0 login on conflict
419419
#[default]
420420
Fail,
421421

422-
/// Adds the upstream account link, regardless of whether there is an
423-
/// existing link or not
422+
/// Adds the upstream OAuth 2.0 identity link, regardless of whether there
423+
/// is an existing link or not
424424
Add,
425+
426+
/// Replace any existing upstream OAuth 2.0 identity link
427+
Replace,
428+
429+
/// Adds the upstream OAuth 2.0 identity link *only* if there is no existing
430+
/// link for this provider on the matching user
431+
Set,
425432
}

0 commit comments

Comments
 (0)