From ed5fba9abce636e2538d523b70f6d701b5bcb63c Mon Sep 17 00:00:00 2001 From: Narayan Bhat Date: Wed, 18 Dec 2024 11:26:34 +0530 Subject: [PATCH] refactor(auth): remove duplicate profile fetch in case of partial auth header auth impl --- crates/router/src/services/authentication.rs | 35 ++++++-------------- 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/crates/router/src/services/authentication.rs b/crates/router/src/services/authentication.rs index e8435243ff4d..26184f6bb802 100644 --- a/crates/router/src/services/authentication.rs +++ b/crates/router/src/services/authentication.rs @@ -680,31 +680,18 @@ where request_headers: &HeaderMap, state: &A, ) -> RouterResult<(AuthenticationData, AuthenticationType)> { - let (auth_data, auth_type): (AuthenticationData, AuthenticationType) = self - .0 - .authenticate_and_fetch(request_headers, state) - .await?; - - let profile_id = HeaderMapStruct::new(request_headers) - .get_id_type_from_header::(headers::X_PROFILE_ID)?; - - let key_manager_state = &(&state.session_state()).into(); - let profile = state - .store() - .find_business_profile_by_profile_id( - key_manager_state, - &auth_data.key_store, - &profile_id, - ) - .await - .to_not_found_response(errors::ApiErrorResponse::Unauthorized)?; + let enable_partial_auth = state.conf().api_keys.get_inner().enable_partial_auth; - let auth_data_v2 = AuthenticationData { - merchant_account: auth_data.merchant_account, - key_store: auth_data.key_store, - profile, - }; - Ok((auth_data_v2, auth_type)) + match enable_partial_auth { + true => self.0.authenticate_and_fetch(request_headers, state).await, + false => { + let auth = self + .0 + .authenticate_and_fetch(request_headers, state) + .await?; + Ok(auth) + } + } } }