Skip to content

Commit 8820251

Browse files
committed
fix: support get service account flow token again
1 parent 7ba5ffc commit 8820251

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

internal/cmd/auth/get-access-token/get_access_token.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
4444
return &cliErr.SessionExpiredError{}
4545
}
4646

47-
// Try to get a valid access token, refreshing if necessary
48-
accessToken, err := auth.RefreshAccessToken(params.Printer)
47+
// Get a valid access token for the current authentication flow
48+
// For user flows: refreshes if necessary, for service account flows: returns current token
49+
accessToken, err := auth.GetValidAccessToken(params.Printer)
4950
if err != nil {
5051
return err
5152
}

internal/pkg/auth/auth.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,22 @@ func getEmailFromToken(token string) (string, error) {
134134
return claims.Email, nil
135135
}
136136

137-
// RefreshAccessToken refreshes the access token if it's expired for the user token flow.
138-
// It returns the new access token or an error if the refresh fails.
139-
func RefreshAccessToken(p *print.Printer) (string, error) {
137+
// GetValidAccessToken returns a valid access token for the current authentication flow.
138+
// For user token flows, it refreshes the token if necessary.
139+
// For service account flows, it returns the current access token.
140+
func GetValidAccessToken(p *print.Printer) (string, error) {
140141
flow, err := GetAuthFlow()
141142
if err != nil {
142143
return "", fmt.Errorf("get authentication flow: %w", err)
143144
}
145+
146+
// For service account flows, just return the current token
147+
if flow == AUTH_FLOW_SERVICE_ACCOUNT_TOKEN || flow == AUTH_FLOW_SERVICE_ACCOUNT_KEY {
148+
return GetAccessToken()
149+
}
150+
144151
if flow != AUTH_FLOW_USER_TOKEN {
145-
return "", fmt.Errorf("token refresh is only supported for user token flow, current flow: %s", flow)
152+
return "", fmt.Errorf("unsupported authentication flow: %s", flow)
146153
}
147154

148155
// Load tokens from storage

0 commit comments

Comments
 (0)