mirror of
https://github.com/sstent/go-garth.git
synced 2026-01-25 16:42:28 +00:00
1.8 KiB
1.8 KiB
High Priority (Fix These First):
Fix MFA Response Handling:
gofunc (a GarthAuthenticator) authenticate(/ params */) (*Token, error) { // ... existing code ...
if resp.StatusCode == http.StatusPreconditionFailed {
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("failed to read MFA challenge: %w", err)
}
return a.handleMFA(ctx, username, password, mfaToken, string(body))
}
// ... rest of method
}
Create Complete Client Factory:
go// Add to garth.go func NewGarminClient(ctx context.Context, username, password, mfaToken string) (*GarminClient, error) { storage := NewMemoryStorage() auth := NewAuthenticator(ClientOptions{ Storage: storage, TokenURL: "https://connectapi.garmin.com/oauth-service/oauth/token", Timeout: 30 * time.Second, })
token, err := auth.Login(ctx, username, password, mfaToken)
if err != nil {
return nil, err
}
transport := NewAuthTransport(auth.(*GarthAuthenticator), storage, nil)
httpClient := &http.Client{Transport: transport}
apiClient := NewAPIClient("https://connectapi.garmin.com", httpClient)
return &GarminClient{
Activities: NewActivityService(apiClient),
Profile: NewProfileService(apiClient),
Workouts: NewWorkoutService(apiClient),
}, nil
}
Add Integration Test:
go//go:build integration // +build integration
func TestRealGarminFlow(t *testing.T) { client, err := NewGarminClient(ctx, username, password, "") require.NoError(t, err)
// Test actual API calls
profile, err := client.Profile.Get(ctx)
require.NoError(t, err)
require.NotEmpty(t, profile.UserID)
activities, err := client.Activities.List(ctx, ActivityListOptions{Limit: 5})
require.NoError(t, err)
}