mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 12:06:56 +08:00
feat(users): Add force_two_factor_auth environment variable (#6466)
This commit is contained in:
@ -556,6 +556,7 @@ pub struct UserSettings {
|
||||
pub two_factor_auth_expiry_in_secs: i64,
|
||||
pub totp_issuer_name: String,
|
||||
pub base_url: String,
|
||||
pub force_two_factor_auth: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
|
||||
@ -1319,7 +1319,7 @@ pub async fn list_user_roles_details(
|
||||
))
|
||||
.await
|
||||
.change_context(UserErrors::InternalServerError)
|
||||
.attach_printable("Failed to construct proifle map")?
|
||||
.attach_printable("Failed to construct profile map")?
|
||||
.into_iter()
|
||||
.map(|profile| (profile.get_id().to_owned(), profile.profile_name))
|
||||
.collect::<HashMap<_, _>>();
|
||||
@ -1927,7 +1927,7 @@ pub async fn terminate_two_factor_auth(
|
||||
.change_context(UserErrors::InternalServerError)?
|
||||
.into();
|
||||
|
||||
if !skip_two_factor_auth {
|
||||
if state.conf.user.force_two_factor_auth || !skip_two_factor_auth {
|
||||
if !tfa_utils::check_totp_in_redis(&state, &user_token.user_id).await?
|
||||
&& !tfa_utils::check_recovery_code_in_redis(&state, &user_token.user_id).await?
|
||||
{
|
||||
@ -1997,9 +1997,12 @@ pub async fn check_two_factor_auth_status_with_attempts(
|
||||
.await
|
||||
.change_context(UserErrors::InternalServerError)?
|
||||
.into();
|
||||
|
||||
let is_skippable = state.conf.user.force_two_factor_auth.not();
|
||||
if user_from_db.get_totp_status() == TotpStatus::NotSet {
|
||||
return Ok(ApplicationResponse::Json(user_api::TwoFactorStatus {
|
||||
status: None,
|
||||
is_skippable,
|
||||
}));
|
||||
};
|
||||
|
||||
@ -2018,6 +2021,7 @@ pub async fn check_two_factor_auth_status_with_attempts(
|
||||
totp,
|
||||
recovery_code,
|
||||
}),
|
||||
is_skippable,
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user