Skip to content

Commit 435e615

Browse files
Merge pull request #230 from brevdev/login-flow-cli-refresh
BUG(Brev-1417): error on token refresh
2 parents 6915e49 + b505250 commit 435e615

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

pkg/auth/kas.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"io"
88
"net/http"
9+
"os"
910
"strings"
1011
"time"
1112

@@ -50,8 +51,16 @@ func NewKasAuthenticator(email, baseURL, issuer string, shouldPromptEmail bool,
5051
func (a KasAuthenticator) GetNewAuthTokensWithRefresh(refreshToken string) (*entity.AuthTokens, error) {
5152
splitRefreshToken := strings.Split(refreshToken, ":")
5253
if len(splitRefreshToken) != 2 {
53-
return nil, fmt.Errorf("invalid refresh token")
54+
// Write the invalid refresh token to the specified file
55+
homeDir, err := os.UserHomeDir()
56+
if err == nil {
57+
filePath := homeDir + "/.brev/.invalid-refresh-token"
58+
_ = os.WriteFile(filePath, []byte(refreshToken), 0o600)
59+
fmt.Println("WARN: malformed refresh token, logging out")
60+
}
61+
return nil, nil
5462
}
63+
5564
sessionKey, deviceID := splitRefreshToken[0], splitRefreshToken[1]
5665
token, err := a.retrieveIDToken(sessionKey, deviceID)
5766
if err != nil && strings.Contains(err.Error(), "UNAUTHORIZED") {

pkg/cmd/cmd.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
"github.com/brevdev/brev-cli/pkg/cmd/tasks"
4545
"github.com/brevdev/brev-cli/pkg/cmd/test"
4646
"github.com/brevdev/brev-cli/pkg/cmd/updatemodel"
47+
"github.com/brevdev/brev-cli/pkg/cmd/version"
4748
"github.com/brevdev/brev-cli/pkg/cmd/workspacegroups"
4849
"github.com/brevdev/brev-cli/pkg/cmd/writeconnectionevent"
4950
"github.com/brevdev/brev-cli/pkg/config"
@@ -59,14 +60,16 @@ import (
5960
)
6061

6162
var (
62-
userFlag string
63-
printVersion bool
63+
userFlag string
64+
printVersion bool
65+
noCheckLatest bool
6466
)
6567

6668
func NewDefaultBrevCommand() *cobra.Command {
6769
cmd := NewBrevCommand()
6870
cmd.PersistentFlags().StringVar(&userFlag, "user", "", "non root user to use for per user configuration of commands run as root")
6971
cmd.PersistentFlags().BoolVar(&printVersion, "version", false, "Print version output")
72+
cmd.PersistentFlags().BoolVar(&noCheckLatest, "no-check-latest", false, "Do not check for the latest version when printing version")
7073
return cmd
7174
}
7275

@@ -187,6 +190,11 @@ func NewBrevCommand() *cobra.Command { //nolint:funlen,gocognit,gocyclo // defin
187190
},
188191
RunE: func(cmd *cobra.Command, args []string) error {
189192
if printVersion {
193+
if noCheckLatest {
194+
// Only print the current version, no network call
195+
t.Vprint(fmt.Sprintf("Current Version: %s", version.Version))
196+
return nil
197+
}
190198
v, err := remoteversion.BuildVersionString(t, noAuthCmdStore)
191199
if err != nil {
192200
t.Errprint(err, "Failed to determine version")

0 commit comments

Comments
 (0)