Skip to content

Add switchHomeUser method to PlexServer#1599

Open
JonnyWong16 wants to merge 9 commits intopushingkarmaorg:masterfrom
JonnyWong16:feature/switchHomeUser
Open

Add switchHomeUser method to PlexServer#1599
JonnyWong16 wants to merge 9 commits intopushingkarmaorg:masterfrom
JonnyWong16:feature/switchHomeUser

Conversation

@JonnyWong16
Copy link
Collaborator

@JonnyWong16 JonnyWong16 commented Mar 26, 2026

Description

Ref.: https://forums.plex.tv/t/information-related-to-security-vulnerabilities/935164/24

  • Deprecates the PlexServer.swichUser() method.
  • Adds a PlexServer.switchHomeUser() method.
  • Updates Playlist.copyToUser() to use switchHomeUser().

Fixes #1598

Type of change

Please delete options that are not relevant.

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated the docstring for new or existing methods
  • I have added tests when applicable

Copilot AI review requested due to automatic review settings March 26, 2026 04:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses upstream Plex.tv changes that stopped providing managed-user tokens by deprecating PlexServer.switchUser() and introducing a new PlexServer.switchHomeUser() flow that switches via Plex Home, and updates playlist copying to use the new method.

Changes:

  • Deprecate PlexServer.switchUser() and route it to switchHomeUser().
  • Add PlexServer.switchHomeUser() that switches to a Plex Home user via MyPlexAccount.switchHomeUser() and server resource access tokens.
  • Update Playlist.copyToUser() to use switchHomeUser() and adjust wording to “Plex Home user”.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
plexapi/server.py Deprecates switchUser() and adds switchHomeUser() to switch via Plex Home.
plexapi/playlist.py Updates copyToUser() to copy to a Plex Home user via switchHomeUser().
plexapi/myplex.py Extends MyPlexAccount.switchHomeUser() to accept session/timeout and clarifies Plex Home wording.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

plexapi/server.py:246

  • The deprecated switchUser() docstring still claims the user parameter can be a user id, but the implementation now delegates to switchHomeUser(), which documents only username/email (and may not support id lookup for many Plex Home users). Update the docstring parameter description to match the actual supported inputs to avoid misleading callers while the method is still present.
        """ Deprecated. Use :meth:`~plexapi.server.PlexServer.switchHomeUser` instead.
            Returns a new :class:`~plexapi.server.PlexServer` object logged in as the given username.
            Note: Only the admin account can switch to other users.

            Parameters:
                user (:class:`~plexapi.myplex.MyPlexUser` or str): `MyPlexUser` object, username,
                    email, or user id of the user to log in to the server.
                session (requests.Session, optional): Use your own session object if you want to

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

Comments suppressed due to low confidence (1)

plexapi/server.py:246

  • The switchUser() docstring still documents switching to any user (including user id) even though the method now calls switchHomeUser() and effectively only supports Plex Home users. Update the parameter docs/wording to reflect the new behavior and avoid misleading callers during the deprecation period.
        """ Deprecated. Use :meth:`~plexapi.server.PlexServer.switchHomeUser` instead.
            Returns a new :class:`~plexapi.server.PlexServer` object logged in as the given username.
            Note: Only the admin account can switch to other users.

            Parameters:
                user (:class:`~plexapi.myplex.MyPlexUser` or str): `MyPlexUser` object, username,
                    email, or user id of the user to log in to the server.
                session (requests.Session, optional): Use your own session object if you want to

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ash32152
Copy link

Hey @JonnyWong16, thanks for jumping on this so quickly! The recent token deprecation completely broke my HA automations, so I pulled down your PR to test it locally for my use case.

The new auth flow works perfectly to grab the Managed User token, but I did find a small TypeError when calling server.switchHomeUser():

TypeError: MyPlexAccount.switchHomeUser() got an unexpected keyword argument 'session'

It looks like in server.py (at line 286), the call passes session and timeout:
userAccount = self.myPlexAccount().switchHomeUser(user, pin=pin, session=session, timeout=timeout)

But the switchHomeUser method inside myplex.py doesn't accept those args. I stripped session and timeout out of that line locally to test it and it successfully returned the token and bypassed the 401 unauthorized I was getting before!!

Thanks again for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

switchUser() throws 401 Unauthorized - Plex.tv API no longer returning Managed User tokens

3 participants