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
feat(platform): Support dual authentication for SDK - enhanced SDK authorization and publishable key with client secret (#11187)
Sandeep Kumar6b38eb74757e
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.jsonindex 8cb7649be9..068dd5797f 100644--- a/api-reference/v1/openapi_spec_v1.json+++ b/api-reference/v1/openapi_spec_v1.json@@ -27491,9 +27491,6 @@},"PaymentsCompleteAuthorizeRequest": {"type": "object",- "required": [- "client_secret"- ],"properties": {"shipping": {"allOf": [@@ -27505,7 +27502,8 @@},"client_secret": {"type": "string",- "description": "Client Secret"+ "description": "Client Secret",+ "nullable": true},"threeds_method_comp_ind": {"allOf": [@@ -29273,7 +29271,6 @@"type": "object","required": ["shipping",- "client_secret","payment_method_type"],"properties": {@@ -29282,7 +29279,8 @@},"client_secret": {"type": "string",- "description": "Client Secret"+ "description": "Client Secret",+ "nullable": true},"payment_method_type": {"$ref": "#/components/schemas/PaymentMethodType"@@ -29386,14 +29384,14 @@"PaymentsExternalAuthenticationRequest": {"type": "object","required": [- "client_secret","device_channel","threeds_method_comp_ind"],"properties": {"client_secret": {"type": "string",- "description": "Client Secret"+ "description": "Client Secret",+ "nullable": true},"sdk_information": {"allOf": [@@ -29494,14 +29492,14 @@"PaymentsPostSessionTokensRequest": {"type": "object","required": [- "client_secret","payment_method_type","payment_method"],"properties": {"client_secret": {"type": "string",- "description": "It's a token used for client side verification."+ "description": "It's a token used for client side verification.",+ "nullable": true},"payment_method_type": {"$ref": "#/components/schemas/PaymentMethodType"@@ -30952,7 +30950,6 @@"type": "object","required": ["payment_id",- "client_secret","wallets"],"properties": {@@ -30962,7 +30959,8 @@},"client_secret": {"type": "string",- "description": "This is a token which expires after 15 minutes, used from the client to authenticate and create sessions from the SDK"+ "description": "This is a token which expires after 15 minutes, used from the client to authenticate and create sessions from the SDK",+ "nullable": true},"wallets": {"type": "array",diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.jsonindex 0c1d9448b5..ba6d6cab5c 100644--- a/api-reference/v2/openapi_spec_v2.json+++ b/api-reference/v2/openapi_spec_v2.json@@ -22017,9 +22017,6 @@},"PaymentsCompleteAuthorizeRequest": {"type": "object",- "required": [- "client_secret"- ],"properties": {"shipping": {"allOf": [@@ -22031,7 +22028,8 @@},"client_secret": {"type": "string",- "description": "Client Secret"+ "description": "Client Secret",+ "nullable": true},"threeds_method_comp_ind": {"allOf": [@@ -22346,7 +22344,6 @@"type": "object","required": ["shipping",- "client_secret","payment_method_type"],"properties": {@@ -22355,7 +22352,8 @@},"client_secret": {"type": "string",- "description": "Client Secret"+ "description": "Client Secret",+ "nullable": true},"payment_method_type": {"$ref": "#/components/schemas/PaymentMethodType"@@ -22406,14 +22404,14 @@"PaymentsExternalAuthenticationRequest": {"type": "object","required": [- "client_secret","device_channel","threeds_method_comp_ind"],"properties": {"client_secret": {"type": "string",- "description": "Client Secret"+ "description": "Client Secret",+ "nullable": true},"sdk_information": {"allOf": [diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rsindex 75aeedaf0c..2fb3974134 100644--- a/crates/api_models/src/payments.rs+++ b/crates/api_models/src/payments.rs@@ -9110,18 +9110,6 @@ impl From<&VerifyRequest> for MandateValidationFields {// }// }-#[cfg(feature = "v1")]-impl From<PaymentsSessionRequest> for PaymentsSessionResponse {- fn from(item: PaymentsSessionRequest) -> Self {- let client_secret: Secret<String, pii::ClientSecret> = Secret::new(item.client_secret);- Self {- session_token: vec![],- payment_id: item.payment_id,- client_secret,- }- }-}-#[cfg(feature = "v1")]impl From<PaymentsStartRequest> for PaymentsRequest {fn from(item: PaymentsStartRequest) -> Self {@@ -9437,7 +9425,7 @@ pub struct PaymentsSessionRequest {#[schema(value_type = String)]pub payment_id: id_type::PaymentId,/// This is a token which expires after 15 minutes, used from the client to authenticate and create sessions from the SDK- pub client_secret: String,+ pub client_secret: Option<String>,/// The list of the supported wallets#[schema(value_type = Vec<PaymentMethodType>)]pub wallets: Vec<api_enums::PaymentMethodType>,@@ -9485,8 +9473,8 @@ pub struct PaymentsPostSessionTokensRequest {#[schema(value_type = String)]pub payment_id: id_type::PaymentId,/// It's a token used for client side verification.- #[schema(value_type = String)]- pub client_secret: Secret<String>,+ #[schema(value_type = Option<String>)]+ pub client_secret: Option<Secret<String>>,/// Payment method type#[schema(value_type = PaymentMethodType)]pub payment_method_type: api_enums::PaymentMethodType,@@ -9515,8 +9503,8 @@ pub struct PaymentsDynamicTaxCalculationRequest {/// The shipping address for the paymentpub shipping: Address,/// Client Secret- #[schema(value_type = String)]- pub client_secret: Secret<String>,+ #[schema(value_type = Option<String>)]+ pub client_secret: Option<Secret<String>>,/// Payment method type#[schema(value_type = PaymentMethodType)]pub payment_method_type: api_enums::PaymentMethodType,@@ -10937,8 +10925,8 @@ pub struct PaymentsCompleteAuthorizeRequest {/// The shipping address for the paymentpub shipping: Option<Address>,/// Client Secret- #[schema(value_type = String)]- pub client_secret: Secret<String>,+ #[schema(value_type = Option<String>)]+ pub client_secret: Option<Secret<String>>,/// Indicates if 3DS method data was successfully completed or notpub threeds_method_comp_ind: Option<ThreeDsCompletionIndicator>,}@@ -10997,8 +10985,8 @@ pub struct PaymentsExternalAuthenticationRequest {#[serde(skip)]pub payment_id: id_type::PaymentId,/// Client Secret- #[schema(value_type = String)]- pub client_secret: Secret<String>,+ #[schema(value_type = Option<String>)]+ pub client_secret: Option<Secret<String>>,/// SDK Information if request is from SDKpub sdk_information: Option<SdkInformation>,/// Device Channel indicating whether request is coming from App or Browserdiff --git a/crates/hyperswitch_domain_models/src/sdk_auth.rs b/crates/hyperswitch_domain_models/src/sdk_auth.rsindex 7a07b37f04..266733845b 100644--- a/crates/hyperswitch_domain_models/src/sdk_auth.rs+++ b/crates/hyperswitch_domain_models/src/sdk_auth.rs@@ -20,8 +20,8 @@ pub struct SdkAuthorization {/// Platform publishable key (only for platform-initiated flows)pub platform_publishable_key: Option<String>,- /// Client secret for the payment (if available)- pub client_secret: Option<String>,+ /// Client secret for the payment (required for SDK authorization)+ pub client_secret: String,/// Customer ID for the payment (if available)pub customer_id: Option<id_type::CustomerId>,@@ -38,9 +38,7 @@ impl SdkAuthorization {self.platform_publishable_key.as_ref().map(|k| format!("platform_publishable_key={}", k)),- self.client_secret- .as_ref()- .map(|s| format!("client_secret={}", s)),+ Some(format!("client_secret={}", self.client_secret)),self.customer_id.as_ref().map(|id| format!("customer_id={}", id.get_string_repr())),@@ -110,7 +108,14 @@ impl SdkAuthorization {})?.to_string(),platform_publishable_key: parts.get("platform_publishable_key").map(|v| v.to_string()),- client_secret: parts.get("client_secret").map(|v| v.to_string()),+ client_secret: parts+ .get("client_secret")+ .ok_or_else(|| {+ report!(ValidationError::InvalidValue {+ message: "Missing required field: client_secret".to_string()+ })+ })?+ .to_string(),customer_id: parts.get("customer_id").map(|v| {diff --git a/crates/router/src/compatibility/stripe/payment_intents.rs b/crates/router/src/compatibility/stripe/payment_intents.rsindex b4ee992036..f884b7aa95 100644--- a/crates/router/src/compatibility/stripe/payment_intents.rs+++ b/crates/router/src/compatibility/stripe/payment_intents.rs@@ -151,7 +151,11 @@ pub async fn payment_intents_retrieve(state.into_inner(),&req,payload,- |state, auth, payload, req_state| {+ |state, auth, mut payload, req_state| {+ if let Some(client_secret) = auth.client_secret {+ payload.client_secret = Some(client_secret);+ }+payments::payments_core::<api_types::PSync,api_types::PaymentsResponse,@@ -235,7 +239,11 @@ pub async fn payment_intents_retrieve_with_gateway_creds(state.into_inner(),&req,payload,- |state, auth, req, req_state| {+ |state, auth, mut req, req_state| {+ if let Some(client_secret) = auth.client_secret {+ req.client_secret = Some(client_secret);+ }+payments::payments_core::<api_types::PSync,payment_types::PaymentsResponse,@@ -315,7 +323,11 @@ pub async fn payment_intents_update(state.into_inner(),&req,payload,- |state, auth, req, req_state| {+ |state, auth, mut req, req_state| {+ if let Some(client_secret) = auth.client_secret {+ req.client_secret = Some(client_secret);+ }+let eligible_connectors = req.connector.clone();payments::payments_core::<api_types::Authorize,@@ -405,7 +417,11 @@ pub async fn payment_intents_confirm(state.into_inner(),&req,payload,- |state, auth, req, req_state| {+ |state, auth, mut req, req_state| {+ if let Some(client_secret) = auth.client_secret {+ req.client_secret = Some(client_secret);+ }+let eligible_connectors = req.connector.clone();payments::payments_core::<api_types::Authorize,diff --git a/crates/router/src/compatibility/stripe/setup_intents.rs b/crates/router/src/compatibility/stripe/setup_intents.rsindex 04251c9723..aac6c0c4d3 100644--- a/crates/router/src/compatibility/stripe/setup_intents.rs+++ b/crates/router/src/compatibility/stripe/setup_intents.rs@@ -137,7 +137,11 @@ pub async fn setup_intents_retrieve(state.into_inner(),&req,payload,- |state, auth, payload, req_state| {+ |state, auth, mut payload, req_state| {+ if let Some(client_secret) = auth.client_secret {+ payload.client_secret = Some(client_secret);+ }+payments::payments_core::<api_types::PSync,api_types::PaymentsResponse,@@ -218,7 +222,11 @@ pub async fn setup_intents_update(state.into_inner(),&req,payload,- |state, auth, req, req_state| {+ |state, auth, mut req, req_state| {+ if let Some(client_secret) = auth.client_secret {+ req.client_secret = Some(client_secret);+ }+payments::payments_core::<api_types::SetupMandate,api_types::PaymentsResponse,@@ -300,7 +308,11 @@ pub async fn setup_intents_confirm(state.into_inner(),&req,payload,- |state, auth, req, req_state| {+ |state, auth, mut req, req_state| {+ if let Some(client_secret) = auth.client_secret {+ req.client_secret = Some(client_secret);+ }+payments::payments_core::<api_types::SetupMandate,api_types::PaymentsResponse,diff --git a/crates/router/src/core/payments/operations/payment_post_session_tokens.rs b/crates/router/src/core/payments/operations/payment_post_session_tokens.rsindex f7f9de77f4..5dfad074cb 100644--- a/crates/router/src/core/payments/operations/payment_post_session_tokens.rs+++ b/crates/router/src/core/payments/operations/payment_post_session_tokens.rs@@ -71,7 +71,13 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsPostSess.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;// TODO (#7195): Add platform merchant account validation once publishable key auth is solved- helpers::authenticate_client_secret(Some(request.client_secret.peek()), &payment_intent)?;+ helpers::authenticate_client_secret(+ request+ .client_secret+ .as_ref()+ .map(|client_secret| client_secret.peek()),+ &payment_intent,+ )?;let mut payment_attempt = db.find_payment_attempt_by_payment_id_processor_merchant_id_attempt_id(diff --git a/crates/router/src/core/payments/operations/payment_session.rs b/crates/router/src/core/payments/operations/payment_session.rsindex 7b8f092191..f2188f84a7 100644--- a/crates/router/src/core/payments/operations/payment_session.rs+++ b/crates/router/src/core/payments/operations/payment_session.rs@@ -77,7 +77,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsSessionR"create a session token for",)?;- helpers::authenticate_client_secret(Some(&request.client_secret), &payment_intent)?;+ helpers::authenticate_client_secret(request.client_secret.as_ref(), &payment_intent)?;let mut payment_attempt = db.find_payment_attempt_by_payment_id_processor_merchant_id_attempt_id(diff --git a/crates/router/src/core/payments/operations/tax_calculation.rs b/crates/router/src/core/payments/operations/tax_calculation.rsindex 4543210cf2..34ae70ebfa 100644--- a/crates/router/src/core/payments/operations/tax_calculation.rs+++ b/crates/router/src/core/payments/operations/tax_calculation.rs@@ -88,7 +88,13 @@ impl<F: Send + Clone + Sync>"create a session update for",)?;- helpers::authenticate_client_secret(Some(request.client_secret.peek()), &payment_intent)?;+ helpers::authenticate_client_secret(+ request+ .client_secret+ .as_ref()+ .map(|client_secret| client_secret.peek()),+ &payment_intent,+ )?;let mut payment_attempt = db.find_payment_attempt_by_payment_id_processor_merchant_id_attempt_id(diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rsindex 2d8ff85e19..b6f1ef2b48 100644--- a/crates/router/src/core/payments/transformers.rs+++ b/crates/router/src/core/payments/transformers.rs@@ -3977,7 +3977,10 @@ where| domain::Initiator::Jwt { .. }| domain::Initiator::EmbeddedToken { .. } => None,}),- client_secret: payment_intent.client_secret.clone(),+ client_secret: payment_intent+ .client_secret+ .clone()+ .get_required_value("client_secret")?,customer_id: payment_intent.customer_id.clone(),};diff --git a/crates/router/src/routes/authentication.rs b/crates/router/src/routes/authentication.rsindex d2b5f6111f..c6427fe7a3 100644--- a/crates/router/src/routes/authentication.rs+++ b/crates/router/src/routes/authentication.rs@@ -6,6 +6,7 @@ use api_models::authentication::{AuthenticationRetrieveEligibilityCheckRequest, AuthenticationSessionTokenRequest,AuthenticationSyncPostUpdateRequest, AuthenticationSyncRequest,};+use masking::Secret;use router_env::{instrument, tracing, Flow};use crate::{@@ -64,7 +65,11 @@ pub async fn authentication_eligibility(state,&req,payload,- |state, auth: auth::AuthenticationData, req, _| {+ |state, auth, mut req, _| {+ if let Some(client_secret) = auth.client_secret {+ req.client_secret = Some(Secret::new(client_secret));+ }+unified_authentication_service::authentication_eligibility_core(state,auth.platform,@@ -105,7 +110,11 @@ pub async fn authentication_authenticate(state,&req,payload,- |state, auth: auth::AuthenticationData, req, _| {+ |state, auth, mut req, _| {+ if let Some(client_secret) = auth.client_secret {+ req.client_secret = Some(Secret::new(client_secret));+ }+unified_authentication_service::authentication_authenticate_core(state,auth.platform,@@ -146,7 +155,11 @@ pub async fn authentication_eligibility_check(state,&req,payload,- |state, auth: auth::AuthenticationData, req, _| {+ |state, auth, mut req, _| {+ if let Some(client_secret) = auth.client_secret {+ req.client_secret = Some(Secret::new(client_secret));+ }+unified_authentication_service::authentication_eligibility_check_core(state,auth.platform,@@ -221,7 +234,11 @@ pub async fn authentication_sync(state,&req,payload,- |state, auth: auth::AuthenticationData, req, _| {+ |state, auth, mut req, _| {+ if let Some(client_secret) = auth.client_secret {+ req.client_secret = Some(Secret::new(client_secret));+ }+unified_authentication_service::authentication_sync_core(state,auth.platform,@@ -291,7 +308,10 @@ pub async fn authentication_session_token(state,&req,payload,- |state, auth: auth::AuthenticationData, req, _| {+ |state, auth: auth::AuthenticationData, mut req, _| {+ if let Some(client_secret) = auth.client_secret {+ req.client_secret = Some(Secret::new(client_secret));+ }unified_authentication_service::authentication_session_core(state, auth.platform, req)},&*auth,diff --git a/crates/router/src/routes/blocklist.rs b/crates/router/src/routes/blocklist.rsindex 224e730907..fdee5d9035 100644--- a/crates/router/src/routes/blocklist.rs+++ b/crates/router/src/routes/blocklist.rs@@ -129,7 +129,11 @@ pub async fn list_blocked_payment_methods(state,&req,payload,- |state, auth: auth::AuthenticationData, query, _| {+ |state, auth, mut query, _| {+ if let Some(client_secret) = auth.client_secret {+ query.client_secret = Some(client_secret);+ }+blocklist::list_blocklist_entries(state, auth.platform, query)},auth::auth_type(diff --git a/crates/router/src/routes/cards_info.rs b/crates/router/src/routes/cards_info.rsindex e4c6bdc438..ca4ce611cd 100644--- a/crates/router/src/routes/cards_info.rs+++ b/crates/router/src/routes/cards_info.rs@@ -51,7 +51,13 @@ pub async fn card_iin_info(state,&req,payload,- |state, auth, req, _| cards_info::retrieve_card_info(state, auth.platform, req),+ |state, auth, mut req, _| {+ if let Some(client_secret) = auth.client_secret {+ req.client_secret = Some(client_secret);+ }++ cards_info::retrieve_card_info(state, auth.platform, req)+ },&*auth,api_locking::LockAction::NotApplicable,))diff --git a/crates/router/src/routes/customers.rs b/crates/router/src/routes/customers.rsindex ac9a950763..a56945f253 100644--- a/crates/router/src/routes/customers.rs+++ b/crates/router/src/routes/customers.rs@@ -100,7 +100,7 @@ pub async fn customers_retrieve(state,&req,customer_id,- |state, auth: auth::AuthenticationData, customer_id, _| {+ |state, auth, customer_id, _| {let profile_id = auth.profile.map(|profile| profile.get_id().clone());retrieve_customer(state,diff --git a/crates/router/src/routes/payment_methods.rs b/crates/router/src/routes/payment_methods.rsindex ff00fa0f46..a9c68b1d32 100644--- a/crates/router/src/routes/payment_methods.rs+++ b/crates/router/src/routes/payment_methods.rs@@ -633,7 +633,11 @@ pub async fn save_payment_method_api(state,&req,payload,- |state, auth: auth::AuthenticationData, req, _| {+ |state, auth: auth::AuthenticationData, mut req, _| {+ if let Some(client_secret) = auth.client_secret {+ req.client_secret = Some(client_secret);+ }+Box::pin(cards::add_payment_method_data(state,req,@@ -671,7 +675,11 @@ pub async fn list_payment_method_api(state,&req,payload,- |state, auth: auth::AuthenticationData, req, _| {+ |state, auth: auth::AuthenticationData, mut req, _| {+ if let Some(client_secret) = auth.client_secret {+ req.client_secret = Some(client_secret);+ }+// TODO (#7195): Fill platform_merchant_account in the client secret auth and pass it here.cards::list_payment_methods(state, auth.platform, req)},@@ -700,16 +708,27 @@ pub async fn list_customer_payment_method_api(allow_platform_self_operation: true,};- let ephemeral_auth = match auth::is_ephemeral_auth(req.headers(), api_auth) {- Ok(auth) => auth,- Err(err) => return api::log_and_return_error_response(err),- };+ let auth_type: Box<dyn auth::AuthenticateAndFetch<auth::AuthenticationData, _>> =+ match req.headers().get(actix_web::http::header::AUTHORIZATION) {+ Some(_) => Box::new(auth::SdkAuthorizationAuth {+ allow_connected_scope_operation: api_auth.allow_connected_scope_operation,+ allow_platform_self_operation: api_auth.allow_platform_self_operation,+ }),+ None => match auth::is_ephemeral_auth(req.headers(), api_auth) {+ Ok(auth) => auth,+ Err(err) => return api::log_and_return_error_response(err),+ },+ };Box::pin(api::server_wrap(flow,state,&req,payload,- |state, auth: auth::AuthenticationData, req, _| {+ |state, auth: auth::AuthenticationData, mut req, _| {+ if let Some(client_secret) = auth.client_secret {+ req.client_secret = Some(client_secret);+ }+cards::do_list_customer_pm_fetch_customer_if_not_passed(state,auth.platform,@@ -718,7 +737,7 @@ pub async fn list_customer_payment_method_api(None,)},- &*ephemeral_auth,+ &*auth_type,api_locking::LockAction::NotApplicable,)).await@@ -739,22 +758,44 @@ pub async fn list_customer_payment_method_api_client(let api_key = auth::get_api_key(req.headers()).ok();let api_auth = auth::ApiKeyAuth {allow_connected_scope_operation: true,- allow_platform_self_operation: true,+ allow_platform_self_operation: false,+ };++ // Check if Authorization header is present for SDK authorization+ let (auth, _, is_ephemeral_auth) = match req+ .headers()+ .get(actix_web::http::header::AUTHORIZATION)+ {+ Some(_) => {+ // If Authorization header is present, use SdkAuthorizationAuth+ let auth: Box<dyn auth::AuthenticateAndFetch<auth::AuthenticationData, _>> =+ Box::new(auth::SdkAuthorizationAuth {+ allow_connected_scope_operation: api_auth.allow_connected_scope_operation,+ allow_platform_self_operation: api_auth.allow_platform_self_operation,+ });+ (auth, api::AuthFlow::Client, false)+ }+ None => {+ // If Authorization header is not present, use existing logic+ match auth::get_ephemeral_or_other_auth(req.headers(), false, Some(&payload), api_auth)+ .await+ {+ Ok((auth, _auth_flow, is_ephemeral_auth)) => (auth, _auth_flow, is_ephemeral_auth),+ Err(e) => return api::log_and_return_error_response(e),+ }+ }};- let (auth, _, is_ephemeral_auth) =- match auth::get_ephemeral_or_other_auth(req.headers(), false, Some(&payload), api_auth)- .await- {- Ok((auth, _auth_flow, is_ephemeral_auth)) => (auth, _auth_flow, is_ephemeral_auth),- Err(e) => return api::log_and_return_error_response(e),- };Box::pin(api::server_wrap(flow,state,&req,payload,- |state, auth: auth::AuthenticationData, req, _| {+ |state, auth: auth::AuthenticationData, mut req, _| {+ if let Some(client_secret) = auth.client_secret {+ req.client_secret = Some(client_secret);+ }+cards::do_list_customer_pm_fetch_customer_if_not_passed(state,auth.platform,@@ -1006,7 +1047,11 @@ pub async fn payment_method_update_api(state,&req,payload,- |state, auth: auth::AuthenticationData, req, _| {+ |state, auth: auth::AuthenticationData, mut req, _| {+ if let Some(client_secret) = auth.client_secret {+ req.client_secret = Some(client_secret);+ }+cards::update_customer_payment_method(state,auth.platform.get_provider().clone(),@@ -1159,10 +1204,17 @@ pub async fn default_payment_method_set_api(allow_platform_self_operation: true,};- let ephemeral_auth = match auth::is_ephemeral_auth(req.headers(), api_auth) {- Ok(auth) => auth,- Err(err) => return api::log_and_return_error_response(err),- };+ let auth_type: Box<dyn auth::AuthenticateAndFetch<auth::AuthenticationData, _>> =+ match req.headers().get(actix_web::http::header::AUTHORIZATION) {+ Some(_) => Box::new(auth::SdkAuthorizationAuth {+ allow_connected_scope_operation: api_auth.allow_connected_scope_operation,+ allow_platform_self_operation: api_auth.allow_platform_self_operation,+ }),+ None => match auth::is_ephemeral_auth(req.headers(), api_auth) {+ Ok(auth) => auth,+ Err(err) => return api::log_and_return_error_response(err),+ },+ };Box::pin(api::server_wrap(flow,state,@@ -1180,7 +1232,7 @@ pub async fn default_payment_method_set_api().await},- &*ephemeral_auth,+ &*auth_type,api_locking::LockAction::NotApplicable,)).awaitdiff --git a/crates/router/src/routes/payments.rs b/crates/router/src/routes/payments.rsindex 8f8158c259..99f3c81576 100644--- a/crates/router/src/routes/payments.rs+++ b/crates/router/src/routes/payments.rs@@ -5,8 +5,8 @@ use crate::{pub mod helpers;use actix_web::{web, Responder};use error_stack::report;-use hyperswitch_domain_models::payments::HeaderPayload;-use masking::PeekInterface;+use hyperswitch_domain_models::{ext_traits::OptionExt, payments::HeaderPayload};+use masking::{PeekInterface, Secret};use router_env::{env, instrument, logger, tracing, types, Flow};use super::app::ReqState;@@ -637,7 +637,12 @@ pub async fn payments_retrieve(state,&req,payload,- |state, auth: auth::AuthenticationData, req, req_state| {+ |state, auth, mut req, req_state| {+ // If client_secret is provided via SDK authorization header, use it+ if let Some(client_secret) = auth.client_secret {+ req.client_secret = Some(client_secret);+ }+payments::payments_core::<api_types::PSync,payment_types::PaymentsResponse,@@ -712,7 +717,7 @@ pub async fn payments_retrieve_with_gateway_creds(state,&req,payload,- |state, auth: auth::AuthenticationData, req, req_state| {+ |state, auth, req, req_state| {payments::payments_core::<api_types::PSync,payment_types::PaymentsResponse,@@ -786,7 +791,11 @@ pub async fn payments_update(state,&req,payload,- |state, auth: auth::AuthenticationData, req, req_state| {+ |state, auth: auth::AuthenticationData, mut req, req_state| {+ if let Some(client_secret) = auth.client_secret {+ req.client_secret = Some(client_secret);+ }+authorize_verify_select::<_>(payments::PaymentUpdate,state,@@ -829,12 +838,47 @@ pub async fn payments_post_session_tokens(let locking_action = payload.get_locking_input(flow.clone());+ // Determine auth type based on Authorization header presence+ let auth: Box<dyn auth::AuthenticateAndFetch<auth::AuthenticationData, _>> =+ match req.headers().get(actix_web::http::header::AUTHORIZATION) {+ // If Authorization header is present, use SdkAuthorizationAuth+ Some(_) => Box::new(auth::SdkAuthorizationAuth {+ allow_connected_scope_operation: true,+ allow_platform_self_operation: false,+ }),+ // If Authorization header is not present, use PublishableKeyAuth+ None => {+ // For PublishableKeyAuth, client_secret is mandatory+ match payload+ .client_secret+ .as_ref()+ .map(|client_secret| client_secret.peek())+ .check_value_present("client_secret")+ .map_err(|_| errors::ApiErrorResponse::MissingRequiredField {+ field_name: "client_secret",+ }) {+ Ok(_) => {}+ Err(err) => return api::log_and_return_error_response(report!(err)),+ }++ Box::new(auth::HeaderAuth(auth::PublishableKeyAuth {+ allow_connected_scope_operation: true,+ allow_platform_self_operation: false,+ }))+ }+ };+Box::pin(api::server_wrap(flow,state,&req,payload,- |state, auth, req, req_state| {+ |state, auth: auth::AuthenticationData, mut req, req_state| {+ // If client_secret is provided via SDK authorization header, use it+ if let Some(client_secret) = auth.client_secret {+ req.client_secret = Some(Secret::new(client_secret));+ }+payments::payments_core::<api_types::PostSessionTokens,payment_types::PaymentsPostSessionTokensResponse,@@ -856,10 +900,7 @@ pub async fn payments_post_session_tokens(header_payload.clone(),)},- &auth::PublishableKeyAuth {- allow_connected_scope_operation: true,- allow_platform_self_operation: false,- },+ &*auth,locking_action,)).await@@ -895,7 +936,7 @@ pub async fn payments_update_metadata(state,&req,payload,- |state, auth, req, req_state| {+ |state, auth: auth::AuthenticationData, req, req_state| {payments::payments_core::<api_types::UpdateMetadata,payment_types::PaymentsUpdateMetadataResponse,@@ -985,7 +1026,12 @@ pub async fn payments_confirm(state,&req,payload,- |state, auth: auth::AuthenticationData, req, req_state| {+ |state, auth: auth::AuthenticationData, mut req, req_state| {+ // If client_secret is provided via SDK authorization header, use it+ if let Some(client_secret) = auth.client_secret {+ req.client_secret = Some(client_secret);+ }+authorize_verify_select::<_>(payments::PaymentConfirm,state,@@ -1084,12 +1130,48 @@ pub async fn payments_dynamic_tax_calculation(};tracing::Span::current().record("payment_id", payload.payment_id.get_string_repr());let locking_action = payload.get_locking_input(flow.clone());++ // Determine auth type based on Authorization header presence+ let auth: Box<dyn auth::AuthenticateAndFetch<auth::AuthenticationData, _>> =+ match req.headers().get(actix_web::http::header::AUTHORIZATION) {+ // If Authorization header is present, use SdkAuthorizationAuth+ Some(_) => Box::new(auth::SdkAuthorizationAuth {+ allow_connected_scope_operation: true,+ allow_platform_self_operation: false,+ }),+ // If Authorization header is not present, use PublishableKeyAuth+ None => {+ // For PublishableKeyAuth, client_secret is mandatory+ match payload+ .client_secret+ .as_ref()+ .map(|client_secret| client_secret.peek())+ .check_value_present("client_secret")+ .map_err(|_| errors::ApiErrorResponse::MissingRequiredField {+ field_name: "client_secret",+ }) {+ Ok(_) => {}+ Err(err) => return api::log_and_return_error_response(report!(err)),+ }++ Box::new(auth::HeaderAuth(auth::PublishableKeyAuth {+ allow_connected_scope_operation: true,+ allow_platform_self_operation: false,+ }))+ }+ };+Box::pin(api::server_wrap(flow,state,&req,payload,- |state, auth: auth::AuthenticationData, payload, req_state| {+ |state, auth, mut payload, req_state| {+ // If client_secret is provided via SDK authorization header, use it+ if let Some(client_secret) = auth.client_secret {+ payload.client_secret = Some(Secret::new(client_secret));+ }+payments::payments_core::<api_types::SdkSessionUpdate,payment_types::PaymentsDynamicTaxCalculationResponse,@@ -1111,10 +1193,7 @@ pub async fn payments_dynamic_tax_calculation(header_payload.clone(),)},- &auth::PublishableKeyAuth {- allow_connected_scope_operation: true,- allow_platform_self_operation: false,- },+ &*auth,locking_action,)).await@@ -1209,12 +1288,44 @@ pub async fn payments_connector_session(let locking_action = payload.get_locking_input(flow.clone());+ // Determine auth type based on Authorization header presence+ let auth: Box<dyn auth::AuthenticateAndFetch<auth::AuthenticationData, _>> =+ match req.headers().get(actix_web::http::header::AUTHORIZATION) {+ // If Authorization header is present, use SdkAuthorizationAuth+ Some(_) => Box::new(auth::SdkAuthorizationAuth {+ allow_connected_scope_operation: true,+ allow_platform_self_operation: false,+ }),+ // If Authorization header is not present, use PublishableKeyAuth+ None => {+ // For PublishableKeyAuth, client_secret is mandatory+ match payload+ .client_secret+ .check_value_present("client_secret")+ .map_err(|_| errors::ApiErrorResponse::MissingRequiredField {+ field_name: "client_secret",+ }) {+ Ok(_) => {}+ Err(err) => return api::log_and_return_error_response(report!(err)),+ }++ Box::new(auth::HeaderAuth(auth::PublishableKeyAuth {+ allow_connected_scope_operation: true,+ allow_platform_self_operation: false,+ }))+ }+ };+Box::pin(api::server_wrap(flow,state,&req,payload,- |state, auth: auth::AuthenticationData, payload, req_state| {+ |state, auth: auth::AuthenticationData, mut payload, req_state| {+ // If client_secret is provided via SDK authorization header, use it+ if let Some(client_secret) = auth.client_secret {+ payload.client_secret = Some(client_secret);+ }payments::payments_core::<api_types::Session,payment_types::PaymentsSessionResponse,@@ -1236,10 +1347,7 @@ pub async fn payments_connector_session(header_payload.clone(),)},- &auth::HeaderAuth(auth::PublishableKeyAuth {- allow_connected_scope_operation: true,- allow_platform_self_operation: false,- }),+ &*auth,locking_action,)).await@@ -1459,7 +1567,10 @@ pub async fn payments_complete_authorize(payment_id.clone(),)),shipping: payload.shipping.clone(),- client_secret: Some(payload.client_secret.peek().clone()),+ client_secret: payload+ .client_secret+ .clone()+ .map(|client_secret| client_secret.peek().clone()),threeds_method_comp_ind: payload.threeds_method_comp_ind.clone(),..Default::default()};@@ -1481,7 +1592,11 @@ pub async fn payments_complete_authorize(state,&req,payload,- |state, auth: auth::AuthenticationData, _req, req_state| {+ |state, auth: auth::AuthenticationData, mut req, req_state| {+ // If client_secret is provided via SDK authorization header, use it+ if let Some(client_secret) = auth.client_secret {+ req.client_secret = Some(Secret::new(client_secret));+ }payments::payments_core::<api_types::CompleteAuthorize,payment_types::PaymentsResponse,@@ -2372,20 +2487,53 @@ pub async fn payments_external_authentication(payload.payment_id = payment_id;let locking_action = payload.get_locking_input(flow.clone());++ // Determine auth type based on Authorization header presence+ let auth: Box<dyn auth::AuthenticateAndFetch<auth::AuthenticationData, _>> =+ match req.headers().get(actix_web::http::header::AUTHORIZATION) {+ // If Authorization header is present, use SdkAuthorizationAuth+ Some(_) => Box::new(auth::SdkAuthorizationAuth {+ allow_connected_scope_operation: true,+ allow_platform_self_operation: false,+ }),+ // If Authorization header is not present, use PublishableKeyAuth+ None => {+ // For PublishableKeyAuth, client_secret is mandatory+ match payload+ .client_secret+ .as_ref()+ .map(|client_secret| client_secret.peek())+ .check_value_present("client_secret")+ .map_err(|_| errors::ApiErrorResponse::MissingRequiredField {+ field_name: "client_secret",+ }) {+ Ok(_) => {}+ Err(err) => return api::log_and_return_error_response(report!(err)),+ }++ Box::new(auth::HeaderAuth(auth::PublishableKeyAuth {+ allow_connected_scope_operation: true,+ allow_platform_self_operation: false,+ }))+ }+ };+Box::pin(api::server_wrap(flow,state,&req,payload,- |state, auth: auth::AuthenticationData, req, _| {+ |state, auth: auth::AuthenticationData, mut req, _| {+ // If client_secret is provided via SDK authorization header, use it+ if let Some(client_secret) = auth.client_secret {+ req.client_secret = Some(Secret::new(client_secret));+ }+payments::payment_external_authentication::<hyperswitch_domain_models::router_flow_types::Authenticate,>(state, auth.platform, req)},- &auth::HeaderAuth(auth::PublishableKeyAuth {- allow_connected_scope_operation: true,- allow_platform_self_operation: false,- }),+ &*auth,locking_action,)).await@@ -2535,6 +2683,10 @@ pub async fn payments_submit_eligibility(&http_req,payment_id,|state, auth: auth::AuthenticationData, payment_id, _| {+ let mut payload = payload.clone();+ if let Some(client_secret) = auth.client_secret {+ payload.client_secret = Some(Secret::new(client_secret));+ }payments::payments_submit_eligibility(state, auth.platform, payload.clone(), payment_id)},&*auth_type,diff --git a/crates/router/src/routes/payouts.rs b/crates/router/src/routes/payouts.rsindex d94b4d18f9..94067b58c2 100644--- a/crates/router/src/routes/payouts.rs+++ b/crates/router/src/routes/payouts.rs@@ -188,7 +188,14 @@ pub async fn payouts_confirm(state,&req,payload,- |state, auth, req, _| payouts_confirm_core(state, auth.platform, req),+ |state, auth, mut req, _| {+ #[cfg(feature = "v1")]+ if let Some(client_secret) = auth.client_secret {+ req.client_secret = Some(client_secret);+ }++ payouts_confirm_core(state, auth.platform, req)+ },&*auth_type,api_locking::LockAction::NotApplicable,))diff --git a/crates/router/src/routes/pm_auth.rs b/crates/router/src/routes/pm_auth.rsindex d918699070..1eb07071f9 100644--- a/crates/router/src/routes/pm_auth.rs+++ b/crates/router/src/routes/pm_auth.rs@@ -57,7 +57,11 @@ pub async fn link_token_create(state,&req,payload,- |state, auth, payload, _| {+ |state, auth, mut payload, _| {+ #[cfg(feature = "v1")]+ if let Some(client_secret) = auth.client_secret {+ payload.client_secret = Some(client_secret);+ }crate::core::pm_auth::create_link_token(state,auth.platform,@@ -110,7 +114,11 @@ pub async fn exchange_token(state,&req,payload,- |state, auth, payload, _| {+ |state, auth, mut payload, _| {+ #[cfg(feature = "v1")]+ if let Some(client_secret) = auth.client_secret {+ payload.client_secret = Some(client_secret);+ }crate::core::pm_auth::exchange_token_core(state, auth.platform, payload)},&*auth,diff --git a/crates/router/src/routes/profile_acquirer.rs b/crates/router/src/routes/profile_acquirer.rsindex 8ec0514cb1..1d279f2ae4 100644--- a/crates/router/src/routes/profile_acquirer.rs+++ b/crates/router/src/routes/profile_acquirer.rs@@ -23,7 +23,7 @@ pub async fn create_profile_acquirer(state,&req,payload,- |state: super::SessionState, auth_data, req, _| {+ |state: super::SessionState, auth_data: auth::AuthenticationData, req, _| {crate::core::profile_acquirer::create_profile_acquirer(state, req, auth_data.platform)},auth::auth_type(@@ -61,7 +61,7 @@ pub async fn profile_acquirer_update(state,&req,payload,- |state: super::SessionState, auth_data, req, _| {+ |state: super::SessionState, auth_data: auth::AuthenticationData, req, _| {crate::core::profile_acquirer::update_profile_acquirer_config(state,profile_id.clone(),diff --git a/crates/router/src/routes/routing.rs b/crates/router/src/routes/routing.rsindex 9bf72fa41c..ede56adf8e 100644--- a/crates/router/src/routes/routing.rs+++ b/crates/router/src/routes/routing.rs@@ -1616,7 +1616,9 @@ pub async fn call_decide_gateway_open_router(state,&req,payload.clone(),- |state, _auth, payload, _| routing::decide_gateway_open_router(state.clone(), payload),+ |state, _auth: auth::AuthenticationData, payload, _| {+ routing::decide_gateway_open_router(state.clone(), payload)+ },&auth::ApiKeyAuth {allow_connected_scope_operation: false,allow_platform_self_operation: false,@@ -1639,7 +1641,7 @@ pub async fn call_update_gateway_score_open_router(state,&req,payload.clone(),- |state, _auth, payload, _| {+ |state, _auth: auth::AuthenticationData, payload, _| {routing::update_gateway_score_open_router(state.clone(), payload)},&auth::ApiKeyAuth {diff --git a/crates/router/src/routes/subscription.rs b/crates/router/src/routes/subscription.rsindex e5a65ce7b3..b645892459 100644--- a/crates/router/src/routes/subscription.rs+++ b/crates/router/src/routes/subscription.rs@@ -240,7 +240,11 @@ pub async fn confirm_subscription(state,&req,payload,- |state, auth: auth::AuthenticationData, payload, _| {+ |state, auth, mut payload, _| {+ if let Some(client_secret) = auth.client_secret {+ payload.client_secret = Some(subscription_types::ClientSecret::new(client_secret));+ }+subscriptions::confirm_subscription(state.into(),auth.platform,@@ -301,7 +305,11 @@ pub async fn get_subscription_items(state,&req,payload,- |state, auth: auth::AuthenticationData, query, _| {+ |state, auth, mut query, _| {+ if let Some(client_secret) = auth.client_secret {+ query.client_secret = Some(subscription_types::ClientSecret::new(client_secret));+ }+subscriptions::get_subscription_items(state.into(),auth.platform,@@ -427,7 +435,7 @@ pub async fn get_estimate(state,&req,query.into_inner(),- |state, auth: auth::AuthenticationData, query, _| {+ |state, auth, query, _| {subscriptions::get_estimate(state.into(), auth.platform, profile_id.clone(), query)},&*auth_type,diff --git a/crates/router/src/routes/user.rs b/crates/router/src/routes/user.rsindex 3364cf3c61..0d19e3c7f1 100644--- a/crates/router/src/routes/user.rs+++ b/crates/router/src/routes/user.rs@@ -1075,7 +1075,7 @@ pub async fn issue_embedded_token(state.clone(),&http_req,(),- |state, auth_data, _, _| {+ |state, auth_data: auth::AuthenticationData, _, _| {user_core::issue_embedded_token(state,auth_data.platform.get_processor().clone(),diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rsindex 24d1f9d43a..f6e8c170b9 100644--- a/crates/router/src/services/api.rs+++ b/crates/router/src/services/api.rs@@ -748,18 +748,22 @@ impl Authenticate for api_models::payment_methods::PaymentMethodListRequest {#[cfg(feature = "v1")]impl Authenticate for api_models::payments::PaymentsSessionRequest {fn get_client_secret(&self) -> Option<&String> {- Some(&self.client_secret)+ self.client_secret.as_ref()}}impl Authenticate for api_models::payments::PaymentsDynamicTaxCalculationRequest {fn get_client_secret(&self) -> Option<&String> {- Some(self.client_secret.peek())+ self.client_secret+ .as_ref()+ .map(|client_secret| client_secret.peek())}}impl Authenticate for api_models::payments::PaymentsPostSessionTokensRequest {fn get_client_secret(&self) -> Option<&String> {- Some(self.client_secret.peek())+ self.client_secret+ .as_ref()+ .map(|client_secret| client_secret.peek())}}diff --git a/crates/router/src/services/authentication.rs b/crates/router/src/services/authentication.rsindex 7165d46c7d..ac5879c780 100644--- a/crates/router/src/services/authentication.rs+++ b/crates/router/src/services/authentication.rs@@ -68,6 +68,7 @@ mod detached;pub struct AuthenticationData {pub platform: domain::Platform,pub profile: Option<domain::Profile>,+ pub client_secret: Option<String>,}#[cfg(feature = "v2")]@@ -86,6 +87,7 @@ impl AuthenticationData {Self {platform,profile: Some(profile),+ client_secret: None,}}}@@ -785,7 +787,11 @@ whereNone => None,};- let auth = AuthenticationData { platform, profile };+ let auth = AuthenticationData {+ platform,+ profile,+ client_secret: None,+ };Ok((auth.clone(),AuthenticationType::ApiKey {@@ -822,7 +828,7 @@ whereallow_connected_scope_operation: true,allow_platform_self_operation: false,};- let (auth_data, auth_type) = api_auth+ let (auth_data, auth_type): (AuthenticationData, AuthenticationType) = api_auth.authenticate_and_fetch(request_headers, state).await?;@@ -1038,6 +1044,7 @@ wherelet auth = AuthenticationData {platform,profile: None,+ client_secret: None,};Ok((@@ -1177,6 +1184,7 @@ wherelet auth = AuthenticationData {platform,profile: None,+ client_secret: None,};Ok((@@ -1426,7 +1434,11 @@ whereNone => None,};- let auth = AuthenticationData { platform, profile };+ let auth = AuthenticationData {+ platform,+ profile,+ client_secret: None,+ };Ok(auth)}@@ -1720,6 +1732,7 @@ wherelet auth = AuthenticationData {platform,profile: None,+ client_secret: None,};Ok((@@ -2005,6 +2018,7 @@ wherelet auth = AuthenticationData {platform,profile: None,+ client_secret: None,};return Ok((auth,@@ -2069,6 +2083,7 @@ wherelet auth = AuthenticationData {platform,profile: None,+ client_secret: None,};return Ok((auth,@@ -2240,6 +2255,7 @@ wherelet auth = AuthenticationData {platform,profile: None,+ client_secret: None,};Ok((auth,@@ -2433,6 +2449,7 @@ wherelet auth = AuthenticationData {platform,profile: None,+ client_secret: None,};Ok((auth.clone(),@@ -3108,7 +3125,9 @@ wherelet auth = AuthenticationData {platform,profile: None,+ client_secret: None,};+Ok((auth,AuthenticationType::PublishableKey {@@ -3215,6 +3234,9 @@ wherelet sdk_auth = SdkAuthorization::decode(sdk_auth_header).change_context(errors::ApiErrorResponse::Unauthorized)?;+ // Extract client_secret from decoded SDK authorization+ let client_secret = Some(sdk_auth.client_secret.clone());+let (initiator_merchant, initiator_merchant_key_store) = match sdk_auth.platform_publishable_key{@@ -3259,12 +3281,13 @@ where.await.to_not_found_response(errors::ApiErrorResponse::Unauthorized)?;- let auth = AuthenticationData {+ let auth_data = AuthenticationData {platform,profile: Some(profile),+ client_secret,};Ok((- auth,+ auth_data,AuthenticationType::SdkAuthorization {merchant_id: initiator_merchant.get_id().clone(),},@@ -3739,6 +3762,7 @@ wherelet auth = AuthenticationData {platform,profile: Some(profile),+ client_secret: None,};Ok((@@ -4041,6 +4065,7 @@ wherelet auth = AuthenticationData {platform,profile: Some(profile),+ client_secret: None,};Ok((auth.clone(),@@ -4262,6 +4287,7 @@ wherelet auth = AuthenticationData {platform,profile: Some(profile),+ client_secret: None,};Ok((auth.clone(),@@ -4351,6 +4377,7 @@ wherelet auth = AuthenticationData {platform,profile: Some(profile),+ client_secret: None,};Ok((auth.clone(),@@ -4529,6 +4556,7 @@ wherelet auth = AuthenticationData {platform,profile: Some(profile),+ client_secret: None,};Ok((auth,@@ -4683,6 +4711,7 @@ wherelet auth = AuthenticationData {platform,profile: Some(profile),+ client_secret: None,};Ok(((auth.clone(), payload.user_id.clone()),@@ -4838,6 +4867,7 @@ wherelet auth = AuthenticationData {platform,profile: Some(profile),+ client_secret: None,};Ok((auth,@@ -4939,6 +4969,7 @@ wherelet auth = AuthenticationData {platform,profile: Some(profile),+ client_secret: None,};let auth_type = match payload {AuthOrEmbeddedClaims::AuthToken(auth_payload) => AuthenticationType::MerchantJwt {@@ -5005,7 +5036,25 @@ impl ClientSecretFetch for PaymentMethodListRequest {impl ClientSecretFetch for payments::PaymentsPostSessionTokensRequest {fn get_client_secret(&self) -> Option<&String> {- Some(self.client_secret.peek())+ self.client_secret+ .as_ref()+ .map(|client_secret| client_secret.peek())+ }+}++impl ClientSecretFetch for payments::PaymentsDynamicTaxCalculationRequest {+ fn get_client_secret(&self) -> Option<&String> {+ self.client_secret+ .as_ref()+ .map(|client_secret| client_secret.peek())+ }+}++impl ClientSecretFetch for payments::PaymentsExternalAuthenticationRequest {+ fn get_client_secret(&self) -> Option<&String> {+ self.client_secret+ .as_ref()+ .map(|client_secret| client_secret.peek())}}@@ -5124,6 +5173,29 @@ pub fn get_auth_type_and_flow<A: SessionStateInfo + Sync + Send>(Ok((Box::new(HeaderAuth(api_auth)), api::AuthFlow::Merchant))}+#[cfg(feature = "v1")]+/// Wrapper function to check Authorization header and call get_auth_type_and_flow if not present+pub fn check_authorization_header_or_get_auth<A: SessionStateInfo + Sync + Send>(+ headers: &HeaderMap,+ api_auth: ApiKeyAuth,+) -> RouterResult<(+ Box<dyn AuthenticateAndFetch<AuthenticationData, A>>,+ api::AuthFlow,+)> {+ match get_header_value_by_key(headers::AUTHORIZATION.into(), headers)? {+ // If Authorization header is present, use SdkAuthorizationAuth+ Some(_) => Ok((+ Box::new(SdkAuthorizationAuth {+ allow_connected_scope_operation: api_auth.allow_connected_scope_operation,+ allow_platform_self_operation: api_auth.allow_platform_self_operation,+ }),+ api::AuthFlow::Client,+ )),+ // If Authorization header is not present, use existing flow+ None => get_auth_type_and_flow(headers, api_auth),+ }+}+pub fn check_client_secret_and_get_auth<T>(headers: &HeaderMap,payload: &impl ClientSecretFetch,@@ -5224,16 +5296,7 @@ where))} else {let payload = payload.get_required_value("ClientSecretFetch")?;- let (auth, auth_flow) = {- #[cfg(feature = "v1")]- {- check_sdk_auth_and_get_auth(headers, payload, api_auth)?- }- #[cfg(feature = "v2")]- {- check_client_secret_and_get_auth(headers, payload, api_auth)?- }- };+ let (auth, auth_flow) = check_client_secret_and_get_auth(headers, payload, api_auth)?;Ok((auth, auth_flow, false))}}@@ -5317,7 +5380,7 @@ whereapi::AuthFlow::Merchant,))} else {- let (auth, auth_flow) = get_auth_type_and_flow(headers, api_auth)?;+ let (auth, auth_flow) = check_authorization_header_or_get_auth(headers, api_auth)?;Ok((auth, auth_flow))}}