Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(auth): separate OAuth JIT provisioning policy (#19651)

Sbaaoui Idrissd8b072fd9d39
diff --git a/api/apps/restful_apis/user_api.py b/api/apps/restful_apis/user_api.py
index 6f86d7f1a5..e9f84d60ff 100644
--- a/api/apps/restful_apis/user_api.py
+++ b/api/apps/restful_apis/user_api.py
@@ -223,6 +223,9 @@ async def oauth_callback(channel):
user_id = get_uuid()
if not users:
+ if not getattr(settings, "OAUTH_AUTO_REGISTER", True):
+ logging.warning("OAuth/OIDC JIT registration blocked: email=%s, channel=%s", user_info.email, channel)
+ return redirect("/?error=registration_disabled")
try:
try:
avatar = await download_img(user_info.avatar_url)
diff --git a/common/settings.py b/common/settings.py
index 7db73d6330..faebc1cecc 100644
--- a/common/settings.py
+++ b/common/settings.py
@@ -182,6 +182,9 @@ kg_retriever = None
# user registration switch
REGISTER_ENABLED = 1
+# Allow OAuth/OIDC just-in-time user provisioning (independent of local signup).
+OAUTH_AUTO_REGISTER = True
+
# SSO-only mode: hide password login form
DISABLE_PASSWORD_LOGIN = False
@@ -322,6 +325,10 @@ def init_settings():
except Exception:
pass
+ global OAUTH_AUTO_REGISTER
+ env_val = os.environ.get("OAUTH_AUTO_REGISTER", "").lower()
+ OAUTH_AUTO_REGISTER = env_val not in ("0", "false", "no")
+
global DISABLE_PASSWORD_LOGIN
try:
env_val = os.environ.get("DISABLE_PASSWORD_LOGIN", "").lower()
diff --git a/docs/administrator/configurations/configurations.md b/docs/administrator/configurations/configurations.md
index 7982e55992..a1910c4b96 100644
--- a/docs/administrator/configurations/configurations.md
+++ b/docs/administrator/configurations/configurations.md
@@ -142,6 +142,10 @@ If you cannot download the RAGFlow Docker image, try the following mirrors.
- `1`: (Default) Enable user registration.
- `0`: Disable user registration.
+- `OAUTH_AUTO_REGISTER`
+ - `true`: (Default) Allow new users to be provisioned on OAuth/OIDC login.
+ - `false`: Require OAuth/OIDC users to already exist. This is independent of `REGISTER_ENABLED`.
+
## Service Configuration
[service_conf.yaml.template](https://github.com/infiniflow/ragflow/blob/main/docker/service_conf.yaml.template) specifies the system-level configuration for RAGFlow and is used by its API server and task executor.
diff --git a/test/testcases/test_web_api/test_user_app/test_user_app_unit.py b/test/testcases/test_web_api/test_user_app/test_user_app_unit.py
index 71df172d44..d8c8b76a8f 100644
--- a/test/testcases/test_web_api/test_user_app/test_user_app_unit.py
+++ b/test/testcases/test_web_api/test_user_app/test_user_app_unit.py
@@ -606,6 +606,19 @@ def test_oauth_callback_matrix_unit(monkeypatch):
monkeypatch.setattr(module, "get_auth_client", lambda _config: async_new_user)
monkeypatch.setattr(module.UserService, "query", lambda **_kwargs: [])
+ module.settings.OAUTH_AUTO_REGISTER = False
+ register_calls = []
+ monkeypatch.setattr(module, "user_register", lambda *args: register_calls.append(args))
+ avatar_calls = []
+ monkeypatch.setattr(module, "download_img", lambda url: avatar_calls.append(url))
+ module.session.clear()
+ module.session["oauth_state"] = "blocked-state"
+ _set_request_args(monkeypatch, module, {"state": "blocked-state", "code": "code"})
+ res = _run(module.oauth_callback("github"))
+ assert res["redirect"] == "/?error=registration_disabled"
+ assert not register_calls and not avatar_calls
+ module.settings.OAUTH_AUTO_REGISTER = True
+
def _raise_download(_url):
raise RuntimeError("download explode")