Skip to content

Commit

Permalink
refactor: Refcatored to use publishible_key auth as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarthak1799 committed Dec 16, 2024
1 parent 631a628 commit 8206b9c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crates/router/src/routes/payment_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub async fn confirm_payment_method_intent_api(
let pm_id = path.into_inner();
let payload = json_payload.into_inner();

let auth = match auth::is_ephemeral_auth(req.headers()) {
let auth = match auth::is_ephemeral_or_publishible_auth(req.headers()) {
Ok(auth) => auth,
Err(e) => return api::log_and_return_error_response(e),
};
Expand Down Expand Up @@ -190,7 +190,7 @@ pub async fn payment_method_update_api(
let payment_method_id = path.into_inner();
let payload = json_payload.into_inner();

let auth = match auth::is_ephemeral_auth(req.headers()) {
let auth = match auth::is_ephemeral_or_publishible_auth(req.headers()) {
Ok(auth) => auth,
Err(e) => return api::log_and_return_error_response(e),
};
Expand Down
14 changes: 14 additions & 0 deletions crates/router/src/services/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3099,6 +3099,20 @@ where
}
}

pub fn is_ephemeral_or_publishible_auth<A: SessionStateInfo + Sync + Send>(
headers: &HeaderMap,
) -> RouterResult<Box<dyn AuthenticateAndFetch<AuthenticationData, A>>> {
let api_key = get_api_key(headers)?;

if api_key.starts_with("epk") {
Ok(Box::new(EphemeralKeyAuth))
} else if api_key.starts_with("pk_") {
Ok(Box::new(HeaderAuth(PublishableKeyAuth)))
} else {
Ok(Box::new(HeaderAuth(ApiKeyAuth)))
}
}

pub fn is_ephemeral_auth<A: SessionStateInfo + Sync + Send>(
headers: &HeaderMap,
) -> RouterResult<Box<dyn AuthenticateAndFetch<AuthenticationData, A>>> {
Expand Down

0 comments on commit 8206b9c

Please sign in to comment.