Skip to content

Commit

Permalink
Feat: improved oauth support (#4871)
Browse files Browse the repository at this point in the history
* chore: add error message to debug log

* chore: improve debug logging
  • Loading branch information
PeterSchafer committed Sep 21, 2023
1 parent 8fa2665 commit ec40392
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion cliv2/cmd/cliv2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func logHeaderAuthorizationInfo(

err := networkAccess.AddHeaders(apiRequest)
if err != nil {
return authorization, oauthEnabled, userAgent
debugLogger.Print(err)
}

authHeader := apiRequest.Header.Get("Authorization")
Expand All @@ -370,6 +370,8 @@ func logHeaderAuthorizationInfo(
token, err := auth.GetOAuthToken(config)
if token != nil && err == nil {
tokenDetails = fmt.Sprintf(" (type=oauth; expiry=%v)", token.Expiry.UTC())
temp := sha256.Sum256([]byte(token.AccessToken))
tokenShaSum = hex.EncodeToString(temp[0:16]) + "[...]"
}
}

Expand Down
7 changes: 4 additions & 3 deletions cliv2/internal/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import (

"github.com/google/uuid"

"github.com/snyk/cli/cliv2/internal/constants"
"github.com/snyk/cli/cliv2/internal/utils"
"github.com/snyk/go-application-framework/pkg/networking/certs"
"github.com/snyk/go-httpauth/pkg/httpauth"

"github.com/snyk/cli/cliv2/internal/constants"
"github.com/snyk/cli/cliv2/internal/utils"

"github.com/elazarl/goproxy"
"github.com/elazarl/goproxy/ext/auth"
)
Expand Down Expand Up @@ -136,7 +137,7 @@ func (p *WrapperProxy) ProxyInfo() *ProxyInfo {
func (p *WrapperProxy) replaceVersionHandler(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
err := p.addHeaderFunc(r)
if err != nil {
p.DebugLogger.Printf("Failed to add header")
p.DebugLogger.Printf("Failed to add header: %s", err)
}

return r, nil
Expand Down

0 comments on commit ec40392

Please sign in to comment.