feat(sdk): add AccessToken accessor to SDK#3775
Conversation
Expose a public AccessToken method on the SDK that returns a valid access token from the configured token source, passing the SDK's own HTTP client. Returns ErrNoAccessTokenSource when the SDK was created without credentials (nil token source) instead of panicking. Signed-off-by: Krish Suchak <suchak.krish@gmail.com>
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
|
Warning Review limit reached
Next review available in: 51 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe SDK gains an ChangesAuthentication access
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant SDK
participant AuthClient
participant tokenSource
SDK->>AuthClient: Auth()
AuthClient->>tokenSource: AccessToken(ctx, httpClient)
tokenSource-->>AuthClient: token or error
AuthClient-->>SDK: auth.AccessToken or validation error
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
|
@marythought thoughts on this being a top-level method on the SDK instance vs nested somewhere? It seems like we want to be cautious about how many methods are on the SDK client itself, right? |
@alkalescent Rather than a top-level method, could we put this behind an Auth() accessor on the SDK — so the call reads |
Move the top-level SDK.AccessToken method behind an Auth() accessor (s.Auth().AccessToken(ctx)) via a new AuthClient type to keep the SDK client's public surface lean. Also gate an empty token returned by the source, returning ErrAccessTokenInvalid. Addresses PR review feedback. Signed-off-by: Krish Suchak <suchak.krish@gmail.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@sdk/access_token_test.go`:
- Around line 12-17: Extend TestAccessToken_ReturnsTokenFromSource using a
recording token source, explicitly configure SDK.httpClient and the test
context, then call Auth().AccessToken with that context. Assert the source
received the exact context and HTTP client instances unchanged, while preserving
the existing token and no-error assertions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 4763a805-d722-4071-9816-34a149f58ef8
📒 Files selected for processing (3)
sdk/access_token_test.gosdk/auth_client.gosdk/sdk.go
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
Add a recording token source that verifies Auth().AccessToken forwards the context (via a propagated context value) and the exact httpClient instance to the underlying token source. Addresses PR review feedback. Signed-off-by: Krish Suchak <suchak.krish@gmail.com>
|
@marythought moved to |
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
|
marythought
left a comment
There was a problem hiding this comment.
thank you for doing this!
Proposed Changes
AccessToken(ctx context.Context) (auth.AccessToken, error)method on theSDKthat returns a valid access token from the configuredtokenSource, passing the SDK's own HTTP client (the same client the auth interceptor uses).ErrNoAccessTokenSourcesentinel when the SDK was constructed without credentials (nil token source) instead of panicking. Uncredentialed clients are a supported configuration (buildIDPTokenSourcereturns nil in that case).Checklist
Testing Instructions
cd sdk && go test . -race -run TestAccessTokenSummary by CodeRabbit
New Features
Tests