diff --git a/package.spec b/package.spec index c4487a1..e1867b5 100644 --- a/package.spec +++ b/package.spec @@ -1,4 +1,4 @@ -%define _version 0.3.1 +%define _version 0.3.2 %define _release 1 Name: jamjar diff --git a/src/jamjar/__init__.py b/src/jamjar/__init__.py index 54bcc05..40ab32e 100644 --- a/src/jamjar/__init__.py +++ b/src/jamjar/__init__.py @@ -7,7 +7,7 @@ syncing, exporting, and managing playlists in the JamJar database. """ -__version__ = "0.3.1" +__version__ = "0.3.2" import json import os diff --git a/src/jamjar/cli/auth.py b/src/jamjar/cli/auth.py index c836dc0..7faf84e 100644 --- a/src/jamjar/cli/auth.py +++ b/src/jamjar/cli/auth.py @@ -144,8 +144,12 @@ def refresh_token(self): response = requests.post(self.token_url, data=body, timeout=10) response.raise_for_status() new_token_info = response.json() + new_token_info["refresh_token"] = token_info["refresh_token"] new_token_info["expires_at"] = datetime.now().timestamp() + new_token_info["expires_in"] + + self.verify_token(new_token_info) self.save_token(new_token_info) + return new_token_info except requests.exceptions.RequestException as e: @@ -155,6 +159,20 @@ def refresh_token(self): print(f"Error refreshing token: {e}") raise + def verify_token(self, token_info): + """Verifies the validity of the access token.""" + try: + headers = {"Authorization": f"Bearer {token_info['access_token']}"} + response = requests.get("https://api.spotify.com/v1/me", headers=headers, timeout=10) + if response.status_code != 200: + raise RuntimeError("Token verification failed. Please log in again.") + except requests.exceptions.RequestException as e: + print(f"Error verifying token: {e}") + raise + except Exception as e: + print(f"Error processing token verification response: {e}") + raise + def save_token(self, token_info): """Saves token info to a file.""" try: