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
refactor(user): move email token expiry to user config (#15336)
Mani Chandra1b03f94d9436
diff --git a/config/config.example.toml b/config/config.example.tomlindex 6db13d22e2..46fa021cec 100644--- a/config/config.example.toml+++ b/config/config.example.toml@@ -684,6 +684,7 @@ base_url = "" # Base url used for user specific redirectsforce_two_factor_auth = false # Whether to force two factor authentication for all usersforce_cookies = false # Whether to use only cookies for JWT extraction and authentication# idle_session_timeout_in_secs = 900 # When set, signs Dashboard users out after this many seconds without a request+email_token_expiry_in_secs = 86400 # Number of seconds for which email links (verify, reset password, invite, etc.) stay valid[oidc.key.k1]kid = "" # Key ID used to identify the signing key in JWKS and JWT headers (Generate using: openssl rand -hex 16)diff --git a/config/deployments/integration_test.toml b/config/deployments/integration_test.tomlindex 17aea7e2b1..cb1d8b063b 100644--- a/config/deployments/integration_test.toml+++ b/config/deployments/integration_test.toml@@ -246,6 +246,7 @@ slack_invite_url = "https://join.slack.com/t/hyperswitch-io/shared_invite/zt-2aw[user]password_validity_in_days = 90two_factor_auth_expiry_in_secs = 300+email_token_expiry_in_secs = 86400totp_issuer_name = "Hyperswitch Integ"base_url = "https://integ.hyperswitch.io"force_two_factor_auth = falsediff --git a/config/deployments/production.toml b/config/deployments/production.tomlindex ac1c2d9662..300dfb0f7d 100644--- a/config/deployments/production.toml+++ b/config/deployments/production.toml@@ -259,6 +259,7 @@ slack_invite_url = "https://join.slack.com/t/hyperswitch-io/shared_invite/zt-2aw[user]password_validity_in_days = 90two_factor_auth_expiry_in_secs = 300+email_token_expiry_in_secs = 86400totp_issuer_name = "Hyperswitch Production"base_url = "https://live.hyperswitch.io"force_two_factor_auth = truediff --git a/config/deployments/sandbox.toml b/config/deployments/sandbox.tomlindex c1cb0248b6..6c4528dc62 100644--- a/config/deployments/sandbox.toml+++ b/config/deployments/sandbox.toml@@ -255,6 +255,7 @@ slack_invite_url = "https://join.slack.com/t/hyperswitch-io/shared_invite/zt-2aw[user]password_validity_in_days = 90two_factor_auth_expiry_in_secs = 300+email_token_expiry_in_secs = 86400totp_issuer_name = "Hyperswitch Sandbox"base_url = "https://app.hyperswitch.io"force_two_factor_auth = falsediff --git a/config/development.toml b/config/development.tomlindex 36affdbb23..88ecbb7db7 100644--- a/config/development.toml+++ b/config/development.toml@@ -578,6 +578,7 @@ sts_role_session_name = ""[user]password_validity_in_days = 90two_factor_auth_expiry_in_secs = 300+email_token_expiry_in_secs = 86400totp_issuer_name = "Hyperswitch Dev"base_url = "http://localhost:8080"force_two_factor_auth = falsediff --git a/config/docker_compose.toml b/config/docker_compose.tomlindex 626e399d27..7b4707b3d1 100644--- a/config/docker_compose.toml+++ b/config/docker_compose.toml@@ -123,6 +123,7 @@ master_enc_key = "73ad7bbbbc640c845a150f67d058b279849370cd2c1f3c67c4dd6c869213e1[user]password_validity_in_days = 90two_factor_auth_expiry_in_secs = 300+email_token_expiry_in_secs = 86400totp_issuer_name = "Hyperswitch"base_url = "http://localhost:9000"force_two_factor_auth = falsediff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rsindex 02d83324fd..fe7b81730b 100644--- a/crates/router/src/configs/settings.rs+++ b/crates/router/src/configs/settings.rs@@ -1021,6 +1021,7 @@ pub struct UserSettings {pub force_two_factor_auth: bool,pub force_cookies: bool,pub idle_session_timeout_in_secs: Option<u32>,+ pub email_token_expiry_in_secs: u64,}#[derive(Debug, Clone, Default, Deserialize)]diff --git a/crates/router/src/consts.rs b/crates/router/src/consts.rsindex 4222f625cb..2306537d91 100644--- a/crates/router/src/consts.rs+++ b/crates/router/src/consts.rs@@ -77,9 +77,6 @@ pub const ROLE_BLACKLIST_PREFIX: &str = "BR_";pub const USER_IDLE_SESSION_PREFIX: &str = "IS_";pub const MIN_IDLE_SESSION_TIMEOUT_IN_SECS: u32 = 60;-#[cfg(feature = "email")]-pub const EMAIL_TOKEN_TIME_IN_SECS: u64 = 60 * 60 * 24; // 1 day-#[cfg(feature = "email")]pub const EMAIL_TOKEN_BLACKLIST_PREFIX: &str = "BET_";diff --git a/crates/router/src/services/authentication/blacklist.rs b/crates/router/src/services/authentication/blacklist.rsindex 8c936c2b33..3755110727 100644--- a/crates/router/src/services/authentication/blacklist.rs+++ b/crates/router/src/services/authentication/blacklist.rs@@ -7,7 +7,7 @@ use super::AuthToken;#[cfg(feature = "olap")]use super::{SinglePurposeOrLoginToken, SinglePurposeToken};#[cfg(feature = "email")]-use crate::consts::{EMAIL_TOKEN_BLACKLIST_PREFIX, EMAIL_TOKEN_TIME_IN_SECS};+use crate::consts::EMAIL_TOKEN_BLACKLIST_PREFIX;use crate::{consts::{JWT_TOKEN_TIME_IN_SECS, ROLE_BLACKLIST_PREFIX, USER_BLACKLIST_PREFIX},core::errors::{ApiErrorResponse, RouterResult},@@ -102,8 +102,8 @@ pub async fn insert_email_token_in_blacklist(state: &SessionState, token: &str)let redis_conn = get_redis_connection_for_global_tenant(state).change_context(UserErrors::InternalServerError)?;let blacklist_key = format!("{EMAIL_TOKEN_BLACKLIST_PREFIX}{token}");- let expiry =- expiry_to_i64(EMAIL_TOKEN_TIME_IN_SECS).change_context(UserErrors::InternalServerError)?;+ let expiry = expiry_to_i64(state.conf.user.email_token_expiry_in_secs)+ .change_context(UserErrors::InternalServerError)?;redis_conn.set_key_with_expiry(&blacklist_key.as_str().into(), true, expiry).awaitdiff --git a/crates/router/src/services/email/types.rs b/crates/router/src/services/email/types.rsindex 2953e0fa2c..e34eb3d989 100644--- a/crates/router/src/services/email/types.rs+++ b/crates/router/src/services/email/types.rs@@ -7,7 +7,7 @@ use error_stack::ResultExt;use external_services::email::{EmailContents, EmailData, EmailError};use hyperswitch_masking::{ExposeInterface, PeekInterface, Secret};-use crate::{configs, consts, routes::SessionState};+use crate::{configs, routes::SessionState};#[cfg(feature = "olap")]use crate::{core::errors::{UserErrors, UserResult},@@ -338,7 +338,8 @@ impl EmailToken {flow: domain::Origin,settings: &configs::Settings,) -> UserResult<String> {- let expiration_duration = std::time::Duration::from_secs(consts::EMAIL_TOKEN_TIME_IN_SECS);+ let expiration_duration =+ std::time::Duration::from_secs(settings.user.email_token_expiry_in_secs);let exp = jwt::generate_exp(expiration_duration)?.as_secs();let token_payload = Self {email: email.get_secret().expose(),