Skip to content

Authentication

DyUI can put a shared password in front of an app, and always keeps each browser’s conversations private. Read this page before you put an app on the internet.

import os
app = dyui.App(title="Internal Analyst", password=os.environ["APP_PASSWORD"])

With password set:

  • the app shows a password screen first;
  • POST /api/login checks the password with a constant-time comparison and sets a signed, HttpOnly, SameSite=Lax dyui_auth cookie that lasts 30 days (marked Secure when the request arrived over HTTPS);
  • after 10 failed attempts within 5 minutes from one client address, login answers 429 Too many attempts until the window passes, and a successful login resets the count;
  • every other /api/* route (except /api/config and /api/logo) returns 401 without that cookie.

The throttle is kept in memory per process and keys on the client address the server sees. Behind a reverse proxy, run Uvicorn with --proxy-headers (and --forwarded-allow-ips set to your proxy). Otherwise every user shares the proxy’s address, and HTTPS isn’t detected for the Secure flag.

The cookie is an HMAC of the password, signed with a secret. The secret comes from the DYUI_SECRET environment variable, or, when that isn’t set, from a random key generated once in <data_dir>/secret. Changing the password signs everyone out. Set DYUI_SECRET explicitly when you run several instances, so they all accept the same cookie.

Each browser gets a random dyui_uid cookie, and threads, messages, uploaded files and actions are scoped to it. One browser can’t read or act on another browser’s conversations, even with the ids. Clearing cookies starts a fresh, empty history.

DyUI’s app is a standard ASGI application, so you can put it behind any gateway that authenticates users: an SSO proxy, your platform’s access control, or ASGI middleware you wrap around it. OAuth providers are on the roadmap.

An app behind a shared password read from the environment. It needs no API key, only the password.

app.py
"""An internal app behind a shared password.
Put APP_PASSWORD=... in a .env file next to this one (dyui run loads it).
Save as app.py, then run: dyui run app.py
"""
import os
import dyui
from dyui import ui
app = dyui.App(title="Internal Analyst", password=os.environ["APP_PASSWORD"])
@app.on_message
async def reply(msg: dyui.Message, chat: dyui.Chat):
yield "You're signed in. Each browser still sees only its own conversations."
yield ui.KeyValue({"Browser id": chat.user_id[:8] + "…"})
  1. Save it as app.py in a new, empty file, or download app.py.

  2. Put APP_PASSWORD=choose-a-long-passphrase in a .env file next to it.

  3. Run it:

    Terminal window
    pip install dyui
    dyui run app.py
  4. Open http://localhost:8000 and sign in with the password from .env.

DyUI Docs assistant

Answers come from the DyUI docs. gpt-oss-120b via Groq. Press Escape or the close button to return to the page.