mirror of
https://github.com/sstent/go-garth.git
synced 2026-01-25 16:42:28 +00:00
sync 3
This commit is contained in:
@@ -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
|
||||
|
||||
10
types.go
10
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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user