Skip to content

Commit

Permalink
Use external http client for OIDC token exchange (#45162)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjlast committed Dec 5, 2022
1 parent 767ea73 commit 623cd1d
Showing 1 changed file with 4 additions and 2 deletions.
Expand Up @@ -2,6 +2,7 @@
package openidconnect

import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
Expand All @@ -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"
)
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 623cd1d

Please sign in to comment.