Skip to content

Commit e0a6106

Browse files
committed
fix(core): Output curl string after request is made
1 parent 6d655d3 commit e0a6106

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

auth_providers/auth_core.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,19 +501,21 @@ func (c *CommandAuthConfig) Authenticate() error {
501501
}
502502

503503
c.HttpClient.Timeout = time.Duration(c.HttpClientTimeout) * time.Second
504+
505+
cResp, cErr := c.HttpClient.Do(req)
504506
curlStr, cErr := RequestToCurl(req)
505507
if cErr == nil {
506508
log.Printf("[TRACE] curl command: %s", curlStr)
507509
}
508510

509-
cResp, cErr := c.HttpClient.Do(req)
510511
if cErr != nil {
511512
return cErr
512513
} else if cResp == nil {
513514
return fmt.Errorf("failed to authenticate, no response received from Keyfactor Command")
514515
}
515516

516517
defer cResp.Body.Close()
518+
log.Printf("[DEBUG] request to Keyfactor Command API returned status code %d", cResp.StatusCode)
517519

518520
// check if body is empty
519521
if cResp.Body == nil {

auth_providers/auth_oauth.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"crypto/x509"
2020
"fmt"
21+
"log"
2122
"net/http"
2223
"os"
2324
"strings"
@@ -441,14 +442,22 @@ func (b *CommandConfigOauth) GetServerConfig() *Server {
441442

442443
// RoundTrip executes a single HTTP transaction, adding the OAuth2 token to the request
443444
func (t *oauth2Transport) RoundTrip(req *http.Request) (*http.Response, error) {
445+
log.Printf("[DEBUG] Attempting to get oAuth token from: %s %s", req.Method, req.URL)
444446
token, err := t.src.Token()
445447
if err != nil {
446448
return nil, fmt.Errorf("failed to retrieve OAuth token: %w", err)
447449
}
448450

451+
if token == nil || token.AccessToken == "" {
452+
return nil, fmt.Errorf("received empty OAuth token")
453+
}
454+
449455
// Clone the request to avoid mutating the original
456+
log.Printf("[DEBUG] Adding oAuth token to request: %s %s", req.Method, req.URL)
450457
reqCopy := req.Clone(req.Context())
451458
token.SetAuthHeader(reqCopy)
459+
requestCurlStr, _ := RequestToCurl(reqCopy)
460+
log.Printf("[TRACE] curl command: %s", requestCurlStr)
452461

453462
return t.base.RoundTrip(reqCopy)
454463
}

0 commit comments

Comments
 (0)