Complete OAuth 2.0 implementation for the Envato API with one-function authentication.
from envato_oauth import authenticate
import requests
# One function call handles all OAuth complexity
token = authenticate()
# Use token for API calls
headers = {"Authorization": f"Bearer {token}"}
response = requests.get(
"https://api.envato.com/v1/market/private/user/account.json",
headers=headers
)
The envato_oauth
module provides these simple functions:
authenticate()
- One-function OAuth (handles everything automatically)get_auth_headers()
- Get headers ready for API requestsis_authenticated()
- Check authentication statusclear_authentication()
- Clear stored tokens
-
Install dependencies:
pip install -r requirements.txt
-
Configure environment:
cp .env.example .env # Edit .env with your Envato API credentials
-
Start localtunnel (for external access):
lt --port 56654 --subdomain seamless-themes
-
Authenticate (choose one method):
Option A: Web-based (recommended)
python oauth_server.py
Option B: CLI-based
python oauth_cli.py
-
Test the module:
python example_simple.py
For more control, you can still use the individual scripts:
Create a .env
file:
ENVATO_CLIENT_ID=your_client_id_here
ENVATO_CLIENT_SECRET=your_client_secret_here
OAUTH_PORT=56654
ENVATO_REDIRECT_URI=https://seamless-themes.loca.lt/callback
envato_oauth.py
- Main module - One-function OAuth interfaceexample_simple.py
- Simple usage exampleauth.py
- OAuth implementation (used internally)oauth_server.py
- FastAPI web server for OAuth flowoauth_cli.py
- CLI-based OAuth authenticationapi_client_example.py
- Advanced API usage example.envato.auth.json
- Secure token storage (auto-created)
✅ Configurable OAuth port via OAUTH_PORT
environment variable
✅ Automatic token refresh and storage
✅ Web-based authentication flow
✅ Localtunnel integration
✅ Secure token management
from envato_oauth import authenticate, get_auth_headers
import requests
# Method 1: Get token directly
token = authenticate()
headers = {"Authorization": f"Bearer {token}"}
# Method 2: Get headers directly
headers = get_auth_headers()
# Method 3: Advanced options
token = authenticate(
method="manual", # Force manual auth
force_reauth=True, # Force re-authentication
quiet=True # Silent mode
)
# Make API calls
response = requests.get(
"https://api.envato.com/v1/market/private/user/account.json",
headers=headers
)
For the easiest authentication experience, use the FastAPI-based OAuth server that automatically launches your browser:
# Run the OAuth server (launches browser automatically)
python oauth_server.py
This will:
- Start a local FastAPI server on
http://localhost:8080
- Open your browser to the Envato authorization page
- Handle the OAuth callback automatically
- Store your tokens securely in
.envato.auth.json
- Confirm successful authentication
from oauth_server import authenticate_with_browser
from envato_oauth import get_envato_auth_headers
import requests
# Authenticate using browser flow
if authenticate_with_browser():
# Make authenticated API calls
headers = get_envato_auth_headers()
response = requests.get(
"https://api.envato.com/v1/market/user:username.json",
headers=headers
)
print(response.json())