Skip to content

Commit f88eee7

Browse files
feat(router): Add new JWT authentication variants and use them (#2835)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 0eb81f0 commit f88eee7

File tree

34 files changed

+3489
-67
lines changed

34 files changed

+3489
-67
lines changed

.typos.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ afe = "afe" # Commit id
4040
extend-exclude = [
4141
"config/redis.conf", # `typos` also checked "AKE" in the file, which is present as a quoted string
4242
"openapi/open_api_spec.yaml", # no longer updated
43+
"crates/router/src/utils/user/blocker_emails.txt", # this file contains various email domains
4344
]

Cargo.lock

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/api_models/src/events.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub mod payment;
55
pub mod payouts;
66
pub mod refund;
77
pub mod routing;
8+
pub mod user;
89

910
use common_utils::{
1011
events::{ApiEventMetric, ApiEventsType},

crates/api_models/src/events/user.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use common_utils::events::{ApiEventMetric, ApiEventsType};
2+
3+
use crate::user::{ConnectAccountRequest, ConnectAccountResponse};
4+
5+
impl ApiEventMetric for ConnectAccountResponse {
6+
fn get_api_event_type(&self) -> Option<ApiEventsType> {
7+
Some(ApiEventsType::User {
8+
merchant_id: self.merchant_id.clone(),
9+
user_id: self.user_id.clone(),
10+
})
11+
}
12+
}
13+
14+
impl ApiEventMetric for ConnectAccountRequest {}

crates/api_models/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ pub mod payments;
2121
pub mod payouts;
2222
pub mod refunds;
2323
pub mod routing;
24+
pub mod user;
2425
pub mod verifications;
2526
pub mod webhooks;

crates/api_models/src/user.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use common_utils::pii;
2+
use masking::Secret;
3+
4+
#[derive(serde::Deserialize, Debug, Clone, serde::Serialize)]
5+
pub struct ConnectAccountRequest {
6+
pub email: pii::Email,
7+
pub password: Secret<String>,
8+
}
9+
10+
#[derive(serde::Serialize, Debug, Clone)]
11+
pub struct ConnectAccountResponse {
12+
pub token: Secret<String>,
13+
pub merchant_id: String,
14+
pub name: Secret<String>,
15+
pub email: pii::Email,
16+
pub verification_days_left: Option<i64>,
17+
pub user_role: String,
18+
//this field is added for audit/debug reasons
19+
#[serde(skip_serializing)]
20+
pub user_id: String,
21+
}

crates/data_models/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ serde = { version = "1.0.163", features = ["derive"] }
2727
serde_json = "1.0.96"
2828
strum = { version = "0.25", features = [ "derive" ] }
2929
thiserror = "1.0.40"
30-
time = { version = "0.3.21", features = ["serde", "serde-well-known", "std"] }
30+
time = { version = "0.3.21", features = ["serde", "serde-well-known", "std"] }

crates/router/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ actix-cors = "0.6.4"
3838
actix-multipart = "0.6.0"
3939
actix-rt = "2.8.0"
4040
actix-web = "4.3.1"
41+
argon2 = { version = "0.5.0", features = ["std"] }
4142
async-bb8-diesel = "0.1.0"
4243
async-trait = "0.1.68"
4344
aws-config = { version = "0.55.3", optional = true }
@@ -89,10 +90,12 @@ thiserror = "1.0.40"
8990
time = { version = "0.3.21", features = ["serde", "serde-well-known", "std"] }
9091
tokio = { version = "1.28.2", features = ["macros", "rt-multi-thread"] }
9192
tera = "1.19.1"
93+
unicode-segmentation = "1.10.1"
9294
url = { version = "2.4.0", features = ["serde"] }
9395
utoipa = { version = "3.3.0", features = ["preserve_order", "time"] }
9496
utoipa-swagger-ui = { version = "3.1.3", features = ["actix-web"] }
9597
uuid = { version = "1.3.3", features = ["serde", "v4"] }
98+
validator = "0.16.0"
9699
openssl = "0.10.55"
97100
x509-parser = "0.15.0"
98101
sha-1 = { version = "0.9"}

crates/router/src/consts.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[cfg(feature = "olap")]
2+
pub mod user;
3+
14
// ID generation
25
pub(crate) const ID_LENGTH: usize = 20;
36
pub(crate) const MAX_ID_LENGTH: usize = 64;
@@ -52,3 +55,6 @@ pub const ROUTING_CONFIG_ID_LENGTH: usize = 10;
5255

5356
pub const LOCKER_REDIS_PREFIX: &str = "LOCKER_PM_TOKEN";
5457
pub const LOCKER_REDIS_EXPIRY_SECONDS: u32 = 60 * 15; // 15 minutes
58+
59+
#[cfg(any(feature = "olap", feature = "oltp"))]
60+
pub const JWT_TOKEN_TIME_IN_SECS: u64 = 60 * 60 * 24 * 2; // 2 days

crates/router/src/consts/user.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#[cfg(feature = "olap")]
2+
pub const MAX_NAME_LENGTH: usize = 70;
3+
#[cfg(feature = "olap")]
4+
pub const MAX_COMPANY_NAME_LENGTH: usize = 70;
5+
6+
// USER ROLES
7+
#[cfg(any(feature = "olap", feature = "oltp"))]
8+
pub const ROLE_ID_ORGANIZATION_ADMIN: &str = "org_admin";

0 commit comments

Comments
 (0)