This document describes RAGFlow's multi-method authentication and authorization system. RAGFlow supports three primary authentication mechanisms: API key authentication (including Beta tokens), session-based authentication for web UI interactions, and OAuth/OIDC for single-sign-on integration. It covers the implementation across the Python (Quart) and Go (Gin) backend layers, ensuring unified security policies.
RAGFlow implements a flexible authentication architecture that serves different client types across its polyglot backend:
URLSafeTimedSerializer and falls back to server-side session cookies managed via Redis api/apps/__init__.py79-83 api/apps/__init__.py110-142APIToken model manages these credentials api/db/db_models.py26Authorization is tenant-based. Each authenticated user is associated with a tenant_id (often identical to the user ID for the owner) that controls access to datasets, chat assistants, and system resources api/db/services/user_service.py27 internal/service/user.go194-206
Sources: api/apps/__init__.py94-107 api/apps/__init__.py110-142 internal/admin/handler.go94-137 internal/service/user.go194-206
In the Python backend, route protection is primarily handled by the login_required decorator defined in api/apps/__init__.py. This decorator supports multiple authentication types simultaneously (JWT, API, BETA) api/apps/__init__.py227-247
Title: Authentication Resolution Flow in "api.apps.login_required"
Sources: api/apps/__init__.py144-225 api/apps/__init__.py227-247
RAGFlow provides a current_user proxy, allowing developers to access the authenticated user's details throughout the request lifecycle without passing user objects explicitly api/apps/__init__.py249-250
current_user: A LocalProxy that resolves to g.user api/apps/__init__.py250g.auth_type: Stores the method used for the current request (e.g., JWT, API, or BETA) api/apps/__init__.py139-140Sources: api/apps/__init__.py249-250 api/apps/__init__.py139-140
API keys provide programmatic access. The system distinguishes between standard token (general API access) and beta tokens (public bot/agent interfaces).
APIToken table api/apps/__init__.py202-218Sources: api/apps/__init__.py170-183 api/apps/__init__.py202-218
The web UI uses session-based authentication. When a user logs in, the UserService (Python) or UserService (Go) validates credentials.
Title: Login Sequence in "internal.service.UserService" and "api.apps.user_app"
Implementation detail: RAGFlow supports multiple hashing algorithms via Go compatibility (pbkdf2, scrypt) to match Python's password verification logic internal/service/user.go130-133 api/apps/__init__.py187-188
Sources: api/apps/__init__.py110-142 internal/service/user.go105-161 api/utils/api_utils.py136-154
The Go backend (admin and ingestion services) implements its own authentication logic to verify tokens issued by the Python layer.
is_superuser set to true can access admin endpoints internal/admin/handler.go111-114utility.DumpAccessToken and the shared SECRET_KEY retrieved via server.GetSecretKey(redis.Get()) to validate tokens internal/admin/handler.go116-126INVALID_ in the database internal/admin/service.go97-104Sources: internal/admin/handler.go111-126 internal/admin/service.go97-104 internal/admin/service.go120-135
RAGFlow uses a robust validation layer to ensure request integrity before authentication/authorization checks.
validate_and_parse_json_request performs content-type verification and schema validation using Pydantic api/utils/validation_utils.py36-113server_error_response function maps exceptions to RetCode.UNAUTHORIZED when applicable api/utils/api_utils.py136-154Sources: api/utils/validation_utils.py36-113 api/utils/api_utils.py136-154 docs/references/http_api_reference.md18-24
Authentication behavior is controlled via service_conf.yaml and environment variables:
| Setting | Description | File Reference |
|---|---|---|
SECRET_KEY | Key used for JWT signing and session encryption | api/apps/__init__.py82 |
authentication.client.switch | Toggle for client-side API key authentication | conf/service_conf.yaml161-165 |
oauth | Configuration for GitHub, OIDC, and OAuth2 providers | conf/service_conf.yaml138-160 |
RESPONSE_TIMEOUT | Timeout for slow LLM responses (default 600s) | api/apps/__init__.py73 |
disable_password_login | Disables standard password auth when OAuth is preferred | docker/service_conf.yaml.template182 |
Sources: conf/service_conf.yaml138-165 api/apps/__init__.py73-83 docker/service_conf.yaml.template182
Refresh this wiki
This wiki was recently refreshed. Please wait 4 days to refresh again.