Skip to content

fix(availability): check shared Plex users with their server token - #748

Open
ncbudd wants to merge 1 commit into
snapetech-org:mainfrom
ncbudd:pr/plex-shared-user-token
Open

ncbudd wants to merge 1 commit into
snapetech-org:mainfrom
ncbudd:pr/plex-shared-user-token

Conversation

@ncbudd

@ncbudd ncbudd commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • The bug: every Plex user who isn't the server owner saw the whole library as missing.
    • The viewer-scoped availability check (mediaServerAvailability) called the Plex server with the user's plex.tv account token.
    • A Plex server only accepts the owner's account token. Each user it is shared with gets a separate token for that server from plex.tv, so the check got 401 and every title fell back to "not available".
  • The fix:
    • PlexTvAPI.getServerAccessToken(machineId) reads /api/resources and returns the accessToken plex.tv issued this account for the configured server, or null when the server isn't listed.
    • It is a separate method so device lists sent to browsers (getDevices) still never carry tokens. Values are length-bounded like the other resource fields.
    • resolvePlexServerToken uses that token for the item and episode access checks. Without one it keeps the account token, which is what works for the owner.
    • Each user's server token is kept for 6 h (in memory, keyed by a SHA-256 of server id + account token, capped at 1,000 entries). If plex.tv can't be reached, the check uses the account token and asks again after 1 min.

Testing

AI assistance

AI tools helped write parts of the code and tests. I reviewed the changes, ran the tests listed above, and checked it on a live install.

A Plex server refuses the account token of someone it is shared with;
plex.tv issues them a separate token for that server. Availability
checks sent the account token, got 401, and showed every title as
missing to all non-admin Plex users. Look up the server token once per
user (cached 6 h, retried after 1 min on failure) without adding tokens
to device lists.
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.

1 participant