Skip to content

Commit 7a5f6f8

Browse files
committed
fix(core): Output auth config params before calling Authenticate()
Signed-off-by: spbsoluble <1661003+spbsoluble@users.noreply.github.com>
1 parent 0ae8be1 commit 7a5f6f8

File tree

6 files changed

+84
-23
lines changed

6 files changed

+84
-23
lines changed

cmd/login.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,32 @@ WARNING: This will write the environmental credentials to disk and will be store
235235
}
236236

237237
if authType == "oauth" {
238-
log.Debug().Msg("attempting to authenticate via OAuth")
238+
log.Debug().
239+
Str("profile", profile).
240+
Str("configFile", configFile).
241+
Str("host", outputServer.Host).
242+
Str("authType", authType).
243+
Str("accessToken", hashSecretValue(kfcOAuth.AccessToken)).
244+
Str("clientID", kfcOAuth.ClientID).
245+
Str("clientSecret", hashSecretValue(kfcOAuth.ClientSecret)).
246+
Str("apiPath", kfcOAuth.CommandAPIPath).
247+
Msg("attempting to authenticate via OAuth")
239248
aErr := kfcOAuth.Authenticate()
240249
if aErr != nil {
241250
log.Error().Err(aErr)
242251
return aErr
243252
}
244253
} else if authType == "basic" {
245-
log.Debug().Msg("attempting to authenticate via Basic Auth")
254+
log.Debug().
255+
Str("profile", profile).
256+
Str("configFile", configFile).
257+
Str("host", outputServer.Host).
258+
Str("authType", authType).
259+
Str("username", kfcBasicAuth.Username).
260+
Str("domain", kfcBasicAuth.Domain).
261+
Str("password", hashSecretValue(kfcBasicAuth.Password)).
262+
Str("apiPath", kfcBasicAuth.CommandAPIPath).
263+
Msg("attempting to authenticate via Basic Auth")
246264
aErr := kfcBasicAuth.Authenticate()
247265
if aErr != nil {
248266
log.Error().Err(aErr)

cmd/root.go

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ func getServerConfigFromEnv() (*auth_providers.Server, error) {
134134
apiPath, aOk := os.LookupEnv(auth_providers.EnvKeyfactorAPIPath)
135135
clientId, cOk := os.LookupEnv(auth_providers.EnvKeyfactorClientID)
136136
clientSecret, csOk := os.LookupEnv(auth_providers.EnvKeyfactorClientSecret)
137+
audience, _ := os.LookupEnv(auth_providers.EnvKeyfactorAuthAudience)
138+
scopesCSV, _ := os.LookupEnv(auth_providers.EnvKeyfactorAuthScopes)
139+
var scopes []string
140+
if scopesCSV != "" {
141+
scopes = strings.Split(scopesCSV, ",")
142+
}
143+
137144
tokenUrl, tOk := os.LookupEnv(auth_providers.EnvKeyfactorAuthTokenURL)
138145
skipVerify, svOk := os.LookupEnv(auth_providers.EnvKeyfactorSkipVerify)
139146
var skipVerifyBool bool
@@ -160,24 +167,44 @@ func getServerConfigFromEnv() (*auth_providers.Server, error) {
160167
}
161168

162169
if isBasicAuth {
163-
log.Debug().
164-
Str("username", username).
165-
Str("password", hashSecretValue(password)).
166-
Str("domain", domain).
167-
Str("hostname", hostname).
170+
171+
log.Debug().Str("hostname", hostname).
168172
Str("apiPath", apiPath).
169173
Bool("skipVerify", skipVerifyBool).
170-
Msg("call: basicAuthNoParamsConfig.Authenticate()")
174+
Msg("setting up basic auth client base configuration")
171175
basicAuthNoParamsConfig.WithCommandHostName(hostname).
172176
WithCommandAPIPath(apiPath).
173177
WithSkipVerify(skipVerifyBool)
174178

175-
bErr := basicAuthNoParamsConfig.
179+
log.Debug().
180+
Str("username", username).
181+
Str("password", hashSecretValue(password)).
182+
Str("domain", domain).
183+
Msg("setting up basic auth configuration")
184+
_ = basicAuthNoParamsConfig.
176185
WithUsername(username).
177186
WithPassword(password).
178-
WithDomain(domain).
179-
Authenticate()
180-
log.Debug().Msg("complete: basicAuthNoParamsConfig.Authenticate()")
187+
WithDomain(domain)
188+
189+
log.Debug().
190+
Str("username", basicAuthNoParamsConfig.Username).
191+
Str("password", hashSecretValue(password)).
192+
Str("domain", basicAuthNoParamsConfig.Domain).
193+
Str("hostname", basicAuthNoParamsConfig.CommandHostName).
194+
Str("apiPath", basicAuthNoParamsConfig.CommandAPIPath).
195+
Bool("skipVerify", basicAuthNoParamsConfig.CommandAuthConfig.SkipVerify).
196+
Msg(fmt.Sprintf("%s basicAuthNoParamsConfig.Authenticate()", DebugFuncCall))
197+
198+
bErr := basicAuthNoParamsConfig.Authenticate()
199+
log.Debug().
200+
Str("username", basicAuthNoParamsConfig.Username).
201+
Str("password", hashSecretValue(password)).
202+
Str("domain", basicAuthNoParamsConfig.Domain).
203+
Str("hostname", basicAuthNoParamsConfig.CommandHostName).
204+
Str("apiPath", basicAuthNoParamsConfig.CommandAPIPath).
205+
Bool("skipVerify", basicAuthNoParamsConfig.CommandAuthConfig.SkipVerify).
206+
Msg("complete: basicAuthNoParamsConfig.Authenticate()")
207+
181208
if bErr != nil {
182209
log.Error().Err(bErr).Msg("unable to authenticate with provided credentials")
183210
return nil, bErr
@@ -186,16 +213,36 @@ func getServerConfigFromEnv() (*auth_providers.Server, error) {
186213
return basicAuthNoParamsConfig.GetServerConfig(), nil
187214
} else if isOAuth {
188215
log.Debug().
189-
Str("clientId", clientId).
190-
Str("clientSecret", hashSecretValue(clientSecret)).
191-
Str("tokenUrl", tokenUrl).
192216
Str("hostname", hostname).
193217
Str("apiPath", apiPath).
194218
Bool("skipVerify", skipVerifyBool).
195-
Msg("call: oAuthNoParamsConfig.Authenticate()")
219+
Msg("setting up oAuth client base configuration")
196220
_ = oAuthNoParamsConfig.CommandAuthConfig.WithCommandHostName(hostname).
197221
WithCommandAPIPath(apiPath).
198222
WithSkipVerify(skipVerifyBool)
223+
224+
log.Debug().
225+
Str("clientId", clientId).
226+
Str("clientSecret", hashSecretValue(clientSecret)).
227+
Str("tokenUrl", tokenUrl).
228+
Str("audience", audience).
229+
Strs("scopes", scopes).
230+
Msg("setting up oAuth configuration")
231+
_ = oAuthNoParamsConfig.WithClientId(clientId).
232+
WithClientSecret(clientSecret).
233+
WithTokenUrl(tokenUrl).
234+
WithAudience(audience).
235+
WithScopes(scopes)
236+
237+
log.Debug().
238+
Str("clientId", oAuthNoParamsConfig.ClientID).
239+
Str("clientSecret", hashSecretValue(oAuthNoParamsConfig.ClientSecret)).
240+
Str("tokenUrl", oAuthNoParamsConfig.TokenURL).
241+
Str("hostname", oAuthNoParamsConfig.CommandHostName).
242+
Str("apiPath", oAuthNoParamsConfig.CommandAPIPath).
243+
Bool("skipVerify", oAuthNoParamsConfig.SkipVerify).
244+
Str("caCert", oAuthNoParamsConfig.CommandCACert).
245+
Msg(fmt.Sprintf("%s oAuthNoParamsConfig.Authenticate()", DebugFuncCall))
199246
oErr := oAuthNoParamsConfig.Authenticate()
200247
log.Debug().Msg("complete: oAuthNoParamsConfig.Authenticate()")
201248
if oErr != nil {

cmd/rot.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import (
2020
"encoding/json"
2121
"errors"
2222
"fmt"
23-
"io"
24-
stdlog "log"
2523
"os"
2624
"strconv"
2725
"strings"

cmd/storeTypes.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import (
2626
"strings"
2727
"time"
2828

29-
stdlog "log"
30-
3129
"github.com/AlecAivazis/survey/v2"
3230
"github.com/Keyfactor/keyfactor-go-client/v3/api"
3331
"github.com/rs/zerolog/log"

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.18.0
1010
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.9.0
1111
github.com/Jeffail/gabs v1.4.0
12-
github.com/Keyfactor/keyfactor-auth-client-go v1.2.1-rc.1
12+
github.com/Keyfactor/keyfactor-auth-client-go v1.2.1-rc.2
1313
github.com/Keyfactor/keyfactor-go-client-sdk/v2 v2.0.0
1414
github.com/Keyfactor/keyfactor-go-client/v3 v3.1.0
1515
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ github.com/AzureAD/microsoft-authentication-library-for-go v1.4.2 h1:oygO0locgZJ
1818
github.com/AzureAD/microsoft-authentication-library-for-go v1.4.2/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI=
1919
github.com/Jeffail/gabs v1.4.0 h1://5fYRRTq1edjfIrQGvdkcd22pkYUrHZ5YC/H2GJVAo=
2020
github.com/Jeffail/gabs v1.4.0/go.mod h1:6xMvQMK4k33lb7GUUpaAPh6nKMmemQeg5d4gn7/bOXc=
21-
github.com/Keyfactor/keyfactor-auth-client-go v1.2.1-rc.1 h1:9g6ltxTHfMC65i5VOfVERaATkTHAlF2hfRHztiriQAg=
22-
github.com/Keyfactor/keyfactor-auth-client-go v1.2.1-rc.1/go.mod h1:7htRcBIWn+X4fI5jaYBALSYwP84H/djN7d8y3n0ZDQ0=
21+
github.com/Keyfactor/keyfactor-auth-client-go v1.2.1-rc.2 h1:iYl9uaj/YB/5AE/WFl4FP5FP3Cu5I01r+jXNES018vw=
22+
github.com/Keyfactor/keyfactor-auth-client-go v1.2.1-rc.2/go.mod h1:7htRcBIWn+X4fI5jaYBALSYwP84H/djN7d8y3n0ZDQ0=
2323
github.com/Keyfactor/keyfactor-go-client-sdk/v2 v2.0.0 h1:ehk5crxEGVBwkC8yXsoQXcyITTDlgbxMEkANrl1dA2Q=
2424
github.com/Keyfactor/keyfactor-go-client-sdk/v2 v2.0.0/go.mod h1:11WXGG9VVKSV0EPku1IswjHbGGpzHDKqD4pe2vD7vas=
2525
github.com/Keyfactor/keyfactor-go-client/v3 v3.1.0 h1:DQgb93m3xHZZ0FxWGFS90XI8prwS5fmIGrXNxP2IfHM=

0 commit comments

Comments
 (0)