diff --git a/enterprise/cmd/frontend/internal/auth/openidconnect/middleware.go b/enterprise/cmd/frontend/internal/auth/openidconnect/middleware.go index ff613e6098fb..adb248688395 100644 --- a/enterprise/cmd/frontend/internal/auth/openidconnect/middleware.go +++ b/enterprise/cmd/frontend/internal/auth/openidconnect/middleware.go @@ -2,6 +2,7 @@ package openidconnect import ( + "context" "encoding/base64" "encoding/json" "fmt" @@ -19,6 +20,7 @@ import ( "github.com/sourcegraph/sourcegraph/cmd/frontend/external/session" "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/database" + "github.com/sourcegraph/sourcegraph/internal/httpcli" "github.com/sourcegraph/sourcegraph/internal/types" "github.com/sourcegraph/sourcegraph/lib/errors" ) @@ -260,7 +262,7 @@ func AuthCallback(db database.DB, r *http.Request, stateCookieName, usernamePref } // Exchange the code for an access token, see http://openid.net/specs/openid-connect-core-1_0.html#TokenRequest. - oauth2Token, err := p.oauth2Config().Exchange(r.Context(), r.URL.Query().Get("code")) + oauth2Token, err := p.oauth2Config().Exchange(context.WithValue(r.Context(), oauth2.HTTPClient, httpcli.ExternalClient), r.URL.Query().Get("code")) if err != nil { return nil, "Authentication failed. Try signing in again. The error was: unable to obtain access token from issuer.", @@ -301,7 +303,7 @@ func AuthCallback(db database.DB, r *http.Request, stateCookieName, usernamePref errors.New("nonce is incorrect (possible replay attach)") } - userInfo, err := p.oidcUserInfo(r.Context(), oauth2.StaticTokenSource(oauth2Token)) + userInfo, err := p.oidcUserInfo(oidc.ClientContext(r.Context(), httpcli.ExternalClient), oauth2.StaticTokenSource(oauth2Token)) if err != nil { return nil, "Failed to get userinfo: " + err.Error(),