From 56c3fe6cfccf317e615ed476cd11e17f3e77a430 Mon Sep 17 00:00:00 2001 From: Greg Gauthier Date: Fri, 19 Jul 2024 18:47:03 +0100 Subject: [PATCH] add audience and scope --- api-client/eg.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/api-client/eg.py b/api-client/eg.py index 3f7334d..b07c1ac 100644 --- a/api-client/eg.py +++ b/api-client/eg.py @@ -2,11 +2,18 @@ from requests_oauthlib import OAuth2Session from oauthlib.oauth2 import BackendApplicationClient -def get_token(client_id, client_secret, token_url, username, password): +def get_token(client_id, client_secret, token_url, username, password, audience, scope): client = BackendApplicationClient(client_id=client_id) oauth = OAuth2Session(client=client) - token = oauth.fetch_token(token_url=token_url, username=username, password=password, client_id=client_id, - client_secret=client_secret) + token = oauth.fetch_token( + token_url=token_url, + username=username, + password=password, + client_id=client_id, + client_secret=client_secret, + audience=audience, + scope=scope + ) return token @@ -21,9 +28,13 @@ client_secret = '' token_url = '' username = '' password = '' +audience = '' +scope = ['scope1', 'scope2'] # Fetch token -token = get_token(client_id, client_secret, token_url, username, password) +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) + +print(api_response)