Skip to content

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

feat(platform): JWT Authentication for Platform (#10988)

Ankit Kumar Gupta18a78369f71e
diff --git a/crates/router/src/services/authentication.rs b/crates/router/src/services/authentication.rs
index d16cf909d9..60facbc509 100644
--- a/crates/router/src/services/authentication.rs
+++ b/crates/router/src/services/authentication.rs
@@ -606,11 +606,17 @@ where
self.allow_platform_self_operation,
)?;
+ let initiator = Some(domain::Initiator::Api {
+ merchant_id: initiator_merchant.get_id().clone(),
+ merchant_account_type: initiator_merchant.merchant_account_type,
+ });
+
let platform = resolve_platform(
state,
request_headers,
initiator_merchant.clone(),
key_store,
+ initiator,
)
.await?;
@@ -703,11 +709,17 @@ where
self.allow_platform_self_operation,
)?;
+ let initiator = Some(domain::Initiator::Api {
+ merchant_id: initiator_merchant.get_id().clone(),
+ merchant_account_type: initiator_merchant.merchant_account_type,
+ });
+
let platform = resolve_platform(
state,
request_headers,
initiator_merchant.clone(),
key_store.clone(),
+ initiator,
)
.await?;
@@ -1339,7 +1351,19 @@ where
allow_platform_self_operation,
)?;
- let platform = resolve_platform(state, request_headers, initiator_merchant, key_store).await?;
+ let initiator = Some(domain::Initiator::Api {
+ merchant_id: initiator_merchant.get_id().clone(),
+ merchant_account_type: initiator_merchant.merchant_account_type,
+ });
+
+ let platform = resolve_platform(
+ state,
+ request_headers,
+ initiator_merchant,
+ key_store,
+ initiator,
+ )
+ .await?;
let profile = match profile_id {
Some(profile_id) => {
@@ -2766,11 +2790,17 @@ where
self.allow_platform_self_operation,
)?;
+ let initiator = Some(domain::Initiator::Api {
+ merchant_id: initiator_merchant.get_id().clone(),
+ merchant_account_type: initiator_merchant.merchant_account_type,
+ });
+
let platform = resolve_platform(
state,
request_headers,
initiator_merchant.clone(),
key_store,
+ initiator,
)
.await?;
@@ -2995,11 +3025,17 @@ where
self.allow_platform_self_operation,
)?;
+ let initiator = Some(domain::Initiator::Api {
+ merchant_id: initiator_merchant.get_id().clone(),
+ merchant_account_type: initiator_merchant.merchant_account_type,
+ });
+
let platform = resolve_platform(
state,
request_headers,
initiator_merchant.clone(),
key_store,
+ initiator,
)
.await?;
@@ -3049,11 +3085,17 @@ where
self.allow_platform_self_operation,
)?;
+ let initiator = Some(domain::Initiator::Api {
+ merchant_id: initiator_merchant.get_id().clone(),
+ merchant_account_type: initiator_merchant.merchant_account_type,
+ });
+
let platform = resolve_platform(
state,
request_headers,
initiator_merchant.clone(),
key_store,
+ initiator,
)
.await?;
@@ -3399,13 +3441,14 @@ where
user_id: payload.user_id.clone(),
});
- let platform = domain::Platform::new(
+ let platform = resolve_platform(
+ state,
+ request_headers,
merchant.clone(),
- key_store.clone(),
- merchant,
key_store,
initiator,
- );
+ )
+ .await?;
let auth = AuthenticationData {
platform,
@@ -3526,13 +3569,14 @@ where
user_id: payload.user_id.clone(),
});
- let platform = domain::Platform::new(
+ let platform = resolve_platform(
+ state,
+ request_headers,
merchant.clone(),
- key_store.clone(),
- merchant,
key_store,
initiator,
- );
+ )
+ .await?;
let auth = AuthenticationData { platform, profile };
@@ -3699,13 +3743,14 @@ where
user_id: payload.user_id.clone(),
});
- let platform = domain::Platform::new(
+ let platform = resolve_platform(
+ state,
+ request_headers,
merchant.clone(),
- key_store.clone(),
- merchant,
key_store,
initiator,
- );
+ )
+ .await?;
let auth = AuthenticationData {
platform,
@@ -3776,13 +3821,14 @@ where
user_id: payload.user_id.clone(),
});
- let platform = domain::Platform::new(
+ let platform = resolve_platform(
+ state,
+ request_headers,
merchant.clone(),
- key_store.clone(),
- merchant,
key_store,
initiator,
- );
+ )
+ .await?;
let auth = AuthenticationData { platform, profile };
Ok((
@@ -3918,13 +3964,14 @@ where
user_id: payload.user_id.clone(),
});
- let platform = domain::Platform::new(
+ let platform = resolve_platform(
+ state,
+ request_headers,
merchant.clone(),
- key_store.clone(),
- merchant,
key_store,
initiator,
- );
+ )
+ .await?;
let auth = AuthenticationData {
platform,
@@ -4006,13 +4053,14 @@ where
});
// If both of them are same then proceed with the profile id present in the request
- let platform = domain::Platform::new(
+ let platform = resolve_platform(
+ state,
+ request_headers,
merchant.clone(),
- key_store.clone(),
- merchant,
key_store,
initiator,
- );
+ )
+ .await?;
let auth = AuthenticationData {
platform,
@@ -4080,13 +4128,14 @@ where
user_id: payload.user_id.clone(),
});
- let platform = domain::Platform::new(
+ let platform = resolve_platform(
+ state,
+ request_headers,
merchant.clone(),
- key_store.clone(),
- merchant,
key_store,
initiator,
- );
+ )
+ .await?;
let auth = AuthenticationData { platform, profile };
Ok((
@@ -4182,13 +4231,15 @@ where
user_id: payload.user_id.clone(),
});
- let platform = domain::Platform::new(
+ let platform = resolve_platform(
+ state,
+ request_headers,
merchant.clone(),
- key_store.clone(),
- merchant,
key_store,
initiator,
- );
+ )
+ .await?;
+
let auth = AuthenticationData {
platform,
profile: Some(profile),
@@ -4248,6 +4299,7 @@ where
)
.await
.to_not_found_response(errors::ApiErrorResponse::Unauthorized)?;
+
let merchant = state
.store()
.find_merchant_account_by_merchant_id(&payload.merchant_id, &key_store)
@@ -4259,13 +4311,14 @@ where
user_id: payload.user_id.clone(),
});
- let platform = domain::Platform::new(
+ let platform = resolve_platform(
+ state,
+ request_headers,
merchant.clone(),
- key_store.clone(),
- merchant,
key_store,
initiator,
- );
+ )
+ .await?;
let auth = AuthenticationData { platform, profile };
Ok((
@@ -4333,13 +4386,14 @@ where
user_id: payload.user_id.clone(),
});
- let platform = domain::Platform::new(
+ let platform = resolve_platform(
+ state,
+ request_headers,
merchant.clone(),
- key_store.clone(),
- merchant,
key_store,
initiator,
- );
+ )
+ .await?;
let auth = AuthenticationData {
platform,
profile: Some(profile),
@@ -4486,13 +4540,14 @@ where
user_id: payload.user_id.clone(),
});
- let platform = domain::Platform::new(
+ let platform = resolve_platform(
+ state,
+ request_headers,
merchant.clone(),
- key_store.clone(),
- merchant,
key_store,
initiator,
- );
+ )
+ .await?;
let auth = AuthenticationData {
platform,
@@ -4586,13 +4641,14 @@ where
})
};
- let platform = domain::Platform::new(
+ let platform = resolve_platform(
+ state,
+ request_headers,
merchant.clone(),
- key_store.clone(),
- merchant,
key_store,
initiator,
- );
+ )
+ .await?;
let auth = AuthenticationData {
platform,
@@ -5269,6 +5325,7 @@ async fn resolve_platform<A>(
request_headers: &HeaderMap,
initiator_merchant_account: domain::MerchantAccount,
initiator_merchant_key_store: domain::MerchantKeyStore,
+ initiator: Option<domain::Initiator>,
) -> RouterResult<domain::Platform>
where
A: SessionStateInfo + Sync,
@@ -5360,11 +5417,6 @@ where
}
};
- let initiator = Some(domain::Initiator::Api {
- merchant_id: initiator_merchant_account.get_id().clone(),
- merchant_account_type: initiator_merchant_account.merchant_account_type,
- });
-
let platform = match platform_account_with_key_store {
Some(platform_account) => domain::Platform::new(
platform_account.account,