customers: Added ephemeral key authentication for customer retrieve (#89)

This commit is contained in:
Kartikeya Hegde
2022-12-09 17:58:04 +05:30
committed by GitHub
parent 2aef3bccfb
commit 3d7d89172c
21 changed files with 214 additions and 41 deletions

View File

@ -31,7 +31,7 @@ use crate::{
storage::{self, enums},
ErrorResponse, Response,
},
utils::OptionExt,
utils::{self, OptionExt},
};
pub type BoxedConnectorIntegration<'a, T, Req, Resp> =
@ -596,6 +596,29 @@ pub(crate) fn get_auth_type_and_check_client_secret(
))
}
pub(crate) async fn authenticate_eph_key<'a>(
req: &'a actix_web::HttpRequest,
store: &dyn StorageInterface,
customer_id: String,
) -> RouterResult<MerchantAuthentication<'a>> {
let api_key = get_api_key(req)?;
if api_key.starts_with("epk") {
let ek = store
.get_ephemeral_key(api_key)
.await
.change_context(errors::ApiErrorResponse::BadCredentials)?;
utils::when(
ek.customer_id.ne(&customer_id),
Err(report!(errors::ApiErrorResponse::InvalidEphermeralKey)),
)?;
Ok(MerchantAuthentication::MerchantId(Cow::Owned(
ek.merchant_id,
)))
} else {
Ok(MerchantAuthentication::ApiKey)
}
}
fn get_api_key(req: &HttpRequest) -> RouterResult<&str> {
req.headers()
.get("api-key")