mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 13:30:39 +08:00
refactor(user_auth_method): populate default user auth method (#5257)
This commit is contained in:
@ -27,6 +27,7 @@ use super::errors::{StorageErrorExt, UserErrors, UserResponse, UserResult};
|
|||||||
use crate::services::email::types as email_types;
|
use crate::services::email::types as email_types;
|
||||||
use crate::{
|
use crate::{
|
||||||
consts,
|
consts,
|
||||||
|
db::domain::user_authentication_method::DEFAULT_USER_AUTH_METHOD,
|
||||||
routes::{app::ReqState, SessionState},
|
routes::{app::ReqState, SessionState},
|
||||||
services::{authentication as auth, authorization::roles, openidconnect, ApplicationResponse},
|
services::{authentication as auth, authorization::roles, openidconnect, ApplicationResponse},
|
||||||
types::{domain, transformers::ForeignInto},
|
types::{domain, transformers::ForeignInto},
|
||||||
@ -2306,38 +2307,25 @@ pub async fn terminate_auth_select(
|
|||||||
.change_context(UserErrors::InternalServerError)?
|
.change_context(UserErrors::InternalServerError)?
|
||||||
.into();
|
.into();
|
||||||
|
|
||||||
if let Some(id) = &req.id {
|
let user_authentication_method = if let Some(id) = &req.id {
|
||||||
let user_authentication_method = state
|
state
|
||||||
.store
|
.store
|
||||||
.get_user_authentication_method_by_id(id)
|
.get_user_authentication_method_by_id(id)
|
||||||
.await
|
.await
|
||||||
.to_not_found_response(UserErrors::InvalidUserAuthMethodOperation)?;
|
.to_not_found_response(UserErrors::InvalidUserAuthMethodOperation)?
|
||||||
|
} else {
|
||||||
|
DEFAULT_USER_AUTH_METHOD.clone()
|
||||||
|
};
|
||||||
|
|
||||||
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?;
|
|
||||||
}
|
|
||||||
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 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 mut next_flow = current_flow.next(user_from_db.clone(), &state).await?;
|
||||||
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?;
|
let token = next_flow.get_token(&state).await?;
|
||||||
|
|
||||||
auth::cookies::set_cookie_response(
|
auth::cookies::set_cookie_response(
|
||||||
|
|||||||
@ -37,6 +37,7 @@ use crate::{
|
|||||||
pub mod dashboard_metadata;
|
pub mod dashboard_metadata;
|
||||||
pub mod decision_manager;
|
pub mod decision_manager;
|
||||||
pub use decision_manager::*;
|
pub use decision_manager::*;
|
||||||
|
pub mod user_authentication_method;
|
||||||
|
|
||||||
use super::{types as domain_types, UserKeyStore};
|
use super::{types as domain_types, UserKeyStore};
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,17 @@
|
|||||||
|
use common_enums::{Owner, UserAuthType};
|
||||||
|
use diesel_models::UserAuthenticationMethod;
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
|
pub static DEFAULT_USER_AUTH_METHOD: Lazy<UserAuthenticationMethod> =
|
||||||
|
Lazy::new(|| UserAuthenticationMethod {
|
||||||
|
id: String::from("hyperswitch_default"),
|
||||||
|
auth_id: String::from("hyperswitch"),
|
||||||
|
owner_id: String::from("hyperswitch"),
|
||||||
|
owner_type: Owner::Tenant,
|
||||||
|
auth_type: UserAuthType::Password,
|
||||||
|
private_config: None,
|
||||||
|
public_config: None,
|
||||||
|
allow_signup: true,
|
||||||
|
created_at: common_utils::date_time::now(),
|
||||||
|
last_modified_at: common_utils::date_time::now(),
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user