Skip to content

Add support for Plex JWT Authentication - #1554

Merged
JonnyWong16 merged 10 commits into
pushingkarmaorg:masterfrom
JonnyWong16:feature/plex_jwt
Nov 3, 2025
Merged

Add support for Plex JWT Authentication#1554
JonnyWong16 merged 10 commits into
pushingkarmaorg:masterfrom
JonnyWong16:feature/plex_jwt

Conversation

@JonnyWong16

@JonnyWong16JonnyWong16 commented Oct 1, 2025

Copy link
Copy Markdown
Collaborator

Description

Ref.: https://developer.plex.tv/pms/#section/API-Info/Authenticating-with-Plex

  • Added new myplex.MyPlexJWTAuth class to handle Plex JWT authentication.
  • Added new utils.plexJWTAuth() helper function for Plex JWT authentication.

Example using class:

fromplexapi.mypleximportMyPlexAccount, MyPlexJWTLogin# Method 1: Generate a new Plex JWT using Plex OAuthjwtlogin=MyPlexJWTLogin(
oauth=True,
scopes=['username', 'email', 'friendly_name']
)
jwtlogin.generateKeypair(keyfiles=('private.key', 'public.key'))
print(f'Login to Plex at the following url:\n{jwtlogin.oauthUrl()}')
jwtlogin.run()
jwtlogin.waitForLogin()
jwtToken=jwtlogin.jwtTokenaccount=MyPlexAccount(token=jwtToken)
# Method 2: Generate a new Plex JWT using an existing Plex token and keypairjwtlogin=MyPlexJWTLogin(
token='2ffLuB84dqLswk9skLos',
keypair=('private.key', 'public.key'),
scopes=['username', 'email', 'friendly_name']
)
jwtlogin.registerDevice()
jwtToken=jwtlogin.refreshJWT()
account=MyPlexAccount(token=jwtToken)
# Refresh an existing Plex JWTjwtlogin=MyPlexJWTLogin(
jwtToken=jwtToken,
keypair=('private.key', 'public.key'),
scopes=['username', 'email', 'friendly_name']
)
ifnotjwtlogin.verifyJWT():
jwtToken=jwtlogin.refreshJWT()
account=MyPlexAccount(token=jwtToken)

Example using helper function:

fromplexapi.utilsimportplexJWTAuth# Generate a new Plex JWT using Plex OAuth# Client identifier and keypair will be generated automaticallyaccount=plexJWTAuth(scopes=['username', 'email', 'friendly_name'])

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • 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

@JonnyWong16
JonnyWong16force-pushed the feature/plex_jwt branch 8 times, most recently from 16b4d54 to 75a134bCompareOctober 2, 2025 06:24

CopilotAI 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

This PR adds support for Plex JWT Authentication, implementing a new authentication method that uses JSON Web Tokens with ED25519 key pairs as described in the Plex API documentation.

Key changes include:

  • Implementation of a new MyPlexJWTLogin class for handling JWT-based authentication flows (OAuth and token-based)
  • Addition of plexJWTAuth() helper function for simplified JWT authentication using OAuth
  • Support for ED25519 keypair generation, JWT encoding/decoding, and token refresh functionality

Reviewed Changes

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

Show a summary per file
FileDescription
requirements_dev.txtAdds pyjwt[crypto] as a development dependency for JWT functionality
pyproject.tomlAdds optional 'jwt' dependency group for JWT authentication support
plexapi/utils.pyAdds JWT authentication helper functions, UUID generation, base64url encoding, and updates to existing OAuth functions for consistency
plexapi/myplex.pyImplements MyPlexJWTLogin class with JWT generation, verification, refresh, and device registration capabilities
README.rstDocuments the new JWT optional dependency installation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment threadplexapi/utils.py
Comment threadplexapi/utils.py
Comment threadplexapi/myplex.py
Comment threadplexapi/myplex.py
Comment threadplexapi/myplex.py
Comment threadplexapi/myplex.py
Comment threadplexapi/myplex.py Outdated
Comment threadplexapi/myplex.py
@JonnyWong16
JonnyWong16 marked this pull request as ready for review November 2, 2025 09:45
@JonnyWong16
JonnyWong16 merged commit c4ea6e7 into pushingkarmaorg:masterNov 3, 2025
5 checks passed
@JonnyWong16
JonnyWong16 deleted the feature/plex_jwt branch November 16, 2025 08:29
JonnyWong16 added a commit to JonnyWong16/python-plexapi that referenced this pull request Nov 18, 2025
* Add private.key and public.key to .gitignore
* Add `MyPlexJWTAuth` class
* Add `utils.plexJWTAuth` helper function
* Update optional dependencies for Plex JWT authentication
* Add method to retrieve Plex JWT without initial Plex token
* Update doc strings
* Switch MyPlexJWTLogin to JSON response
* Remove cached data properties
* Guard against None keypair
* Use UTC timezone for jwt
Sign up for freeto 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.

3 participants

@JonnyWong16@montaguethomas