Issue:
Bug: populate `profile_id` in for the HeaderAuth of v1



populate `profile_id` in for the HeaderAuth of v1

Pull request description:
## Type of Change
<!-- Put an `x` in the boxes that apply -->

- [x] Bugfix
- [ ] New feature
- [ ] Enhancement
- [ ] Refactoring
- [ ] Dependency updates
- [ ] Documentation
- [ ] CI/CD

## Description
<!-- Describe your changes in detail -->
populate `profile_id` in for the HeaderAuth of v1
And also this pr involves the changes to unmask the profile id that is sent in the headers.

### Additional Changes

- [ ] This PR modifies the API contract
- [ ] This PR modifies the database schema
- [ ] This PR modifies application configuration/environment variables

<!--
Provide links to the files with corresponding changes.

Following are the paths where you can find config files:
1. `config`
2. `crates/router/src/configs`
3. `loadtest/config`
-->


## Motivation and Context
<!--
Why is this change required? What problem does it solve?
If it fixes an open issue, please link to the issue here.

If you don't have an issue, we'd recommend starting with one first so the PR
can focus on the implementation (unless it is an obvious bug or documentation fix
that will have little conversation).
-->


## How did you test it?
<!--
Did you write an integration/unit/API test to verify the code changes?
Or did you test this change manually (provide relevant screenshots)?
-->


## Checklist
<!-- Put an `x` in the boxes that apply -->

- [x] I formatted the code `cargo +nightly fmt --all`
- [x] I addressed lints thrown by `cargo clippy`
- [x] I reviewed the submitted code
- [ ] I added unit tests for my changes where possible


Testing:

Patch:
diff --git a/config/deployments/integration_test.toml b/config/deployments/integration_test.toml
index dd4938d8d6f..6283382258a 100644
--- a/config/deployments/integration_test.toml
+++ b/config/deployments/integration_test.toml
@@ -419,7 +419,7 @@ outgoing_enabled = true
 connectors_with_webhook_source_verification_call = "paypal"         # List of connectors which has additional source verification api-call
 
 [unmasked_headers]
-keys = "accept-language,user-agent"
+keys = "accept-language,user-agent,x-profile-id"
 
 [saved_payment_methods]
 sdk_eligible_payment_methods = "card"
diff --git a/config/deployments/production.toml b/config/deployments/production.toml
index 9ad4f90b71f..3537834fd07 100644
--- a/config/deployments/production.toml
+++ b/config/deployments/production.toml
@@ -435,7 +435,7 @@ outgoing_enabled = true
 connectors_with_webhook_source_verification_call = "paypal"     # List of connectors which has additional source verification api-call
 
 [unmasked_headers]
-keys = "accept-language,user-agent"
+keys = "accept-language,user-agent,x-profile-id"
 
 [saved_payment_methods]
 sdk_eligible_payment_methods = "card"
diff --git a/config/deployments/sandbox.toml b/config/deployments/sandbox.toml
index d2132cd1e40..fcfadb339d9 100644
--- a/config/deployments/sandbox.toml
+++ b/config/deployments/sandbox.toml
@@ -437,7 +437,7 @@ outgoing_enabled = true
 connectors_with_webhook_source_verification_call = "paypal"        # List of connectors which has additional source verification api-call
 
 [unmasked_headers]
-keys = "accept-language,user-agent"
+keys = "accept-language,user-agent,x-profile-id"
 
 [saved_payment_methods]
 sdk_eligible_payment_methods = "card"
diff --git a/config/development.toml b/config/development.toml
index d157894ac76..4c9b8516b5a 100644
--- a/config/development.toml
+++ b/config/development.toml
@@ -768,7 +768,7 @@ enabled = true
 file_storage_backend = "file_system"
 
 [unmasked_headers]
-keys = "accept-language,user-agent"
+keys = "accept-language,user-agent,x-profile-id"
 
 [opensearch]
 host = "https://localhost:9200"
diff --git a/config/docker_compose.toml b/config/docker_compose.toml
index 3bbb1106350..75699d0a967 100644
--- a/config/docker_compose.toml
+++ b/config/docker_compose.toml
@@ -609,7 +609,7 @@ source = "logs"
 file_storage_backend = "file_system"
 
 [unmasked_headers]
-keys = "accept-language,user-agent"
+keys = "accept-language,user-agent,x-profile-id"
 
 [opensearch]
 host = "https://opensearch:9200"
diff --git a/crates/router/src/services/authentication.rs b/crates/router/src/services/authentication.rs
index d35e321a7be..99800b55512 100644
--- a/crates/router/src/services/authentication.rs
+++ b/crates/router/src/services/authentication.rs
@@ -666,6 +666,13 @@ where
             metrics::PARTIAL_AUTH_FAILURE.add(1, &[]);
         };
 
+        let profile_id = HeaderMapStruct::new(request_headers)
+            .get_id_type_from_header_if_present::<id_type::ProfileId>(headers::X_PROFILE_ID)
+            .change_context(errors::ValidationError::IncorrectValueProvided {
+                field_name: "X-Profile-Id",
+            })
+            .change_context(errors::ApiErrorResponse::Unauthorized)?;
+
         let payload = ExtractedPayload::from_headers(request_headers)
             .and_then(|value| {
                 let (algo, secret) = state.get_detached_auth()?;
@@ -687,8 +694,13 @@ where
                     merchant_id: Some(merchant_id),
                     key_id: Some(key_id),
                 } => {
-                    let auth =
-                        construct_authentication_data(state, &merchant_id, request_headers).await?;
+                    let auth = construct_authentication_data(
+                        state,
+                        &merchant_id,
+                        request_headers,
+                        profile_id,
+                    )
+                    .await?;
                     Ok((
                         auth.clone(),
                         AuthenticationType::ApiKey {
@@ -702,8 +714,13 @@ where
                     merchant_id: Some(merchant_id),
                     key_id: None,
                 } => {
-                    let auth =
-                        construct_authentication_data(state, &merchant_id, request_headers).await?;
+                    let auth = construct_authentication_data(
+                        state,
+                        &merchant_id,
+                        request_headers,
+                        profile_id,
+                    )
+                    .await?;
                     Ok((
                         auth.clone(),
                         AuthenticationType::PublishableKey {
@@ -779,6 +796,7 @@ async fn construct_authentication_data<A>(
     state: &A,
     merchant_id: &id_type::MerchantId,
     request_headers: &HeaderMap,
+    profile_id: Option<id_type::ProfileId>,
 ) -> RouterResult<AuthenticationData>
 where
     A: SessionStateInfo + Sync,
@@ -830,7 +848,7 @@ where
         merchant_account: merchant,
         platform_merchant_account,
         key_store,
-        profile_id: None,
+        profile_id,
     };
 
     Ok(auth)
diff --git a/loadtest/config/development.toml b/loadtest/config/development.toml
index 64d0526d147..ec58ab08b87 100644
--- a/loadtest/config/development.toml
+++ b/loadtest/config/development.toml
@@ -396,7 +396,7 @@ client_secret = ""
 partner_id = ""
 
 [unmasked_headers]
-keys = "accept-language,user-agent"
+keys = "accept-language,user-agent,x-profile-id"
 
 [multitenancy]
 enabled = false