feat(sidecar): auto-discover app scopes via API, remove offline_access fallback#1367
feat(sidecar): auto-discover app scopes via API, remove offline_access fallback#1367hGrany wants to merge 1 commit into
Conversation
…s fallback The multi-tenant sidecar demo previously fell back to `offline_access` when the scope cache was empty, resulting in scope_count=1 — effectively granting no useful permissions. Replace this silent failure with scope auto-discovery: - Query /open-apis/application/v6/applications/:app_id using the sidecar's tenant access token to discover enabled user scopes. - Cache discovered scopes in discovered_scopes.json with a 24-hour TTL. - On API failure with existing stale cache, use stale scopes (degradation over interruption). - On API failure with no cache, return an explicit 503 error with a diagnostic message — no fallback to offline_access. - Backward-compatible: still reads legacy auth_login_scopes/ directory but always triggers a fresh API discovery.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughMulti-tenant sidecar now auto-discovers OAuth scopes dynamically via Lark API with 24-hour TTL caching. When ChangesScope auto-discovery and caching
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
The multi-tenant sidecar demo previously fell back to
offline_accesswhen the scope cache was empty duringhandleLogin, resulting inscope_count=1— effectively granting no useful permissions. This was a silent failure that was difficult to diagnose.This PR replaces the fallback with scope auto-discovery:
/open-apis/application/v6/applications/:app_idusing the sidecar's tenant access token to discover all enabled user scopes.discovered_scopes.jsonwith a 24-hour TTL. Fresh cache is used directly; stale cache triggers a background refresh.application:application:self_managescope. No silent fallback tooffline_access.auth_login_scopes/directory but always treats it as stale to trigger a fresh API discovery.Prerequisite
The app must have the
application:application:self_managescope enabled so the sidecar can query its own scope list (read-only introspection).Changes
auth_bridge.goresolveScopes(),discoverAppScopes(),loadScopeCache(),saveScopeCache(), scope cache types; modifyhandleLoginto use auto-discovery instead ofoffline_accessfallbackhandler_test.goREADME.mdTest plan
TestDiscoverAppScopes_Success— mock API server returns scopes, verify parsingTestScopeCacheRoundTrip— write/read cache, verify contentTestScopeCacheTTL— 25h-old cache is reported as staleTestResolveScopesNoFallbackToOfflineAccess— no cache + no API = empty (notoffline_access)TestResolveScopesUsesStaleOnAPIFailure— stale cache used when API failsMade with Cursor
Summary by CodeRabbit