Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

feat(users): use cookie for auth (#4434)

Rachit Naithanib2b9fab31dc8
diff --git a/crates/router/src/services/authentication.rs b/crates/router/src/services/authentication.rs
index 5203b20c55..03db3987ea 100644
--- a/crates/router/src/services/authentication.rs
+++ b/crates/router/src/services/authentication.rs
@@ -611,19 +611,17 @@ where
T: serde::de::DeserializeOwned,
A: AppStateInfo + Sync,
{
- let token = get_jwt_from_authorization_header(headers)?;
- if let Some(token_from_cookies) = get_cookie_from_header(headers)
- .ok()
- .and_then(|cookies| cookies::parse_cookie(cookies).ok())
- {
- logger::info!(
- "Cookie header and authorization header JWT comparison result: {}",
- token == token_from_cookies
- );
- }
- let payload = decode_jwt(token, state).await?;
-
- Ok(payload)
+ let token = match get_cookie_from_header(headers).and_then(cookies::parse_cookie) {
+ Ok(cookies) => cookies,
+ Err(e) => {
+ let token = get_jwt_from_authorization_header(headers);
+ if token.is_err() {
+ logger::error!(?e);
+ }
+ token?.to_owned()
+ }
+ };
+ decode_jwt(&token, state).await
}
#[async_trait]
@@ -949,6 +947,9 @@ pub async fn is_ephemeral_auth<A: AppStateInfo + Sync>(
pub fn is_jwt_auth(headers: &HeaderMap) -> bool {
headers.get(crate::headers::AUTHORIZATION).is_some()
+ || get_cookie_from_header(headers)
+ .and_then(cookies::parse_cookie)
+ .is_ok()
}
pub async fn decode_jwt<T>(token: &str, state: &impl AppStateInfo) -> RouterResult<T>