@@ -117,6 +117,20 @@ impl ConfigurationSection for UpstreamOAuth2Config {
117
117
}
118
118
}
119
119
}
120
+
121
+ if !provider. claims_imports . localpart . on_conflict . is_default ( )
122
+ && !matches ! (
123
+ provider. claims_imports. localpart. action,
124
+ ImportAction :: Force | ImportAction :: Require
125
+ )
126
+ {
127
+ return annotate ( figment:: Error :: custom (
128
+ "The field `action` must be either `force` or `require` when `on_conflict` is set to `add`" ,
129
+ ) ) ;
130
+ }
131
+
132
+ //TODO : check that claims imports use on_conflict where it is not
133
+ // supported?
120
134
}
121
135
122
136
Ok ( ( ) )
@@ -190,6 +204,26 @@ impl ImportAction {
190
204
}
191
205
}
192
206
207
+ /// How to handle an existing localpart claim
208
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Serialize , Deserialize , Default , JsonSchema ) ]
209
+ #[ serde( rename_all = "lowercase" ) ]
210
+ pub enum OnConflict {
211
+ /// Fails the sso login on conflict
212
+ #[ default]
213
+ Fail ,
214
+
215
+ /// Adds the oauth identity link, regardless of whether there is an existing
216
+ /// link or not
217
+ Add ,
218
+ }
219
+
220
+ impl OnConflict {
221
+ #[ allow( clippy:: trivially_copy_pass_by_ref) ]
222
+ const fn is_default ( & self ) -> bool {
223
+ matches ! ( self , OnConflict :: Fail )
224
+ }
225
+ }
226
+
193
227
/// What should be done for the subject attribute
194
228
#[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize , Default , JsonSchema ) ]
195
229
pub struct SubjectImportPreference {
@@ -218,6 +252,10 @@ pub struct LocalpartImportPreference {
218
252
/// If not provided, the default template is `{{ user.preferred_username }}`
219
253
#[ serde( default , skip_serializing_if = "Option::is_none" ) ]
220
254
pub template : Option < String > ,
255
+
256
+ /// How to handle conflicts on the claim, default value is `Fail`
257
+ #[ serde( default , skip_serializing_if = "OnConflict::is_default" ) ]
258
+ pub on_conflict : OnConflict ,
221
259
}
222
260
223
261
impl LocalpartImportPreference {
0 commit comments