Skip to content

Commit 2f11d96

Browse files
committed
API-2197 check for client credentials, use corresponding client in oauth library
1 parent cba49ff commit 2f11d96

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

bynder_sdk/client/bynder_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from bynder_sdk.client.workflow_client import WorkflowClient
55
from bynder_sdk.oauth2 import BynderOAuth2Session
66
from bynder_sdk.permanent_token import PermanentTokenSession
7+
from oauthlib.oauth2 import BackendApplicationClient
78

89
REQUIRED_OAUTH_KWARGS = (
910
'client_id', 'client_secret', 'redirect_uri', 'scopes')
@@ -29,6 +30,8 @@ def __init__(self, domain, **kwargs):
2930
f'Missing required arguments: {missing}'
3031
)
3132

33+
# if client credentials use BackendApplicationClient from oauthlib, client suited for client credentials
34+
client_credentials = BackendApplicationClient(kwargs['client_id']) if kwargs['client_credentials'] else None
3235
self.session = BynderOAuth2Session(
3336
domain,
3437
kwargs['client_id'],
@@ -38,7 +41,9 @@ def __init__(self, domain, **kwargs):
3841
'client_id': kwargs['client_id'],
3942
'client_secret': kwargs['client_secret']
4043
},
41-
token_updater=kwargs.get('token_saver', (lambda _: None))
44+
token_updater=kwargs.get('token_saver', (lambda _: None)),
45+
# if client is None, default to WebApplicationClient which uses authorization_code grant type
46+
client=client_credentials
4247
)
4348

4449
if kwargs.get('token') is not None:

samples/client.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,16 @@ def get_auth_client(self) -> BynderClient:
3939
# "scope": ["offline"],
4040
# "token_type": "bearer"
4141
# }
42-
if self.config_data.get('token', None) is None:
42+
43+
# auth code grant type
44+
if self.config_data.get('token', None) is None and self.config_data.get('client_credentials', None) is None:
4345
print(bynder_client.get_authorization_url())
4446

4547
code = input('Code: ')
4648
print(bynder_client.fetch_token(code))
4749

48-
return bynder_client
50+
# client credentials grant type
51+
elif self.config_data.get('token', None) is None and self.config_data.get('client_credentials', None):
52+
bynder_client.fetch_token(code=None)
53+
54+
return bynder_client

0 commit comments

Comments
 (0)