Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(users): clear cookie and alter parsing for sso (#5147)
Apoorv Dixit6d9b37e8a2e9
diff --git a/crates/router/src/core/user.rs b/crates/router/src/core/user.rsindex 3e9145c2d3..ff1477aa3c 100644--- a/crates/router/src/core/user.rs+++ b/crates/router/src/core/user.rs@@ -4,7 +4,6 @@ use api_models::{payments::RedirectionResponse,user::{self as user_api, InviteMultipleUserResponse},};-use common_utils::ext_traits::ValueExt;#[cfg(feature = "email")]use diesel_models::user_role::UserRoleUpdate;use diesel_models::{@@ -481,7 +480,7 @@ pub async fn rotate_password(.await.map_err(|e| logger::error!(?e));- Ok(ApplicationResponse::StatusOk)+ auth::cookies::remove_cookie_response()}#[cfg(feature = "email")]@@ -544,7 +543,7 @@ pub async fn reset_password_token_only_flow(.await.map_err(|e| logger::error!(?e));- Ok(ApplicationResponse::StatusOk)+ auth::cookies::remove_cookie_response()}#[cfg(feature = "email")]@@ -597,7 +596,7 @@ pub async fn reset_password(.await.map_err(|e| logger::error!(?e));- Ok(ApplicationResponse::StatusOk)+ auth::cookies::remove_cookie_response()}pub async fn invite_multiple_user(@@ -2174,10 +2173,10 @@ pub async fn list_user_authentication_methods(.map(|auth_method| {let auth_name = match (auth_method.auth_type, auth_method.public_config) {(common_enums::UserAuthType::OpenIdConnect, Some(config)) => {- let open_id_public_config: user_api::OpenIdConnectPublicConfig = config- .parse_value("OpenIdConnectPublicConfig")- .change_context(UserErrors::InternalServerError)- .attach_printable("unable to parse generic data value")?;+ let open_id_public_config =+ serde_json::from_value::<user_api::OpenIdConnectPublicConfig>(config)+ .change_context(UserErrors::InternalServerError)+ .attach_printable("Unable to parse OpenIdConnectPublicConfig")?;Ok(Some(open_id_public_config.name))}@@ -2216,13 +2215,14 @@ pub async fn get_sso_auth_url(utils::user::decrypt_oidc_private_config(&state, user_authentication_method.private_config).await?;- let open_id_public_config: user_api::OpenIdConnectPublicConfig = user_authentication_method- .public_config- .ok_or(UserErrors::InternalServerError)- .attach_printable("Public config not present")?- .parse_value("OpenIdConnectPublicConfig")- .change_context(UserErrors::InternalServerError)- .attach_printable("unable to parse OpenIdConnectPublicConfig")?;+ let open_id_public_config = serde_json::from_value::<user_api::OpenIdConnectPublicConfig>(+ user_authentication_method+ .public_config+ .ok_or(UserErrors::InternalServerError)+ .attach_printable("Public config not present")?,+ )+ .change_context(UserErrors::InternalServerError)+ .attach_printable("Unable to parse OpenIdConnectPublicConfig")?;let oidc_state = Secret::new(nanoid::nanoid!());utils::user::set_sso_id_in_redis(&state, oidc_state.clone(), request.id).await?;@@ -2267,13 +2267,14 @@ pub async fn sso_sign(utils::user::decrypt_oidc_private_config(&state, user_authentication_method.private_config).await?;- let open_id_public_config: user_api::OpenIdConnectPublicConfig = user_authentication_method- .public_config- .ok_or(UserErrors::InternalServerError)- .attach_printable("Public config not present")?- .parse_value("OpenIdConnectPublicConfig")- .change_context(UserErrors::InternalServerError)- .attach_printable("unable to parse OpenIdConnectPublicConfig")?;+ let open_id_public_config = serde_json::from_value::<user_api::OpenIdConnectPublicConfig>(+ user_authentication_method+ .public_config+ .ok_or(UserErrors::InternalServerError)+ .attach_printable("Public config not present")?,+ )+ .change_context(UserErrors::InternalServerError)+ .attach_printable("Unable to parse OpenIdConnectPublicConfig")?;let redirect_url =utils::user::get_oidc_sso_redirect_url(&state, &open_id_public_config.name.to_string());@@ -2329,14 +2330,14 @@ pub async fn terminate_auth_select(.store.get_user_authentication_method_by_id(&req.id).await- .change_context(UserErrors::InternalServerError)?;+ .to_not_found_response(UserErrors::InvalidUserAuthMethodOperation)?;let current_flow = domain::CurrentFlow::new(user_token, domain::SPTFlow::AuthSelect.into())?;let mut next_flow = current_flow.next(user_from_db.clone(), &state).await?;// Skip SSO if continue with password(TOTP)if next_flow.get_flow() == domain::UserFlow::SPTFlow(domain::SPTFlow::SSO)- && user_authentication_method.auth_type != common_enums::UserAuthType::OpenIdConnect+ && !utils::user::is_sso_auth_type(&user_authentication_method.auth_type){next_flow = next_flow.skip(user_from_db, &state).await?;}diff --git a/crates/router/src/utils/user.rs b/crates/router/src/utils/user.rsindex 6b957281f7..e80fe8d1de 100644--- a/crates/router/src/utils/user.rs+++ b/crates/router/src/utils/user.rs@@ -1,7 +1,8 @@use std::{collections::HashMap, sync::Arc};use api_models::user as user_api;-use common_utils::{errors::CustomResult, ext_traits::ValueExt};+use common_enums::UserAuthType;+use common_utils::errors::CustomResult;use diesel_models::{encryption::Encryption, enums::UserStatus, user_role::UserRole};use error_stack::ResultExt;use masking::{ExposeInterface, Secret};@@ -206,7 +207,7 @@ pub fn get_redis_connection(state: &SessionState) -> UserResult<Arc<RedisConnect.attach_printable("Failed to get redis connection")}-impl ForeignFrom<user_api::AuthConfig> for common_enums::UserAuthType {+impl ForeignFrom<user_api::AuthConfig> for UserAuthType {fn foreign_from(from: user_api::AuthConfig) -> Self {match from {user_api::AuthConfig::OpenIdConnect { .. } => Self::OpenIdConnect,@@ -244,8 +245,7 @@ pub async fn decrypt_oidc_private_config(.into_inner().expose();- private_config- .parse_value("OpenIdConnectPrivateConfig")+ serde_json::from_value::<user_api::OpenIdConnectPrivateConfig>(private_config).change_context(UserErrors::InternalServerError).attach_printable("unable to parse OpenIdConnectPrivateConfig")}@@ -286,3 +286,10 @@ fn get_oidc_key(oidc_state: &str) -> String {pub fn get_oidc_sso_redirect_url(state: &SessionState, provider: &str) -> String {format!("{}/redirect/oidc/{}", state.conf.user.base_url, provider)}++pub fn is_sso_auth_type(auth_type: &UserAuthType) -> bool {+ match auth_type {+ UserAuthType::OpenIdConnect => true,+ UserAuthType::Password | UserAuthType::MagicLink => false,+ }+}