A Reflex plugin for handling Descope OAuth authentication.
Project description
A plugin for integrating Descope authentication with Reflex apps.
Supports secure login, logout, and session management using OpenID Connect (OIDC) Authorization Code Flow with PKCE.
View on GitHub for more details
✨ Features
- 🔐 OIDC login with PKCE using Descope
- 🧠 Local JWT session management
- 🍪 Cookie-based session token storage
- 👤 Easy access to user profile info
- 🔁 Automatic session token generation
- ❌ Graceful error handling
- 🔧 Overrideable plugin state for customization
📦 Installation
pip install reflex-descope-auth
⚙️ Configuration
Before using the plugin, set the required environment variables.
Create a .env file in your Reflex project:
DESCOPE_PROJECT_ID=<your-project-id>
DESCOPE_REDIRECT_URI=http://localhost:3000/callback
DESCOPE_FLOW_ID=sign-up-or-in
DESCOPE_LOGOUT_REDIRECT_URI=http://localhost:3000
SESSION_SECRET=<your-session-secret>
You can also override Descope’s OIDC endpoints using additional environment variables (see Environment Variables) — useful for custom Descope domains.
🚀 Usage
1. Import and Extend the Plugin
import reflex as rx
from reflex_descope_auth import DescopeAuthState
class State(DescopeAuthState):
@rx.event
async def auth_redirect(self):
yield DescopeAuthState.finalize_auth()
yield rx.redirect("/")
2. Setup Pages
@rx.page(route="/callback", on_load=State.auth_redirect)
def callback():
return rx.center("Logging in...")
@rx.page()
def index():
return rx.cond(
State.logged_in,
rx.text(f"Hello, {State.userinfo['name']}!"),
rx.button("Login", on_click=DescopeAuthState.start_login)
)
🔧 Environment Variables
| Name | Description |
|---|---|
DESCOPE_PROJECT_ID |
Your Descope project ID (required) |
DESCOPE_REDIRECT_URI |
Redirect URI after login (default: http://localhost:3000/callback) |
DESCOPE_FLOW_ID |
Flow ID from Descope (default: sign-up-or-in) |
DESCOPE_LOGOUT_REDIRECT_URI |
Redirect URI after logout (default: http://localhost:3000) |
SESSION_SECRET |
Secret used to sign local session tokens (default: default-secret) |
DESCOPE_AUTH_URL |
(Optional) Override Descope auth endpoint |
DESCOPE_TOKEN_URL |
(Optional) Override Descope token endpoint |
DESCOPE_USERINFO_URL |
(Optional) Override userinfo endpoint |
DESCOPE_LOGOUT_URL |
(Optional) Override logout endpoint |
DESCOPE_JWKS_URL |
(Optional) Override JWKS URL for public keys |
❗ Error Handling
If authentication fails:
- The plugin sets an
error_messagevariable in the state. - No crashes or exceptions — just check and display
State.error_message. - Customize handling by subclassing and overriding the default behavior.
📝 Notes
- Sessions are managed entirely on the client using secure cookies.
- JWT tokens are signed with
HS256using yourSESSION_SECRET. - Descope handles user identity and OIDC flow; the plugin wraps it for Reflex.
- See the full working demo app on GitHub.
📄 License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file reflex_descope_auth-0.1.6.tar.gz.
File metadata
- Download URL: reflex_descope_auth-0.1.6.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d14dfdf631fbee73b6b2693f93e49ec551eeb15f9e2fab68fe1f11cf4658e3f1
|
|
| MD5 |
79950379c832cfc15ddf10de2117b107
|
|
| BLAKE2b-256 |
1248988554165c2bbbd88f33d8c1076fa13152372e62268ae9195c8f7bc30653
|
File details
Details for the file reflex_descope_auth-0.1.6-py3-none-any.whl.
File metadata
- Download URL: reflex_descope_auth-0.1.6-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
060c580fcef05ba3170b84b26881921b9b945f69884df058ef3f4cca7d619e68
|
|
| MD5 |
14b93e67b45a7f1a7b90b454d2aec459
|
|
| BLAKE2b-256 |
08edb60195ecee009f18b0a59d1bae57e0d17bd8c8f3af87a45a32a84d33c5f3
|