From 5481b9e51df0616d38c852afb4efef91ac244fc3 Mon Sep 17 00:00:00 2001 From: Greg Gauthier Date: Fri, 19 Jul 2024 19:18:53 +0100 Subject: [PATCH] a little cleanup --- api-client/eg.py | 18 ++++++------------ env_template | 2 +- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/api-client/eg.py b/api-client/eg.py index e5d38cf..a78ad56 100644 --- a/api-client/eg.py +++ b/api-client/eg.py @@ -14,6 +14,8 @@ username = os.getenv('USERNAME') password = os.getenv('PASSWORD') audience = os.getenv('AUDIENCE') scope = os.getenv('SCOPE', '').split(',') +api_url = os.getenv('API_URL') + def get_token(client_id, client_secret, token_url, username, password, audience, scope): client = BackendApplicationClient(client_id=client_id) @@ -30,24 +32,16 @@ def get_token(client_id, client_secret, token_url, username, password, audience, return token -def api_client(base_url, token): - client = OAuth2Session(token=token) - response = client.get(base_url) +def api_client(resource_url, auth_token): + client = OAuth2Session(token=auth_token) + response = client.get(resource_url) return response.content -client_id = '' -client_secret = '' -token_url = '' -username = '' -password = '' -audience = '' -scope = ['scope1', 'scope2'] - # Fetch token token = get_token(client_id, client_secret, token_url, username, password, audience, scope) # Now we can make API calls -api_response = api_client('https://api.example.com/resource', token) +api_response = api_client(api_url + '/resource', token) print(api_response) diff --git a/env_template b/env_template index b76f9c7..3fe19ae 100644 --- a/env_template +++ b/env_template @@ -1,4 +1,4 @@ -URL=https://api.dummy.com +API_URL=https://api.dummy.com CLIENT_ID=client_id CLIENT_SECRET=client_secret TOKEN_URL=oauth_token_fetch_url