) to authenticate with Strava. You could look into this. Admittedly, I've been using it in the context of a Flask based application.
There is a function called refresh_token in the OAuth2Session class that can help you refresh a previous token. The below code snippet shows this function in use to refresh a previously received token that has expired. This is working for me as I'm subsequently able to call the APIs with this token in order to get the data I require.
from authlib.integrations.requests_client import OAuth2Session
my_token = {'refresh_token': strava_athlete.refresh_token,
'access_token': strava_athlete.access_token,
'expires_at': strava_athlete.access_token_expires_at,
'expires_in': strava_athlete.access_token_expires_in}
print("existing token", my_token)
oauth_session = OAuth2Session(flask.current_app.config['STRAVA_CLIENT_ID'],
flask.current_app.config['STRAVA_CLIENT_SECRET'],
authorization_endpoint=flask.current_app.config['STRAVA_CLIENT_DOMAIN'] + '/oauth/authorize',
token_endpoint=flask.current_app.config['STRAVA_CLIENT_DOMAIN'] + '/oauth/token',
token=my_token,
grant_type='refresh_token')
new_token = oauth_session.refresh_token(
url = flask.current_app.config['STRAVA_CLIENT_DOMAIN'] + '/oauth/token',
client_id=flask.current_app.config['STRAVA_CLIENT_ID'],
client_secret=flask.current_app.config['STRAVA_CLIENT_SECRET'])