Skip to content

Commit

Permalink
Update Strava authorization (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
oldnapalm committed Mar 27, 2024
1 parent 7f80f9e commit 3497a10
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,29 @@ To obtain your current profile:

<details><summary>Expand</summary>

* __NOTE:__ instead of performing the steps below you can instead use the "Settings - Strava" button in the launcher window to authorize (Windows and macOS only).
* [OPTIONAL] Get CLIENT_ID and CLIENT_SECRET from https://www.strava.com/settings/api
* Get CLIENT_ID and CLIENT_SECRET from https://www.strava.com/settings/api

<details><summary>Using launcher (Windows and macOS only)</summary>

* Set the authorization callback domain of your API application to ``launcher.zwift.com``
* Create a ``strava-api.txt`` file in the ``storage`` directory containing your client ID and secret
```
CLIENT_ID
CLIENT_SECRET
```
* Use the "Settings - Strava" button in the launcher window to authorize.

</details>

<details><summary>Using strava_auth script</summary>

* Run ``scripts/strava_auth.py --client-id CLIENT_ID --client-secret CLIENT_SECRET``
* Or, if using the Windows zoffline.exe version without Python installed you can run ``strava_auth.exe`` obtained from https://github.com/zoffline/zwift-offline/releases/tag/zoffline_helper in place of ``scripts/strava_auth.py``
* Run without arguments to use default values.
* Open http://localhost:8000/ and authorize.
* Move the resulting ``strava_token.txt`` (saved in whatever directory you ran ``strava_auth.py`` in) into the ``storage/1`` directory.

</details>

* If testing, ride at least 300 meters, shorter activities won't be uploaded.

</details>
Expand Down
10 changes: 6 additions & 4 deletions cdn/static/web/launcher/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ <h4 class="text-shadow">Logged in as {{ username }}</h4>
{% endif %}
<a href="{{ url_for('power_curves', username=username) }}" class="btn btn-sm btn-secondary">Power curves</a>
<a href="{{ url_for('profile', username=username) }}" class="btn btn-sm btn-secondary">Zwift</a>
{% if not token %}
<a href="{{ url_for('strava') }}" class="btn btn-sm btn-secondary">Strava</a>
{% else %}
<a href="/delete/strava_token.txt" class="btn btn-sm btn-danger">Remove Strava token</a>
{% if api %}
{% if not token %}
<a href="{{ url_for('strava') }}" class="btn btn-sm btn-secondary">Strava</a>
{% else %}
<a href="/delete/strava_token.txt" class="btn btn-sm btn-danger">Remove Strava token</a>
{% endif %}
{% endif %}
<a href="{{ url_for('garmin', username=username) }}" class="btn btn-sm btn-secondary">Garmin</a>
<a href="{{ url_for('intervals', username=username) }}" class="btn btn-sm btn-secondary">Intervals</a>
Expand Down
4 changes: 2 additions & 2 deletions scripts/strava_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ def main(port, client_id, client_secret):
parser.add_argument('-p', '--port', help='Which port to bind to',
action='store', type=int, default=8000)
parser.add_argument('--client-id', help='Strava API Client ID',
action='store', type=int, default=28117)
action='store', type=int, required=True)
parser.add_argument('--client-secret', help='Strava API Client Secret',
action='store', default='41b7b7b76d8cfc5dc12ad5f020adfea17da35468')
action='store', required=True)
args = parser.parse_args()

main(port=args.port, client_id=args.client_id, client_secret=args.client_secret)
10 changes: 7 additions & 3 deletions zwift_offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,11 @@
with warnings.catch_warnings():
from stravalib.client import Client

STRAVA_CLIENT_ID = 28117
STRAVA_CLIENT_SECRET = '41b7b7b76d8cfc5dc12ad5f020adfea17da35468'
STRAVA_API_FILE = "%s/strava-api.txt" % STORAGE_DIR
if os.path.exists(STRAVA_API_FILE):
with open(STRAVA_API_FILE) as f:
STRAVA_CLIENT_ID = int(f.readline().rstrip('\r\n'))
STRAVA_CLIENT_SECRET = f.readline().rstrip('\r\n')

from tokens import *

Expand Down Expand Up @@ -942,8 +945,9 @@ def settings(username):
if os.path.isfile(achievements_file):
stat = os.stat(achievements_file)
achievements = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(stat.st_mtime))
api = os.path.isfile(STRAVA_API_FILE)
token = os.path.isfile(os.path.join(profile_dir, 'strava_token.txt'))
return render_template("settings.html", username=current_user.username, profile=profile, achievements=achievements, token=token)
return render_template("settings.html", username=current_user.username, profile=profile, achievements=achievements, api=api, token=token)


@app.route("/download/<filename>", methods=["GET"])
Expand Down

0 comments on commit 3497a10

Please sign in to comment.