deps: remove oauth2 in favor of bearerTransport#2462
Open
deps: remove oauth2 in favor of bearerTransport#2462
Conversation
Replace golang.org/x/oauth2 with a minimal bearerTransport (http.RoundTripper) that sets the Authorization header. oauth2 was only used to create an HTTP client with a static Bearer token, which doesn't require the full OAuth2 library. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Verify that bearerTransport correctly sets Authorization Bearer header, clones requests without modifying originals, and integrates properly with http.Client. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why (motivation for removing this dependency)
golang.org/x/oauth2provides the full OAuth2 authentication flowWhat (replacement details)
oauth2.NewClient()with a 15-linebearerTransport(http.RoundTripperimpl)detector/github.go: addedbearerTransporttype +newBearerClient()function, replaced 2 call sites ofoauth2.NewClientwithnewBearerClient(token)Safety (why this is safe)
oauth2.NewClientsource: for static tokens, it simply creates aTransportthat addsAuthorization: Bearer <token>. Our implementation does exactly thisreq.Clone()to avoid mutating the original requestTest plan
TestBearerTransport_SetsAuthorizationHeader- verifies the header is set toBearer <token>using httptestTestBearerTransport_ClonesRequest- verifies RoundTrip does not mutate original request headersTestNewBearerClient_ReturnsValidClient- end-to-end: verifies the returnedhttp.Clientsends the correct tokengo build ./cmd/...passgo test ./detector/...passReview hint (how to review efficiently)
bearerTransporttype +RoundTripmethod (15 lines) — this is the core replacementDetectGitHubSecurityAlertsandDetectGitHubDependencyGraphdiffs — 4 lines ofoauth2.*become 1 linenewBearerClient(token)github_test.gocovers the new implementation with 3 focused tests🤖 Generated with Claude Code