wheresfrank / voterr

Voting through your Plex movies to watch with your friends
GNU General Public License v3.0
23 stars 1 forks source link

Rework auth with more information and a constant client id #2

Closed wheresfrank closed 2 months ago

wheresfrank commented 2 months ago

PlexAuthController Refactor and Improvements

This pull request introduces significant improvements to the PlexAuthController, enhancing its reliability, error handling, and overall functionality for Plex authentication.

Key Changes

  1. Consistent API Calls: Introduced a unified plex_request method for all Plex API interactions, ensuring consistent headers and error handling across all requests.
  2. JSON Parsing: Updated all methods to use JSON parsing instead of XML, aligning with Plex API's preferred response format.
  3. Rate Limiting Handling: Implemented an exponential backoff strategy in the generate_plex_pin method to handle Plex API rate limiting (HTTP 429 errors).
  4. Improved Error Handling: Added comprehensive error handling and logging throughout the controller, including specific handling for JSON parsing errors.
  5. Consistent Client Identifier: Introduced a VOTERR_CLIENT_ID constant, ensuring a consistent client identifier is used across all Plex interactions.
  6. Enhanced Plex Auth URL Generation: Updated the plex_auth_url method to include all necessary parameters and headers required by the Plex OAuth flow.
  7. Robust Callback Handling: Refactored the callback method to handle potential nil returns from user data and server ID fetching operations.
  8. Logging Improvements: Added detailed logging throughout the authentication process for better debugging and monitoring.

Impact

These changes address several issues:

Testing

The updated controller has been tested locally with the following scenarios: