strava_connector
1""".. include:: ../README.md.""" 2 3import json 4from urllib.parse import parse_qs, urlparse 5 6from strava_connector.authenticator import Authenticator 7 8 9def initial_auth( 10 client_id: str, 11 client_secret: str, 12 client_token_path: str = ".tokens_client.json", # noqa: S107 13 strava_token_path: str = ".tokens_strava.json", # noqa: S107 14 to_print: bool = True, 15) -> None: 16 authenticator = Authenticator( 17 strava_token_path=strava_token_path, 18 client_token_path=client_token_path, 19 ) 20 21 auth_url = f"""http://www.strava.com/oauth/authorize?client_id={client_id}&response_type=code&redirect_uri=http://localhost/exchange_token&approval_prompt=force&scope=profile:read_all,activity:read_all""" 22 23 print("Click on the following authentication url.") 24 print("You will be redirected and have to click 'Authorize'.") 25 print("This redirects to a domain that does not resolve.") 26 print() 27 print(f"""[link={auth_url}]Click here.[/link]""") 28 print() 29 print("Paste the full url in here.") 30 redirect_url = input() 31 32 parsed_url = urlparse(redirect_url) 33 code = parse_qs(parsed_url.query)["code"][0] 34 35 authenticator.initial_auth( 36 client_secret=client_secret, 37 client_id=client_id, 38 code=code, 39 ) 40 if to_print: 41 with open(client_token_path) as _: 42 print(json.load(_)) 43 44 with open(strava_token_path) as _: 45 print(json.load(_))
def
initial_auth( client_id: str, client_secret: str, client_token_path: str = '.tokens_client.json', strava_token_path: str = '.tokens_strava.json', to_print: bool = True) -> None:
10def initial_auth( 11 client_id: str, 12 client_secret: str, 13 client_token_path: str = ".tokens_client.json", # noqa: S107 14 strava_token_path: str = ".tokens_strava.json", # noqa: S107 15 to_print: bool = True, 16) -> None: 17 authenticator = Authenticator( 18 strava_token_path=strava_token_path, 19 client_token_path=client_token_path, 20 ) 21 22 auth_url = f"""http://www.strava.com/oauth/authorize?client_id={client_id}&response_type=code&redirect_uri=http://localhost/exchange_token&approval_prompt=force&scope=profile:read_all,activity:read_all""" 23 24 print("Click on the following authentication url.") 25 print("You will be redirected and have to click 'Authorize'.") 26 print("This redirects to a domain that does not resolve.") 27 print() 28 print(f"""[link={auth_url}]Click here.[/link]""") 29 print() 30 print("Paste the full url in here.") 31 redirect_url = input() 32 33 parsed_url = urlparse(redirect_url) 34 code = parse_qs(parsed_url.query)["code"][0] 35 36 authenticator.initial_auth( 37 client_secret=client_secret, 38 client_id=client_id, 39 code=code, 40 ) 41 if to_print: 42 with open(client_token_path) as _: 43 print(json.load(_)) 44 45 with open(strava_token_path) as _: 46 print(json.load(_))