diff --git a/src/config.rs b/src/config.rs index 6b31566..a1f7737 100644 --- a/src/config.rs +++ b/src/config.rs @@ -149,6 +149,8 @@ pub enum FeatureFlag { DryRun, /// If only deactivated users should be synced DeactivateOnly, + /// Use plain localpart + PlainLocalpart, } #[derive(Debug, Clone, Deserialize, PartialEq, Default)] @@ -356,7 +358,10 @@ mod tests { let file_path = create_config_file(tempdir.path()); let env_var_name = format!("{ENV_VAR_CONFIG_PREFIX}__FEATURE_FLAGS"); - env::set_var(&env_var_name, "sso_login verify_email verify_phone dry_run deactivate_only"); + env::set_var( + &env_var_name, + "sso_login verify_email verify_phone dry_run deactivate_only plain_localpart", + ); let loaded_config = Config::new(file_path.as_path()).expect("Failed to create config object"); @@ -367,6 +372,7 @@ mod tests { sample_config.feature_flags.push(FeatureFlag::VerifyPhone); sample_config.feature_flags.push(FeatureFlag::DryRun); sample_config.feature_flags.push(FeatureFlag::DeactivateOnly); + sample_config.feature_flags.push(FeatureFlag::PlainLocalpart); env::remove_var(env_var_name); diff --git a/src/zitadel.rs b/src/zitadel.rs index 5761a06..a7d2406 100644 --- a/src/zitadel.rs +++ b/src/zitadel.rs @@ -408,6 +408,27 @@ impl Zitadel { return Ok(()); } + let id = match &user.user_data.external_user_id { + StringOrBytes::String(value) => value.as_bytes(), + StringOrBytes::Bytes(value) => value, + }; + + let uuid; + let localpart = if self.feature_flags.contains(&FeatureFlag::PlainLocalpart) { + match &user.user_data.external_user_id { + StringOrBytes::String(value) => value, + StringOrBytes::Bytes(_) => { + bail!( + "Unsupported binary external ID for user using plain localparts: {:?}", + user + ); + } + } + } else { + uuid = Uuid::new_v5(&FAMEDLY_NAMESPACE, id).to_string(); + &uuid + }; + let new_user_id = self .zitadel_client .create_human_user(&self.zitadel_config.organization_id, user.clone().into()) @@ -422,17 +443,12 @@ impl Zitadel { ) .await?; - let id = match &user.user_data.external_user_id { - StringOrBytes::String(value) => value.as_bytes(), - StringOrBytes::Bytes(value) => value, - }; - self.zitadel_client .set_user_metadata( Some(&self.zitadel_config.organization_id), new_user_id.clone(), "localpart".to_owned(), - &Uuid::new_v5(&FAMEDLY_NAMESPACE, id).to_string(), + localpart, ) .await?;