feat(users): Add force_two_factor_auth environment variable (#6466)

This commit is contained in:
Mani Chandra
2024-11-05 19:13:11 +05:30
committed by GitHub
parent 95f2e0b8c5
commit 6b66cccd02
10 changed files with 17 additions and 4 deletions

View File

@ -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)]

View File

@ -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,
}))
}