Skip to content

feat: replace garth with garminconnect for Garmin Connect uploads#79

Merged
jat255 merged 3 commits into
mainfrom
feature/issue-75-garth-to-garminconnect
Apr 27, 2026
Merged

feat: replace garth with garminconnect for Garmin Connect uploads#79
jat255 merged 3 commits into
mainfrom
feature/issue-75-garth-to-garminconnect

Conversation

@jat255

@jat255 jat255 commented Apr 27, 2026

Copy link
Copy Markdown
Owner

Background

Garmin changed their authentication flow to use Cloudflare TLS fingerprinting, which blocks garth's mobile user-agent (GCM-iOS-5.7.2.1). This prevents OAuth tokens from being created, breaking all uploads. Also, as of now, the garth project is effectively archived and so we should no longer rely on it.

This PR swaps out garth with python-garminconnect for authentication and uploading files.

Closes #75.

Changes

  • Dependency swap: garth>=0.5.21garminconnect>=0.3.3
  • get_garth_dir()get_token_dir(): Token storage moved from user_cache_path to user_data_path so tokens survive routine cache wipes; directory prefix changes from .garth_<name> to .garmin_<name>
  • upload() rewritten: Uses Garmin(email, password).login(tokenstore=...) + upload_activity(); raises ValueError immediately for missing credentials instead of prompting interactively
  • --show-dirs: Now shows the data directory and lists .garmin_* token directories
  • Logging: Removed oauth1_auth logger suppression (garth-specific)
  • Tests: Replaced mock_garth_* fixtures with mock_garmin_client; updated show-dirs tests for new directory names and locations

Upgrade behavior for users

  • Re-authentication happens automatically on first run after upgrade (no manual steps required)
  • Existing .garth_* directories are left behind as orphaned dirs; they cause no harm but can be manually deleted
  • garminconnect automatically falls back through multiple login strategies if rate-limited (429), so auth is resilient

Test plan

  • All 287 tests pass
  • ruff check and ruff format pass
  • Manual smoke test: fit-file-faker -u -d tests/files/mywhoosh_20260111.fit authenticated successfully via widget+cffi fallback strategy
  • Full upload test: fit-file-faker -u tests/files/mywhoosh_20260111.fit uploaded successfully to Garmin Connect
  • Token cached to ~/Library/Application Support/FitFileFaker/.garmin_<profile>/garmin_tokens.json

Garmin's Cloudflare TLS fingerprinting blocks garth's mobile user-agent,
breaking OAuth token creation and all uploads. Replace with
python-garminconnect v0.3.3+, which uses curl_cffi TLS impersonation and
automatic fallback login strategies to bypass rate limiting.

- Swap garth>=0.5.21 dependency for garminconnect>=0.3.3
- Rename get_garth_dir() to get_token_dir(); move token storage from
  user_cache_path to user_data_path so tokens survive cache wipes
- Token directory prefix changes from .garth_<name> to .garmin_<name>
- Rewrite upload() to use Garmin.login(tokenstore=) + upload_activity();
  raise ValueError immediately for missing credentials instead of
  prompting interactively
- Update --show-dirs output to show data directory and .garmin_* dirs
- Remove garth-specific oauth1_auth logger suppression
- Update tests: replace mock_garth_* fixtures with mock_garmin_client;
  update show-dirs tests for new directory names and locations
@jat255 jat255 added enhancement New feature or request garmin Related to Garmin uploads/connection labels Apr 27, 2026
@codecov-commenter

codecov-commenter commented Apr 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (d899364) to head (1b9839c).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #79   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines         1238      1226   -12     
=========================================
- Hits          1238      1226   -12     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jat255 jat255 force-pushed the feature/issue-75-garth-to-garminconnect branch from de29fef to 1b9839c Compare April 27, 2026 01:24
@jat255 jat255 merged commit 5ab22dc into main Apr 27, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request garmin Related to Garmin uploads/connection

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Garmin Connection

2 participants