extsvc: unify OAuth and username/password authentication methods in outbound requests
Created by: LawnGnome
Right now, all the external service client implementations have their own versions of adding authentication headers to outbound requests. In practice, there's a lot of commonality between the methods: an OAuth bearer token is always going to look the same, but we have repeated req.Header.Set("Authorization", "Bearer ...")
calls.
Unifying these makes it easier for campaigns to add support for generic user tokens: rather than having to implement code host specific switches in the campaigns and repo-updater packges, we can instead implement these once in internal/extsvc
and use the generic types in the relevant campaigns tables, which is a significant win.
I've elected to only update github
, gitlab
, and bitbucketserver
, mostly because (a) that's what we need for campaigns, and (b) there are diminishing returns after that, since the other service types only support one method of authentication, and that method isn't always standard.
Implementation wise, there isn't much of note here. OAuthBearerToken
probably looks a touch overengineered having a struct
with a field right now instead of just being a type alias for string
, but this pays off in the next PR.
This is part of #14989.
Merge request reports
Activity
Created by: codecov[bot]
Codecov Report
Merging #15077 into main will increase coverage by
0.04%
. The diff coverage is63.41%
.@@ Coverage Diff @@ ## main #15077 +/- ## ========================================== + Coverage 52.56% 52.60% +0.04% ========================================== Files 1610 1615 +5 Lines 80458 80501 +43 Branches 7110 7001 -109 ========================================== + Hits 42293 42350 +57 + Misses 34338 34325 -13 + Partials 3827 3826 -1
Flag Coverage Δ #go 52.60% <63.41%> (+0.07%)
#integration 30.36% <ø> (-0.13%)
#storybook 26.12% <ø> (ø)
#typescript 52.62% <ø> (-0.04%)
#unit 34.29% <ø> (ø)
Impacted Files Coverage Δ ...terprise/internal/codeintel/httpapi/auth_github.go 0.00% <0.00%> (ø)
internal/authz/github/client.go 42.85% <0.00%> (-7.15%)
internal/extsvc/gitlab/client.go 34.34% <0.00%> (+2.26%)
internal/extsvc/bitbucketserver/client.go 54.35% <65.30%> (+5.44%)
internal/extsvc/github/client.go 67.12% <80.00%> (-0.48%)
cmd/repo-updater/repos/github.go 64.08% <100.00%> (+0.10%)
...nterprise/cmd/frontend/auth/githuboauth/session.go 75.90% <100.00%> (ø)
internal/authz/bitbucketserver/provider.go 76.99% <100.00%> (-1.39%)
internal/authz/github/github.go 72.00% <100.00%> (ø)
internal/extsvc/auth/basic.go 100.00% <100.00%> (ø)
... and 18 more Created by: sourcegraph-bot
Notifying subscribers in CODENOTIFY files for diff 34dc5ac868a26c6807c7559d72609f9f4b5f7a13...2c81fe56ece800aac5bc4ba8accc305bd05534d8.
Notify File(s) @efritz enterprise/internal/codeintel/httpapi/auth_github.go @nicksnyder internal/extsvc/CODENOTIFY
internal/extsvc/auth/CODENOTIFY