Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(lark): honor the device-flow expires_in so the bind QR keeps its full 1h window (MUL-7340) (#8370)

Bohan Jiang408bf2b270ec
diff --git a/server/internal/integrations/lark/registration.go b/server/internal/integrations/lark/registration.go
index 31343c9cb0..928de55644 100644
--- a/server/internal/integrations/lark/registration.go
+++ b/server/internal/integrations/lark/registration.go
@@ -58,10 +58,12 @@ const (
// without buying any latency improvement.
registrationDefaultPollSeconds = 5
- // Default registration window (10 minutes) — long enough for a user
- // to scan, switch apps, walk the create-bot flow, and authorize on
- // their phone, short enough that an abandoned session does not pin
- // resources for hours.
+ // Fallback registration window, used ONLY when the server omits the
+ // expiry from its begin response. Both real clouds send
+ // expires_in=3600, so this is a floor for mocks / schema drift, not
+ // the value users normally get: 10 minutes is long enough to scan,
+ // switch apps, walk the create-bot flow, and authorize on a phone,
+ // short enough that an abandoned session does not poll for hours.
registrationDefaultExpireSeconds = 600
// Internal-tenant brand label Lark uses to flag "you scanned with a
@@ -263,9 +265,16 @@ func (c *RegistrationClient) Begin(ctx context.Context, namePreset string, regio
VerificationURI string `json:"verification_uri"`
UserCode string `json:"user_code"`
Interval int `json:"interval"`
- ExpireIn int `json:"expire_in"`
- Error string `json:"error"`
- ErrorDescription string `json:"error_description"`
+ // ExpiresIn is the RFC 8628 §3.2 field name, and the one both
+ // accounts.feishu.cn and accounts.larksuite.com actually send
+ // (currently 3600). ExpireIn is the spelling the upstream Lark
+ // Go SDK types; we accept both so a schema drift in either
+ // direction keeps the real window instead of silently
+ // collapsing to the default.
+ ExpiresIn int `json:"expires_in"`
+ ExpireIn int `json:"expire_in"`
+ Error string `json:"error"`
+ ErrorDescription string `json:"error_description"`
}
form := url.Values{
"action": []string{"begin"},
@@ -294,7 +303,9 @@ func (c *RegistrationClient) Begin(ctx context.Context, namePreset string, regio
interval = resp.Interval
}
expireIn := registrationDefaultExpireSeconds
- if resp.ExpireIn > 0 {
+ if resp.ExpiresIn > 0 {
+ expireIn = resp.ExpiresIn
+ } else if resp.ExpireIn > 0 {
expireIn = resp.ExpireIn
}
return &BeginResult{
diff --git a/server/internal/integrations/lark/registration_service.go b/server/internal/integrations/lark/registration_service.go
index 6f67963e46..1bd775b27e 100644
--- a/server/internal/integrations/lark/registration_service.go
+++ b/server/internal/integrations/lark/registration_service.go
@@ -69,7 +69,8 @@ type RegistrationServiceConfig struct {
// for the frontend to fetch the final status after the dialog
// closes, short enough that abandoned sessions do not pin memory
// forever. Independent of the device-flow expiry (Lark's
- // expire_in, ~10 min).
+ // expires_in, currently 1h), which bounds the PENDING phase; this
+ // TTL only starts once a session has already terminated.
SessionTTL time.Duration
// Now is overridable for deterministic expiry-bound tests.
diff --git a/server/internal/integrations/lark/registration_test.go b/server/internal/integrations/lark/registration_test.go
index 8db5fb7e71..1b6a3136b9 100644
--- a/server/internal/integrations/lark/registration_test.go
+++ b/server/internal/integrations/lark/registration_test.go
@@ -223,8 +223,34 @@ func TestRegistrationClient_Begin_RegionFeishuBeginsOnFeishu(t *testing.T) {
}
}
+func TestRegistrationClient_Begin_HonorsExpiresInWireField(t *testing.T) {
+ // MUL-7340: the wire field accounts.feishu.cn and
+ // accounts.larksuite.com actually send is `expires_in` (RFC 8628
+ // §3.2), currently 3600 — NOT the `expire_in` spelling the upstream
+ // Go SDK types. Parsing only `expire_in` made every real begin
+ // response look like "server omitted the expiry", silently
+ // collapsing a 1-hour QR to the 10-minute fallback.
+ fake := newRegistrationFake(t)
+ fake.stubBegin(map[string]any{
+ "device_code": "dc_expires_in",
+ "verification_uri_complete": "https://open.feishu.cn/page/launcher?user_code=ABCD-EFGH",
+ "user_code": "ABCD-EFGH",
+ "interval": 5,
+ "expires_in": 3600,
+ })
+
+ c := NewRegistrationClient(RegistrationConfig{Domain: fake.URL()})
+ res, err := c.Begin(context.Background(), "", "")
+ if err != nil {
+ t.Fatalf("Begin: %v", err)
+ }
+ if res.ExpiresIn != 3600*time.Second {
+ t.Errorf("ExpiresIn: got %v want 1h — the server's expires_in must win over the fallback", res.ExpiresIn)
+ }
+}
+
func TestRegistrationClient_Begin_DefaultsWhenServerOmitsTimers(t *testing.T) {
- // When Lark's response omits `interval` / `expire_in` (the empty
+ // When Lark's response omits `interval` / `expires_in` (the empty
// path the upstream SDK accepts), the client falls back to its
// documented defaults rather than zero-second polling that would
// hammer the endpoint or zero-second expiry that would fail the