Skip to content

Commit

Permalink
fix: forward authorization header when getting gitlab tokens (#1982)
Browse files Browse the repository at this point in the history
  • Loading branch information
olevski authored Oct 2, 2024
1 parent 8b47163 commit acaa998
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion git-https-proxy/tokenstore/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,22 @@ func (s *TokenStore) refreshGitAccessToken(provider string) error {
return err
}
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", renkuAccessToken))
res, err := http.DefaultClient.Do(req)
// NOTE: Without the function below the authorization header is taken out before the request
// even hits the gateway proxy and therefore the token never reaches the gateway-auth module
// that swaps this authorization token for a gitlab token.
preserveAuthzHeader := func(req *http.Request, via []*http.Request) error {
if len(via) == 0 {
return nil
}
authz := via[0].Header.Get("Authorization")
if authz == "" {
return nil
}
req.Header.Set("Authorization", authz)
return nil
}
c := http.Client{Timeout: time.Second * 30, CheckRedirect: preserveAuthzHeader}
res, err := c.Do(req)
if err != nil {
return err
}
Expand Down

0 comments on commit acaa998

Please sign in to comment.