fix(feishu): use /page/cli verification URL for QR onboarding
Co-authored-by: HammerHound AI <26013314+hammerhoundai@users.noreply.github.com>
This commit is contained in:
1 parent
0afebd4747
commit
1fd0cca7e2
2 files changed
+51
No files matched your search
@@ -546,6 +546,13 @@ def _begin_registration(domain: str = "feishu") -> _RegistrationStart:
|
|||||||
qr_url = res.get("verification_uri_complete", "")
|
qr_url = res.get("verification_uri_complete", "")
|
||||||
if not isinstance(qr_url, str) or not qr_url:
|
if not isinstance(qr_url, str) or not qr_url:
|
||||||
raise RuntimeError("Feishu / Lark registration did not return a login 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")
|
interval = res.get("interval")
|
||||||
expire_in = res.get("expire_in")
|
expire_in = res.get("expire_in")
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -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,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"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
|
||||||
Reference in new issue
Block a user