A minimal Flask web application for authenticating with Plex and obtaining access tokens for use with Kometa.
This app provides a simple web interface for users to authenticate with their Plex account and receive an access token that can be used with Kometa or other Plex-based applications.
- Simple, user-friendly web interface
- OAuth 2.0 PIN-based authentication flow
- Secure token generation
- One-click token copy to clipboard
- Ready for Heroku deployment
The easiest way to get started is using VS Code Dev Containers:
-
Prerequisites:
- Install Docker Desktop
- Install VS Code
- Install the Dev Containers extension
-
Open in container:
- Open this project in VS Code
- Press
F1and selectDev Containers: Reopen in Container - Wait for setup to complete (automatically installs everything)
-
Run the app:
uv run python app.py
-
Open your browser to
http://localhost:8080
See .devcontainer/README.md for more details.
-
Install uv (if not already installed):
curl -LsSf https://astral.sh/uv/install.sh | sh -
Clone the repository:
git clone https://github.com/Kometa-Team/Plex-OAuth.git cd Plex-OAuth -
Install dependencies:
uv sync
-
Create environment file:
cp .env.example .env # Edit .env with your settings -
Run the application:
uv run python app.py
-
Open your browser to
http://localhost:8080
- Click "Authenticate with Plex"
- Sign in with your Plex account
- Authorize the application
- Copy the displayed access token
- Use the token in your Kometa configuration
- Heroku CLI installed
- A Heroku account
-
Create a new Heroku app:
heroku create your-app-name
-
Set environment variables:
heroku config:set SECRET_KEY=$(python -c 'import os; print(os.urandom(24).hex())') heroku config:set APP_NAME="Kometa Plex Auth"
-
Deploy the application:
git push heroku main
-
Open your app:
heroku open
Configure these in Heroku's dashboard or via the CLI:
SECRET_KEY- Flask secret key (required for sessions)APP_NAME- Name displayed in the app and to Plex (default: "Kometa Plex Auth")APP_VERSION- Version string (default: "1.0")DEBUG- Enable debug mode (default: "False", use "True" only in development)
Copy .env.example to .env for local development:
cp .env.example .envEdit .env with your preferred settings.
Plex-OAuth/
├── app.py # Main Flask application
├── templates/ # HTML templates
│ ├── base.html # Base template with styling
│ ├── index.html # Home page
│ ├── success.html # Success page with token
│ └── error.html # Error page
├── pyproject.toml # Project dependencies (uv)
├── Procfile # Heroku process file
├── runtime.txt # Python version for Heroku
└── README.md # This file
- The app generates a unique client identifier for each user session
- Tokens are displayed only once after successful authentication
- Always use HTTPS in production (Heroku provides this automatically)
- Keep your
SECRET_KEYsecure and never commit it to version control - The generated token provides full access to the user's Plex account - handle with care
uv run pytestuv add package-name- This happens if cookies are disabled or cleared between steps
- Ensure cookies are enabled in your browser
- Try the authentication flow again
- Check that you completed the Plex authentication
- Verify the app has network access to plex.tv
- Check Heroku logs:
heroku logs --tail
MIT License - see LICENSE file for details
Contributions are welcome! Please feel free to submit a Pull Request.