From 0bb1b03d9c3dbc298528a0069a17bec8e4afaf9c Mon Sep 17 00:00:00 2001 From: sstent Date: Fri, 5 Sep 2025 09:02:26 -0700 Subject: [PATCH] sync 3 --- client.go | 3 ++- types.go | 10 +++++----- workouts_test.go | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/client.go b/client.go index 0b68efa..7cea2e0 100644 --- a/client.go +++ b/client.go @@ -30,7 +30,7 @@ func NewAuthTransport(auth *GarthAuthenticator, storage TokenStorage, base http. base: base, auth: auth, storage: storage, - userAgent: "GarthClient/1.0", + userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36", } } @@ -61,6 +61,7 @@ func (t *AuthTransport) RoundTrip(req *http.Request) (*http.Response, error) { // Add Authorization header req.Header.Set("Authorization", "Bearer "+token.OAuth2Token.AccessToken) req.Header.Set("User-Agent", t.userAgent) + req.Header.Set("Referer", "https://sso.garmin.com/sso/signin") // Execute request with retry logic var resp *http.Response diff --git a/types.go b/types.go index 6feeb66..13afd4b 100644 --- a/types.go +++ b/types.go @@ -26,7 +26,7 @@ type OAuth2Token struct { // IsExpired checks if the token has expired func (t *OAuth2Token) IsExpired() bool { - return time.Now().After(t.Expiry) + return time.Now().After(time.Unix(t.ExpiresAt, 0)) } // Token represents unified authentication credentials @@ -39,18 +39,18 @@ type Token struct { // IsExpired checks if the OAuth2 token has expired func (t *Token) IsExpired() bool { - if t.OAuth2 == nil { + if t.OAuth2Token == nil { return true } - return t.OAuth2.IsExpired() + return t.OAuth2Token.IsExpired() } // NeedsRefresh checks if token needs refresh (within 5 min expiry window) func (t *Token) NeedsRefresh() bool { - if t.OAuth2 == nil { + if t.OAuth2Token == nil { return true } - return time.Now().Add(5 * time.Minute).After(t.OAuth2.Expiry) + return time.Now().Add(5 * time.Minute).After(time.Unix(t.OAuth2Token.ExpiresAt, 0)) } // UserProfile represents Garmin user profile information diff --git a/workouts_test.go b/workouts_test.go index 15c3bff..03e3a4c 100644 --- a/workouts_test.go +++ b/workouts_test.go @@ -615,7 +615,7 @@ func TestWorkoutService_Export(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - expectedPath := "/workout-service/workout/" + tt.workoutID + "/export/" + tt.format + expectedPath := "/download-service/export/" + tt.format + "/workout/" + tt.workoutID if r.URL.Path != expectedPath { t.Errorf("expected path %s, got %s", expectedPath, r.URL.Path) }