Skip to content

Plex: announce a stable client identity to plex.tv#4217

Open
anatosun wants to merge 2 commits into
music-assistant:devfrom
anatosun:plex/auth-identity
Open

Plex: announce a stable client identity to plex.tv#4217
anatosun wants to merge 2 commits into
music-assistant:devfrom
anatosun:plex/auth-identity

Conversation

@anatosun

@anatosun anatosun commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

What does this implement/fix?

plexapi defaults the X-Plex-Client-Identifier to the machine's MAC address and the device name to the hostname. Plex binds OAuth tokens to the client identifier, and the MAC address is unstable in containers, so stored tokens could be rejected after a restart.

Pin plexapi's process-global identity to Music Assistant's persistent server id and announce 'Music Assistant' as product/device name, both before the OAuth pin login (config flow) and at provider setup. The pin login no longer needs its own headers override, and the provider session reuses the shared PLEX_PRODUCT constant.

Types of changes

  • Bugfix (non-breaking change which fixes an issue) — bugfix
  • New feature (non-breaking change which adds functionality) — new-feature
  • Enhancement to an existing feature — enhancement
  • New music/player/metadata/plugin provider — new-provider
  • Breaking change (fix or feature that would cause existing functionality to not work as expected) — breaking-change
  • Refactor (no behaviour change) — refactor
  • Documentation only — documentation
  • Maintenance / chore — maintenance
  • CI / workflow change — ci
  • Dependencies bump — dependencies

Checklist

  • The code change is tested and works locally.
  • pre-commit run --all-files passes.
  • pytest passes, and tests have been added/updated under tests/ where applicable.
  • For changes to shared models, the companion PR in music-assistant/models is linked.
  • For changes affecting the UI, the companion PR in music-assistant/frontend is linked.
  • I have read and complied with the project's AI Policy for any AI-assisted contributions.
  • I have raised a PR against the documentation repository targeting the main or beta branch as appropriate.

plexapi defaults the X-Plex-Client-Identifier to the machine's MAC address
and the device name to the hostname. Plex binds OAuth tokens to the client
identifier, and the MAC address is unstable in containers, so stored tokens
could be rejected after a restart.

Pin plexapi's process-global identity to Music Assistant's persistent
server id and announce 'Music Assistant' as product/device name, both
before the OAuth pin login (config flow) and at provider setup. The pin
login no longer needs its own headers override, and the provider session
reuses the shared PLEX_PRODUCT constant.
Copilot AI review requested due to automatic review settings June 14, 2026 17:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR standardizes the Plex client identity sent by plexapi so Plex OAuth tokens remain valid across restarts (especially in containerized environments).

Changes:

  • Introduces a process-global Plex identity configuration helper that pins product/device name and client identifier.
  • Adds a PLEX_PRODUCT constant and replaces hardcoded "Music Assistant" header values with it.
  • Removes per-call MyPlexPinLogin header overrides and relies on the configured plexapi defaults.

Reviewed changes

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

File Description
music_assistant/providers/plex/helpers.py Adds configure_plex_identity to set plexapi global identity headers/fields.
music_assistant/providers/plex/constants.py Introduces PLEX_PRODUCT constant for consistent client identity strings.
music_assistant/providers/plex/__init__.py Calls identity configuration before auth/connection; replaces hardcoded header values with PLEX_PRODUCT.

Comment thread music_assistant/providers/plex/__init__.py
Comment thread music_assistant/providers/plex/__init__.py
Comment thread music_assistant/providers/plex/helpers.py
@OzGav

OzGav commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

@anatosun if you can resolve the copilot comments we will move this along

@marcelveldt

Copy link
Copy Markdown
Member

Comments have been resolved without any code changes been made or a reasoning why it hasn't been addressed. Only resolve comments if you adjusted the code and fixed the review comment OR you provided reasoning why it was invalid.

plexapi rebuilds request headers from BASE_HEADERS on every query, so the
session-level X-Plex-Client-Identifier was overridden by the global identity
(server_id) set in configure_plex_identity() and never reached the wire. Remove
the misleading line so the connection identifies as server_id everywhere.
@anatosun

Copy link
Copy Markdown
Contributor Author

I was gaslighted many times by Copilot, so I did not take its comments very seriously, sorry for that. One was actually relevant and fixed in a commit.

@marcelveldt

Copy link
Copy Markdown
Member

I was gaslighted many times by Copilot, so I did not take its comments very seriously, sorry for that. One was actually relevant and fixed in a commit.

It is right 80% of the time and sometimes its wrong. At least good to see what it flags and either dismiss it (and leave a comment why) or fix it and reply that its fixed.


# Identity announced to Plex / plex.tv. Without this, plexapi falls back to the host
# machine's name (e.g. in the plex.tv "authorized devices" list and during auth).
PLEX_PRODUCT: Final = "Music Assistant"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Might be better to just use the existing APPLICATION_NAME constant from MA constants.py?

plexapi.X_PLEX_DEVICE_NAME = PLEX_PRODUCT
plexapi.BASE_HEADERS["X-Plex-Product"] = PLEX_PRODUCT
plexapi.BASE_HEADERS["X-Plex-Device-Name"] = PLEX_PRODUCT
if client_id:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could this ever be false?

from music_assistant.mass import MusicAssistant


def configure_plex_identity(client_id: str) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Because the identity is set in plexapi's process-global state and always with mass.server_id, every Plex provider instance now advertises the same X-Plex-Client-Identifier. Is that OK with multiple instances?

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.

4 participants