Skip to content

Commit

Permalink
Fix the save credentials not working
Browse files Browse the repository at this point in the history
  • Loading branch information
yuezk committed Oct 28, 2024
1 parent 511cc5e commit 5c6a1c7
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions crates/gpapi/src/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ impl AuthCookieCredential {
pub struct CachedCredential {
username: String,
password: Option<String>,
auth_cookie: AuthCookieCredential,
auth_cookie: Option<AuthCookieCredential>,
}

impl CachedCredential {
pub fn new(username: String, password: Option<String>, auth_cookie: AuthCookieCredential) -> Self {
pub fn new(username: String, password: Option<String>, auth_cookie: Option<AuthCookieCredential>) -> Self {
Self {
username,
password,
Expand All @@ -131,12 +131,12 @@ impl CachedCredential {
self.password.as_deref()
}

pub fn auth_cookie(&self) -> &AuthCookieCredential {
&self.auth_cookie
pub fn auth_cookie(&self) -> Option<&AuthCookieCredential> {
self.auth_cookie.as_ref()
}

pub fn set_auth_cookie(&mut self, auth_cookie: AuthCookieCredential) {
self.auth_cookie = auth_cookie;
self.auth_cookie = Some(auth_cookie);
}

pub fn set_username(&mut self, username: String) {
Expand All @@ -150,11 +150,7 @@ impl CachedCredential {

impl From<PasswordCredential> for CachedCredential {
fn from(value: PasswordCredential) -> Self {
Self::new(
value.username().to_owned(),
Some(value.password().to_owned()),
AuthCookieCredential::new("", "", ""),
)
Self::new(value.username().to_owned(), Some(value.password().to_owned()), None)
}
}
#[derive(Debug, Serialize, Deserialize, Type, Clone)]
Expand Down Expand Up @@ -198,11 +194,16 @@ impl Credential {
Some(cred.prelogon_user_auth_cookie()),
None,
),
// Use the empty string as the password if auth_cookie is present
Credential::Cached(cred) => (
cred.password(),
if cred.auth_cookie.is_some() {
None
} else {
cred.password()
},
None,
Some(cred.auth_cookie.user_auth_cookie()),
Some(cred.auth_cookie.prelogon_user_auth_cookie()),
cred.auth_cookie.as_ref().map(|c| c.user_auth_cookie()),
cred.auth_cookie.as_ref().map(|c| c.prelogon_user_auth_cookie()),
None,
),
};
Expand Down

0 comments on commit 5c6a1c7

Please sign in to comment.