Skip to content

Commit

Permalink
Merge pull request #122 from Olen/oauth_docker
Browse files Browse the repository at this point in the history
Retry with new auth_code and describe docker usage
  • Loading branch information
longstone authored Sep 6, 2023
2 parents 7c046f7 + d0071ab commit 6772ba2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,23 @@ Configure them in `config/withings_app.json`, for example:

For the callback URL you will need to setup a webserver hosting `contrib/withings.html`.

To do this in a Docker installation, you can use the environment variable `WITHINGS_APP` to point to a mounted `withings_app.json`

Example docker-compose:
```
withings-sync:
container_name: withings-sync
image: ghcr.io/jaroslawhartman/withings-sync:latest
volumes:
- "withings-sync:/root"
- "/etc/localtime:/etc/localtime:ro"
environment:
WITHINGS_APP: /root/withings_app.json
(...)
```
You can then add the app-config in `withings-sync/withings_app.json`


### Run a periodic docker-compose cronjob

We take the official docker image and override the entrypoint to crond.
Expand Down
10 changes: 9 additions & 1 deletion withings_sync/withings2.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,15 @@ def __init__(self):
self.user_config[
"authentification_code"
] = self.get_authenticationcode()
try:
self.get_accesstoken()
except Exception as e:
log.warning("Could not get access-token. Trying to renew auth_code")
self.user_config[
"authentification_code"
] = self.get_authenticationcode()
self.get_accesstoken()

self.get_accesstoken()

self.refresh_accesstoken()

Expand Down Expand Up @@ -142,6 +149,7 @@ def get_accesstoken(self):
"If it's regarding an invalid code, try to start the"
" script again to obtain a new link."
)
raise

self.user_config["access_token"] = body.get("access_token")
self.user_config["refresh_token"] = body.get("refresh_token")
Expand Down

0 comments on commit 6772ba2

Please sign in to comment.