Add switchHomeUser method to PlexServer#1599
Add switchHomeUser method to PlexServer#1599JonnyWong16 wants to merge 9 commits intopushingkarmaorg:masterfrom
Conversation
There was a problem hiding this comment.
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 toswitchHomeUser(). - Add
PlexServer.switchHomeUser()that switches to a Plex Home user viaMyPlexAccount.switchHomeUser()and server resource access tokens. - Update
Playlist.copyToUser()to useswitchHomeUser()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.
There was a problem hiding this comment.
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 theuserparameter can be a user id, but the implementation now delegates toswitchHomeUser(), 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.
There was a problem hiding this comment.
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 callsswitchHomeUser()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.
|
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: 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! |
Description
Ref.: https://forums.plex.tv/t/information-related-to-security-vulnerabilities/935164/24
PlexServer.swichUser()method.PlexServer.switchHomeUser()method.Playlist.copyToUser()to useswitchHomeUser().Fixes #1598
Type of change
Please delete options that are not relevant.
Checklist: