Skip to content

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

fix(user_auth_method): make id option in auth select (#5213)

Apoorv Dixit5478f70e3e04
diff --git a/crates/api_models/src/user.rs b/crates/api_models/src/user.rs
index 66d4986129..43b476c9f6 100644
--- a/crates/api_models/src/user.rs
+++ b/crates/api_models/src/user.rs
@@ -377,5 +377,5 @@ pub struct AuthIdQueryParam {
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct AuthSelectRequest {
- pub id: String,
+ pub id: Option<String>,
}
diff --git a/crates/router/src/core/user.rs b/crates/router/src/core/user.rs
index 952b74f579..49993f3873 100644
--- a/crates/router/src/core/user.rs
+++ b/crates/router/src/core/user.rs
@@ -2306,21 +2306,38 @@ pub async fn terminate_auth_select(
.change_context(UserErrors::InternalServerError)?
.into();
- let user_authentication_method = state
- .store
- .get_user_authentication_method_by_id(&req.id)
- .await
- .to_not_found_response(UserErrors::InvalidUserAuthMethodOperation)?;
+ if let Some(id) = &req.id {
+ let user_authentication_method = state
+ .store
+ .get_user_authentication_method_by_id(id)
+ .await
+ .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?;
+ 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)
- && !utils::user::is_sso_auth_type(&user_authentication_method.auth_type)
- {
- next_flow = next_flow.skip(user_from_db, &state).await?;
+ // Skip SSO if continue with password(TOTP)
+ if next_flow.get_flow() == domain::UserFlow::SPTFlow(domain::SPTFlow::SSO)
+ && !utils::user::is_sso_auth_type(&user_authentication_method.auth_type)
+ {
+ next_flow = next_flow.skip(user_from_db, &state).await?;
+ }
+ let token = next_flow.get_token(&state).await?;
+
+ return auth::cookies::set_cookie_response(
+ user_api::TokenResponse {
+ token: token.clone(),
+ token_type: next_flow.get_flow().into(),
+ },
+ token,
+ );
}
+
+ // Giving totp token for hyperswtich users when no id is present in the request body
+ 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?;
+ next_flow = next_flow.skip(user_from_db, &state).await?;
let token = next_flow.get_token(&state).await?;
auth::cookies::set_cookie_response(