fix(feishu): preserve QR query values and registration expiry
Restrict the launcher workaround to its known host and exact path. Honor expires_in while retaining the legacy expire_in response. Cover both hosts, opaque query values and old/new TTL fields.
This commit is contained in:
1 parent
1fd0cca7e2
commit
4535496064
2 files changed
+48
-8
No files matched your search
@@ -18,6 +18,7 @@ from datetime import UTC, datetime
|
||||
from functools import partial
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any, TypedDict, cast
|
||||
from urllib.parse import urlsplit, urlunsplit
|
||||
|
||||
from rich.console import Console
|
||||
from rich.markup import escape
|
||||
@@ -546,15 +547,17 @@ 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?")
|
||||
# PersonalAgent codes use /page/cli. Rewrite only the known landing page,
|
||||
# preserving opaque query values (including user_code) and the fragment.
|
||||
parsed = urlsplit(qr_url)
|
||||
if (
|
||||
parsed.scheme == "https"
|
||||
and parsed.netloc in {"open.feishu.cn", "open.larksuite.com"}
|
||||
and parsed.path == "/page/launcher"
|
||||
):
|
||||
qr_url = urlunsplit(parsed._replace(path="/page/cli"))
|
||||
interval = res.get("interval")
|
||||
expire_in = res.get("expire_in")
|
||||
expire_in = res.get("expires_in", res.get("expire_in"))
|
||||
return {
|
||||
"device_code": device_code,
|
||||
"qr_url": qr_url,
|
||||
|
||||
Reference in new issue
Block a user