mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 12:15:40 +08:00
feat(users): use cookie for auth (#4434)
This commit is contained in:
@ -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>
|
||||
|
||||
Reference in New Issue
Block a user