feat: improve Login5 authentication with token renewal #1

Open
ermitovski wants to merge 1 commit from ermitovski/librespot-spotizerr:improve-login5-implementation into main
First-time contributor

Hi, this is related with spotizerr/spotizerr#5 and inspired from a librespot-python PR.
I don't want to link it here as I think this was the trigger of the takedown from github

As from the initial PR when we introduced the login5 change, this is full vibe coding, and maybe the spotizerr project needs some update after this.

Summary:

  • Move Login5 logic to TokenProvider class for better organization
  • Add automatic token renewal with 10-second expiration buffer
  • Implement proper token caching with scope tracking
  • Add comprehensive error handling and logging
  • Support thread-safe credential access with timeouts
  • Add Login5 token retrieval for different scopes
  • Fix protobuf imports and file organization
  • Enhance zeroconf authentication flow with better error handling
  • Update tests to properly validate Login5 functionality
Hi, this is related with https://lavaforge.org/spotizerr/spotizerr/issues/5 and inspired from a librespot-python PR. I don't want to link it here as I think this was the trigger of the takedown from github As from the initial PR when we introduced the login5 change, this is full vibe coding, and maybe the spotizerr project needs some update after this. Summary: - Move Login5 logic to TokenProvider class for better organization - Add automatic token renewal with 10-second expiration buffer - Implement proper token caching with scope tracking - Add comprehensive error handling and logging - Support thread-safe credential access with timeouts - Add Login5 token retrieval for different scopes - Fix protobuf imports and file organization - Enhance zeroconf authentication flow with better error handling - Update tests to properly validate Login5 functionality
- Move Login5 logic to TokenProvider class for better organization
- Add automatic token renewal with 10-second expiration buffer
- Implement proper token caching with scope tracking
- Add comprehensive error handling and logging
- Support thread-safe credential access with timeouts
- Add Login5 token retrieval for different scopes
- Fix protobuf imports and file organization
- Enhance zeroconf authentication flow with better error handling
- Update tests to properly validate Login5 functionality
First-time contributor

can we merge this PR?

can we merge this PR?
First-time contributor

@GSKang94 wrote in #1 (comment):

can we merge this PR?

as far as I understand, the original dev isn't involved at all anymore, so if we wanted to merge it we'd have to merge it in a fork. I see you have one, so maybe we can copy this PR over there and merge.

@GSKang94 wrote in https://lavaforge.org/spotizerr/librespot-spotizerr/pulls/1#issuecomment-205: > can we merge this PR? as far as I understand, the original dev isn't involved at all anymore, so if we wanted to merge it we'd have to merge it in a fork. I see you have one, so maybe we can copy this PR over there and merge.
First-time contributor

It is technically possible to use this PR without it being merged if you enter the following into your compose file volume section:

  - ./custom_files/core.py:/python/librespot/core.py
  - ./custom_files/Login5_pb2.py:/python/librespot/proto/spotify/login5/v3/Login5_pb2.py
  - ./custom_files/zeroconf.py:/python/librespot/zeroconf.py
  - ./custom_files/Identifiers_pb2.py:/python/librespot/proto/spotify/login5/v3/identifiers/Identifiers_pb2.py

Download the four main files modified in the PR and put them into a "custom_files" folder in the same directory as compose. This has worked for me for about a week so far.

It is technically possible to use this PR without it being merged if you enter the following into your compose file volume section: - ./custom_files/core.py:/python/librespot/core.py - ./custom_files/Login5_pb2.py:/python/librespot/proto/spotify/login5/v3/Login5_pb2.py - ./custom_files/zeroconf.py:/python/librespot/zeroconf.py - ./custom_files/Identifiers_pb2.py:/python/librespot/proto/spotify/login5/v3/identifiers/Identifiers_pb2.py Download the four main files modified in the PR and put them into a "custom_files" folder in the same directory as compose. This has worked for me for about a week so far.
First-time contributor

That worked! thanks @mcn18

That worked! thanks @mcn18
First-time contributor

Implementing this doesn't seem to work. I get continual logs like this with failed downloads:

2025-11-12 06:50:35 [DEBUG] Starting new HTTPS connection (1): apresolve.spotify.com:443
2025-11-12 06:50:36 [DEBUG] https://apresolve.spotify.com:443 "GET /?type=spclient HTTP/1.1" 200 None
2025-11-12 06:50:36 [DEBUG] Starting initial Login5 authentication process...
2025-11-12 06:50:36 [DEBUG] Requesting Login5 token for scopes: ['playlist-read', 'user-read-private', 'user-read-playback-state']
2025-11-12 06:50:39 [WARNING] ap_welcome() call timed out
2025-11-12 06:50:39 [ERROR] Initial Login5 authentication failed

Has there been a breaking change to spotify authentication or something?

Version 3.3.0 doesn't have this particular issue, but 3.3.0 seems to randomly expire/fail every hour or so and requires a restart..?

(unrelated to the recent extended metadata issue as I have patched that)

Implementing this doesn't seem to work. I get continual logs like this with failed downloads: 2025-11-12 06:50:35 [DEBUG] Starting new HTTPS connection (1): apresolve.spotify.com:443 2025-11-12 06:50:36 [DEBUG] https://apresolve.spotify.com:443 "GET /?type=spclient HTTP/1.1" 200 None 2025-11-12 06:50:36 [DEBUG] Starting initial Login5 authentication process... 2025-11-12 06:50:36 [DEBUG] Requesting Login5 token for scopes: ['playlist-read', 'user-read-private', 'user-read-playback-state'] 2025-11-12 06:50:39 [WARNING] ap_welcome() call timed out 2025-11-12 06:50:39 [ERROR] Initial Login5 authentication failed Has there been a breaking change to spotify authentication or something? Version 3.3.0 doesn't have this particular issue, but 3.3.0 seems to randomly expire/fail every hour or so and requires a restart..? (unrelated to the recent extended metadata issue as I have patched that)
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u improve-login5-implementation:ermitovski-improve-login5-implementation
git switch ermitovski-improve-login5-implementation

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch main
git merge --no-ff ermitovski-improve-login5-implementation
git switch ermitovski-improve-login5-implementation
git rebase main
git switch main
git merge --ff-only ermitovski-improve-login5-implementation
git switch ermitovski-improve-login5-implementation
git rebase main
git switch main
git merge --no-ff ermitovski-improve-login5-implementation
git switch main
git merge --squash ermitovski-improve-login5-implementation
git switch main
git merge --ff-only ermitovski-improve-login5-implementation
git switch main
git merge ermitovski-improve-login5-implementation
git push origin main
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
spotizerr/librespot-spotizerr!1
No description provided.