Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(router): populate profile_id in for the HeaderAuth of v1 #6936

Merged
merged 7 commits into from
Dec 26, 2024
30 changes: 25 additions & 5 deletions crates/router/src/services/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,15 @@ where
metrics::PARTIAL_AUTH_FAILURE.add(1, &[]);
};

let profile_id =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use Headermap and this function defined on it get_id_type_from_header_if_present

get_header_value_by_key(headers::X_PROFILE_ID.to_string(), request_headers)?
.map(id_type::ProfileId::from_str)
.transpose()
.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()?;
Expand All @@ -687,8 +696,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 {
Expand All @@ -702,8 +716,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 {
Expand Down Expand Up @@ -779,6 +798,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,
Expand Down Expand Up @@ -830,7 +850,7 @@ where
merchant_account: merchant,
platform_merchant_account,
key_store,
profile_id: None,
profile_id,
};

Ok(auth)
Expand Down
Loading