spotify: check cached creds username before use

If a username was specified, only use cached credentials that match
that username.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1192>
This commit is contained in:
Nick Steel 2023-04-23 22:16:40 +01:00 committed by kingosticks
parent 8d6751c88d
commit 3d01c9b363

View file

@ -132,16 +132,31 @@ impl Settings {
let cache = Cache::new(credentials_cache, None, files_cache, max_size)?; let cache = Cache::new(credentials_cache, None, files_cache, max_size)?;
if let Some(cached_cred) = cache.credentials() { if let Some(cached_cred) = cache.credentials() {
gst::debug!(cat, obj: &src, "reuse credentials from cache",); if !self.username.is_empty() && self.username != cached_cred.username {
if let Ok((session, _credentials)) = Session::connect( gst::debug!(
SessionConfig::default(), cat,
cached_cred, obj: &src,
Some(cache.clone()), "ignore cached credentials for user {} which mismatch user {}",
true, cached_cred.username,
) self.username
.await );
{ } else {
return Ok(session); gst::debug!(
cat,
obj: &src,
"reuse cached credentials for user {}",
cached_cred.username
);
if let Ok((session, _credentials)) = Session::connect(
SessionConfig::default(),
cached_cred,
Some(cache.clone()),
true,
)
.await
{
return Ok(session);
}
} }
} }