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(configs): allow config retrieve API to be called with internal API key or admin API key (#12885)
Sanchith Hegde6298e9fad603
diff --git a/crates/router/src/routes/configs.rs b/crates/router/src/routes/configs.rsindex 1425fda32b..393a797a52 100644--- a/crates/router/src/routes/configs.rs+++ b/crates/router/src/routes/configs.rs@@ -48,7 +48,7 @@ pub async fn config_key_retrieve(&req,&key,|state, _, key, _| configs::read_config(state, key),- &ADMIN_API_AUTH,+ &auth::InternalApiKeyAuth(ADMIN_API_AUTH),api_locking::LockAction::NotApplicable,).awaitdiff --git a/crates/router/src/services/authentication.rs b/crates/router/src/services/authentication.rsindex 9b1998fcc5..135cbeafae 100644--- a/crates/router/src/services/authentication.rs+++ b/crates/router/src/services/authentication.rs@@ -201,6 +201,7 @@ pub enum AuthenticationType {merchant_id: id_type::MerchantId,profile_id: id_type::ProfileId,},+ InternalApiKey,NoAuth,}@@ -235,6 +236,7 @@ impl AuthenticationType {| Self::EmbeddedJwt { merchant_id, .. }| Self::SdkAuthorization { merchant_id, .. } => Some(merchant_id),Self::AdminApiKey+ | Self::InternalApiKey| Self::OrganizationJwt { .. }| Self::BasicAuth { .. }| Self::UserJwt { .. }@@ -2765,6 +2767,47 @@ where}}+pub struct InternalApiKeyAuth<F>(pub F);++#[async_trait]+impl<A, F> AuthenticateAndFetch<(), A> for InternalApiKeyAuth<F>+where+ A: SessionStateInfo + Sync + Send,+ F: AuthenticateAndFetch<(), A> + Sync + Send,+{+ async fn authenticate_and_fetch(+ &self,+ request_headers: &HeaderMap,+ state: &A,+ ) -> RouterResult<((), AuthenticationType)> {+ if !state.conf().internal_merchant_id_profile_id_auth.enabled {+ return self.0.authenticate_and_fetch(request_headers, state).await;+ }++ let internal_api_key = HeaderMapStruct::new(request_headers)+ .get_header_value_by_key(headers::X_INTERNAL_API_KEY)+ .map(|s| s.to_string());++ match internal_api_key {+ Some(key) => {+ if key+ == *state+ .conf()+ .internal_merchant_id_profile_id_auth+ .internal_api_key+ .peek()+ {+ Ok(((), AuthenticationType::InternalApiKey))+ } else {+ Err(errors::ApiErrorResponse::Unauthorized)+ .attach_printable("Internal API key authentication failed")+ }+ }+ None => self.0.authenticate_and_fetch(request_headers, state).await,+ }+ }+}+#[derive(Debug)]#[cfg(feature = "v2")]pub struct MerchantIdAndProfileIdAuth {