Skip to content

Conversation

@isaaclins
Copy link
Owner

This pull request introduces significant improvements to the OAuth authentication and token refresh flow, enhances user feedback and error handling for authentication failures, and adds a new controller for global keybinds. The changes ensure that expired or invalid OAuth tokens are properly detected, cleared, and that the user is prompted to re-authenticate, resulting in a more robust and user-friendly authentication experience. Additionally, a new KeybindsController centralizes keybind action handling and user feedback.

OAuth authentication and token refresh improvements:

  • Updated the OAuth client setup in psst-core/src/oauth.rs to use AuthType::RequestBody, ensuring that the client_id is included in the body for PKCE flows, as required by Spotify, both for initial authentication and token refresh. Improved logging and error handling during token refresh. [1] [2] [3]
  • On startup, the application now attempts to refresh the OAuth token if a refresh token is available. If the refresh fails, all tokens and credentials are cleared, and the user is prompted to log in again. If only an access token is present, it is used as a fallback. [1] [2]

Session expiration and re-authentication handling:

  • Implemented a new OAUTH_AUTH_REQUIRED command and associated logic in the delegate and Web API client. When token refresh fails or is not possible, the application clears all authentication data and notifies the user to re-authenticate, ensuring the UI reflects the expired session state. [1] [2] [3] [4]
  • Improved logout and reset logic to avoid blocking the UI thread, and clarified session cleanup behavior.

Keybinds and user feedback:

  • Added a new KeybindsController in psst-gui/src/controller/keybinds.rs to centralize handling of global keybind actions, including playback, navigation, UI controls, and queue behavior. Provides user feedback for relevant actions (e.g., volume changes, queue mode switches).

These changes collectively improve the reliability of authentication, enhance the user experience during session expiration, and provide a more maintainable architecture for handling keybinds and user actions.

- Add AuthType::RequestBody to OAuth client for PKCE compliance
- Spotify requires client_id in request body (not Basic auth header) for PKCE flow
- Add OAUTH_AUTH_REQUIRED command to handle expired session gracefully
- Improve error logging for OAuth refresh failures
- WebApi client now emits re-auth command when token refresh fails
Previously, OAUTH_AUTH_REQUIRED only showed an error but didn't clear
the invalid tokens from config. This caused an infinite error loop on
restart as the old invalid tokens would be reloaded.
The session.shutdown() method calls worker.join() which blocks the UI
thread, causing the app to freeze during logout. Removed the blocking
call - session cleanup happens naturally on new login or app exit.
When OAuth token refresh fails at startup (e.g., revoked token), now
properly clears credentials and tokens so user sees login screen
instead of falling back to invalid tokens that cause repeated errors.
@isaaclins isaaclins marked this pull request as ready for review December 2, 2025 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants