From f8d38738eadc22b054165fcfebf90ee414872d9b Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Mon, 15 Mar 2021 09:57:05 +0100 Subject: [PATCH] Authenticate to Hello Asso by client id and secret --- .../management/commands/check_hello_asso.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/participation/management/commands/check_hello_asso.py b/apps/participation/management/commands/check_hello_asso.py index 4d63bae..35e22f2 100644 --- a/apps/participation/management/commands/check_hello_asso.py +++ b/apps/participation/management/commands/check_hello_asso.py @@ -10,6 +10,17 @@ import requests class Command(BaseCommand): def handle(self, *args, **options): # noqa: C901 + # Get access token + response = requests.post('https://api.helloasso.com/oauth2/token', headers={ + 'Content-Type': 'application/x-www-form-urlencoded', + }, data={ + 'client_id': os.getenv('HELLOASSO_CLIENT_ID', ''), + 'client_secret': os.getenv('HELLOASSO_CLIENT_SECRET', ''), + 'grant_type': 'client_credentials', + }).json() + + token = response['access_token'] + organization = "animath" form_slug = "tfjm-2021" from_date = "2000-01-01" @@ -17,7 +28,7 @@ class Command(BaseCommand): f"?from={from_date}&pageIndex=1&pageSize=10000&retrieveOfflineDonations=false" headers = { "Accept": "application/json", - "Authorization": f"Bearer {os.getenv('HELLO_ASSO_TOKEN', '')}", + "Authorization": f"Bearer {token}", } http_response = requests.get(url, headers=headers) response = http_response.json()