Skip to content

Commit

Permalink
Fix a bug where KC would fail to login if config file was empty
Browse files Browse the repository at this point in the history
  • Loading branch information
punmechanic committed Feb 7, 2025
1 parent 0fe05af commit 07515ad
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 1 addition & 2 deletions command/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ var accountsCmd = &cobra.Command{
if HasTokenExpired(config.Tokens) {
return ErrTokensExpiredOrAbsent
}

accounts, err := refreshAccounts(cmd.Context(), serverAddrURI, config.Tokens)
accounts, err := refreshAccounts(cmd.Context(), serverAddrURI, config)
if err != nil {
return fmt.Errorf("error refreshing accounts: %w", err)
}
Expand Down
7 changes: 7 additions & 0 deletions command/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ func (c Config) GetOAuthToken() (*TokenSet, bool) {
return c.Tokens, c.Tokens != nil
}

func (c Config) Token() (*oauth2.Token, error) {
if c.Tokens == nil {
return nil, nil
}
return c.Tokens.Token()
}

func HasTokenExpired(tok *TokenSet) bool {
if tok == nil {
return true
Expand Down
2 changes: 1 addition & 1 deletion command/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var rolesCmd = cobra.Command{
applicationID = account.ID
}

samlResponse, _, err := oauth2cli.DiscoverConfigAndExchangeTokenForAssertion(cmd.Context(), config.Tokens, oidcDomain, clientID, applicationID)
samlResponse, _, err := oauth2cli.DiscoverConfigAndExchangeTokenForAssertion(cmd.Context(), config, oidcDomain, clientID, applicationID)
if err != nil {
return err
}
Expand Down

0 comments on commit 07515ad

Please sign in to comment.