cyberjunky / python-garminconnect

Python 3 API wrapper for Garmin Connect to get activity statistics
MIT License
802 stars 132 forks source link

Login using single string token (garth.loads method) #182

Closed Tiim closed 3 months ago

Tiim commented 6 months ago

Currently the only way to login is via username/password and via the tokens in a folder. However, garth supports parsing the tokens from a base64 encoded string as well using the loads method. Would this be something that you would be willing to implement?

My usecase is I want to create a github action that connects to garmin, and storing the token in a single secret is much more user friendly than having to use two secrets and writing them to the filesystem. I currently implement this by monkeypatching the library in the following way:

GARMIN_TOKEN = os.getenv("INPUT_GARMIN_TOKEN")

# monkeypatch login to support garth loads
def login(self):
    self.garth.loads(GARMIN_TOKEN)
    self.display_name = self.garth.profile["displayName"]
    self.full_name = self.garth.profile["fullName"]

    settings = self.garth.connectapi(self.garmin_connect_user_settings_url)
    self.unit_system = settings["userData"]["measurementSystem"]

Garmin.login = login
cyberjunky commented 5 months ago

I did this inside login(), so it's compatible with both ways:

if tokenstore:
    if len(tokenstore) > 512:
        self.garth.loads(tokenstore)
    else:
        self.garth.load(tokenstore)
else:
    self.garth.login(self.username, self.password)

What do you think?

cyberjunky commented 5 months ago

Added to version 0.2.13, are you able to test?

cyberjunky commented 3 months ago

@Tiim kindly reminder... not a must though ;-)

Tiim commented 3 months ago

Thanks a lot for implementing this and for the reminder. My side project that uses python-garminconnect is paused since I don't have enough spare time to work on it, so I am currently unable to test.

cyberjunky commented 3 months ago

Closing, please (re)open if needed!