Skip to content

Commit 35912e8

Browse files
committed
only update OAuth refresh_token if present in refresh response
credential formation from ap_welcome spun off into separate Session function version bump v0.0.13
1 parent 7a89401 commit 35912e8

4 files changed

Lines changed: 22 additions & 20 deletions

File tree

librespot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
class Version:
9-
version_name = "0.0.12"
9+
version_name = "0.0.13"
1010

1111
@staticmethod
1212
def platform() -> Platform:

librespot/core.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,20 @@ def create_client(conf: Configuration) -> requests.Session:
11791179
client = requests.Session()
11801180
return client
11811181

1182+
def credentials(self) -> dict:
1183+
ap_welcome = self.ap_welcome()
1184+
reusable = ap_welcome.reusable_auth_credentials
1185+
reusable_type = Authentication.AuthenticationType.Name(
1186+
ap_welcome.reusable_auth_credentials_type)
1187+
return {
1188+
"username":
1189+
ap_welcome.canonical_username,
1190+
"credentials":
1191+
base64.b64encode(reusable).decode(),
1192+
"type":
1193+
reusable_type,
1194+
}
1195+
11821196
def dealer(self) -> DealerClient:
11831197
""" """
11841198
self.__wait_auth_lock()
@@ -1375,28 +1389,15 @@ def __authenticate_partial(self,
13751389
self.__auth_lock_bool = False
13761390
self.__auth_lock.notify_all()
13771391
if self.__inner.conf.store_credentials:
1378-
reusable = self.__ap_welcome.reusable_auth_credentials
1379-
reusable_type = Authentication.AuthenticationType.Name(
1380-
self.__ap_welcome.reusable_auth_credentials_type)
1392+
self.__stored_str = base64.b64encode(
1393+
json.dumps(self.credentials()).encode()
1394+
).decode()
13811395
if self.__inner.conf.stored_credentials_file is None:
13821396
raise TypeError(
13831397
"The file path to be saved is not specified")
1384-
self.__stored_str = base64.b64encode(
1385-
json.dumps({
1386-
"username":
1387-
self.__ap_welcome.canonical_username,
1388-
"credentials":
1389-
base64.b64encode(reusable).decode(),
1390-
"type":
1391-
reusable_type,
1392-
}).encode()).decode()
13931398
with open(self.__inner.conf.stored_credentials_file, "w") as f:
13941399
json.dump(
1395-
{
1396-
"username": self.__ap_welcome.canonical_username,
1397-
"credentials": base64.b64encode(reusable).decode(),
1398-
"type": reusable_type,
1399-
},
1400+
self.credentials(),
14001401
f,
14011402
)
14021403

librespot/oauth.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ def set_listen_all(self, listen_all: bool):
7373

7474
def ingest_token_response(self, result):
7575
self.__token = result["access_token"]
76-
self.__refresh_token = result["refresh_token"]
76+
if "refresh_token" in result:
77+
self.__refresh_token = result["refresh_token"]
7778
if "expires_in" in result:
7879
self.__token_expires_at = datetime.now() + timedelta(seconds=result["expires_in"])
7980
elif "expires_at" in result:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import setuptools
22

33
setuptools.setup(name="librespot",
4-
version="0.0.12",
4+
version="0.0.13",
55
description="Open Source Spotify Client",
66
long_description=open("README.md").read(),
77
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)