spotify: fix credentials cache

Cache Spotify response instead of username and password.
This should resolve frequent "New login to Spotify" emails.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1183>
This commit is contained in:
John King 2023-04-15 20:24:44 +00:00 committed by Guillaume Desmottes
parent cc3646640e
commit 2bd2e501d9

View file

@ -131,29 +131,37 @@ impl Settings {
let cache = Cache::new(credentials_cache, None, files_cache, max_size)?; let cache = Cache::new(credentials_cache, None, files_cache, max_size)?;
let credentials = match cache.credentials() { if let Some(cached_cred) = cache.credentials() {
Some(cached_cred) => { gst::debug!(cat, obj: &src, "reuse credentials from cache",);
gst::debug!(cat, obj: &src, "reuse credentials from cache",); if let Ok((session, _credentials)) = Session::connect(
cached_cred SessionConfig::default(),
cached_cred,
Some(cache.clone()),
true,
)
.await
{
return Ok(session);
} }
None => { }
gst::debug!(cat, obj: &src, "credentials not in cache",);
if self.username.is_empty() { gst::debug!(
bail!("username is not set and credentials are not in cache"); cat,
} obj: &src,
if self.password.is_empty() { "credentials not in cache or cached credentials invalid",
bail!("password is not set and credentials are not in cache"); );
}
let cred = Credentials::with_password(&self.username, &self.password); if self.username.is_empty() {
cache.save_credentials(&cred); bail!("username is not set and credentials are not in cache");
cred }
} if self.password.is_empty() {
}; bail!("password is not set and credentials are not in cache");
}
let cred = Credentials::with_password(&self.username, &self.password);
let (session, _credentials) = let (session, _credentials) =
Session::connect(SessionConfig::default(), credentials, Some(cache), false).await?; Session::connect(SessionConfig::default(), cred, Some(cache), true).await?;
Ok(session) Ok(session)
} }