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