Skip to content

Agent Mesh

address review comments on token refresh error handling and validation

Antonio Ojea5e1d8e7d6d4b
diff --git a/cmd/sam-node/oidc.go b/cmd/sam-node/oidc.go
index ef6c7b10..0de8216b 100644
--- a/cmd/sam-node/oidc.go
+++ b/cmd/sam-node/oidc.go
@@ -380,8 +380,10 @@ func (n *SamNode) RefreshJWT(ctx context.Context, tokenURL, clientID, clientSecr
Error string `json:"error"`
ErrorDescription string `json:"error_description"`
}
- _ = json.NewDecoder(resp.Body).Decode(&errResp)
- return "", "", fmt.Errorf("refresh token request failed: %s - %s", errResp.Error, errResp.ErrorDescription)
+ if err := json.NewDecoder(resp.Body).Decode(&errResp); err == nil && errResp.Error != "" {
+ return "", "", fmt.Errorf("refresh token request failed (status %s): %s - %s", resp.Status, errResp.Error, errResp.ErrorDescription)
+ }
+ return "", "", fmt.Errorf("refresh token request failed with status: %s", resp.Status)
}
var tokenResp struct {
@@ -397,5 +399,8 @@ func (n *SamNode) RefreshJWT(ctx context.Context, tokenURL, clientID, clientSecr
if tokenResp.IdToken != "" {
jwtStr = tokenResp.IdToken
}
+ if jwtStr == "" {
+ return "", "", fmt.Errorf("token response did not contain an access_token or id_token")
+ }
return jwtStr, tokenResp.RefreshToken, nil
}