Skip to content

Conversation

@JonnyWong16
Copy link
Collaborator

@JonnyWong16 JonnyWong16 commented Oct 1, 2025

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:

from plexapi.myplex import MyPlexAccount, MyPlexJWTLogin

# Method 1: Generate a new Plex JWT using Plex OAuth
jwtlogin = 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.jwtToken

account = MyPlexAccount(token=jwtToken)

# Method 2: Generate a new Plex JWT using an existing Plex token and keypair
jwtlogin = 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 JWT
jwtlogin = MyPlexJWTLogin(
    jwtToken=jwtToken,
    keypair=('private.key', 'public.key'),
    scopes=['username', 'email', 'friendly_name']
)
if not jwtlogin.verifyJWT():
    jwtToken = jwtlogin.refreshJWT()

account = MyPlexAccount(token=jwtToken)

Example using helper function:

from plexapi.utils import plexJWTAuth

# Generate a new Plex JWT using Plex OAuth
# Client identifier and keypair will be generated automatically
account = 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 JonnyWong16 force-pushed the feature/plex_jwt branch 8 times, most recently from 16b4d54 to 75a134b Compare October 2, 2025 06:24
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 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
File Description
requirements_dev.txt Adds pyjwt[crypto] as a development dependency for JWT functionality
pyproject.toml Adds optional 'jwt' dependency group for JWT authentication support
plexapi/utils.py Adds JWT authentication helper functions, UUID generation, base64url encoding, and updates to existing OAuth functions for consistency
plexapi/myplex.py Implements MyPlexJWTLogin class with JWT generation, verification, refresh, and device registration capabilities
README.rst Documents the new JWT optional dependency installation

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

@JonnyWong16 JonnyWong16 marked this pull request as ready for review November 2, 2025 09:45
@JonnyWong16 JonnyWong16 merged commit c4ea6e7 into pushingkarmaorg:master Nov 3, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant