Skip to content

Your lightweight open-source personal agent.

fix(feishu): use /page/cli verification URL for QR onboarding

ubuntu1fd0cca7e241
diff --git a/nanobot/channels/feishu/runtime.py b/nanobot/channels/feishu/runtime.py
index 23bbb1569..a99e71ced 100644
--- a/nanobot/channels/feishu/runtime.py
+++ b/nanobot/channels/feishu/runtime.py
@@ -546,6 +546,13 @@ def _begin_registration(domain: str = "feishu") -> _RegistrationStart:
qr_url = res.get("verification_uri_complete", "")
if not isinstance(qr_url, str) or not qr_url:
raise RuntimeError("Feishu / Lark registration did not return a login URL")
+ # The registration endpoint returns a /page/launcher URL, but that page
+ # rejects these device codes instantly ("Link expired") even when scanned
+ # seconds after issuance. /page/cli is the page used by other agent
+ # implementations of this flow and works for both feishu.cn and
+ # larksuite.com tenants, so rewrite the host page and keep the user_code.
+ if "/page/launcher?" in qr_url:
+ qr_url = qr_url.replace("/page/launcher?", "/page/cli?")
interval = res.get("interval")
expire_in = res.get("expire_in")
return {
diff --git a/tests/channels/test_feishu_login_url.py b/tests/channels/test_feishu_login_url.py
new file mode 100644
index 000000000..11c276f5c
--- /dev/null
+++ b/tests/channels/test_feishu_login_url.py
@@ -0,0 +1,44 @@
+"""Feishu/Lark QR onboarding: verification URL handling."""
+
+from __future__ import annotations
+
+from unittest.mock import patch
+
+import pytest
+
+from nanobot.channels.feishu import runtime as feishu_runtime
+
+
+def _begin_response(uri: str) -> dict:
+ return {
+ "device_code": "dc-test",
+ "verification_uri_complete": uri,
+ "interval": 5,
+ "expire_in": 3600,
+ }
+
+
+ "returned",
+ [
+ "https://open.feishu.cn/page/launcher?user_code=ABCD-EFGH",
+ "https://open.larksuite.com/page/launcher?user_code=ABCD-EFGH",
+ ],
+)
+def test_launcher_url_rewritten_to_cli_page(returned: str) -> None:
+ """The registration endpoint returns /page/launcher, which rejects these
+ device codes instantly; the CLI page is the one that works."""
+ with patch.object(feishu_runtime, "_post_registration",
+ return_value=_begin_response(returned)):
+ start = feishu_runtime._begin_registration("feishu")
+ assert start["qr_url"].startswith(
+ returned.split("/page/")[0] + "/page/cli?user_code="
+ )
+
+
+def test_cli_url_passed_through_unchanged() -> None:
+ uri = "https://open.feishu.cn/page/cli?user_code=ABCD-EFGH"
+ with patch.object(feishu_runtime, "_post_registration",
+ return_value=_begin_response(uri)):
+ start = feishu_runtime._begin_registration("feishu")
+ assert start["qr_url"] == uri