Skip to content

Commit 0ba559a

Browse files
authored
Fix jf eot response to a valid json (#1378)
1 parent 32508ce commit 0ba559a

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

general/token/oidctokenexchange.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package token
22

33
import (
4+
"encoding/json"
45
"fmt"
56
rtUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
67
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
@@ -74,6 +75,11 @@ type OidcParams struct {
7475
Repository string
7576
}
7677

78+
type ExchangeCommandOutputStruct struct {
79+
AccessToken string `json:"AccessToken"`
80+
Username string `json:"Username"`
81+
}
82+
7783
func NewOidcTokenExchangeCommand() *OidcTokenExchangeCommand {
7884
return &OidcTokenExchangeCommand{response: new(auth.OidcTokenResponseData), OidcParams: &OidcParams{}}
7985
}
@@ -150,7 +156,16 @@ func (otc *OidcTokenExchangeCommand) SetProviderTypeAsString(providerType string
150156
}
151157

152158
func (otc *OidcTokenExchangeCommand) PrintResponseToConsole() {
153-
log.Output(fmt.Sprintf("{ AccessToken: %s Username: %s }", otc.response.AccessToken, otc.response.Username))
159+
response := ExchangeCommandOutputStruct{
160+
AccessToken: otc.response.AccessToken,
161+
Username: otc.response.Username,
162+
}
163+
jsonOutput, err := json.Marshal(response)
164+
if err != nil {
165+
log.Error("Failed to marshal response to JSON:", err)
166+
return
167+
}
168+
log.Output(string(jsonOutput))
154169
}
155170

156171
func (otc *OidcTokenExchangeCommand) Run() (err error) {

0 commit comments

Comments
 (0)