From 516d685c9e4228dc7b9d99d5ae86d021c9d1feb8 Mon Sep 17 00:00:00 2001 From: Kevin Yue Date: Wed, 30 Oct 2024 16:13:20 +0000 Subject: [PATCH] fix: saved credentials not working --- crates/gpapi/src/credential.rs | 6 +----- crates/gpapi/src/portal/config.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/crates/gpapi/src/credential.rs b/crates/gpapi/src/credential.rs index 2438764..acae63e 100644 --- a/crates/gpapi/src/credential.rs +++ b/crates/gpapi/src/credential.rs @@ -196,11 +196,7 @@ impl Credential { ), // Use the empty string as the password if auth_cookie is present Credential::Cached(cred) => ( - if cred.auth_cookie.is_some() { - None - } else { - cred.password() - }, + cred.password(), None, cred.auth_cookie.as_ref().map(|c| c.user_auth_cookie()), cred.auth_cookie.as_ref().map(|c| c.prelogon_user_auth_cookie()), diff --git a/crates/gpapi/src/portal/config.rs b/crates/gpapi/src/portal/config.rs index f775d57..edcc5bb 100644 --- a/crates/gpapi/src/portal/config.rs +++ b/crates/gpapi/src/portal/config.rs @@ -103,6 +103,20 @@ pub async fn retrieve_config(portal: &str, cred: &Credential, gp_params: &GpPara let client = Client::try_from(gp_params)?; let mut params = cred.to_params(); + // Avoid sending the auth cookies for the portal config API if the password is cached + // Otherwise, the portal will return an error even if the password is correct, because + // the auth cookies could have been invalidated and the portal server takes precedence + // over the password + if let Credential::Cached(cache_cred) = cred { + info!("Using cached credentials, excluding auth cookies from the portal config request"); + + if cache_cred.password().is_some() { + params.remove("prelogin-cookie"); + params.remove("portal-userauthcookie"); + params.remove("portal-prelogonuserauthcookie"); + } + } + let extra_params = gp_params.to_params(); params.extend(extra_params);