Skip to content

Commit 28e0197

Browse files
authored
API-2197 [BE] Add client credentials auth support for Python SDK (#48)
* API-2197 check for client credentials, use corresponding client in oauth library * API-2197 check for client credentials key * API-2197 check for client credentials key and boolean value * API-2197 update README for client credentials usage * API-2197 add Makefile command to update container package, remove checks for scopes/redirect uri for client credentials
1 parent fe1f34e commit 28e0197

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,8 @@ run-docker:
4848

4949
.PHONY: stop-docker
5050
stop-docker:
51-
docker-compose down
51+
docker-compose down
52+
53+
.PHONY: update-container-package
54+
update-container-package:
55+
docker-compose exec bynder-python-sdk sh -c "pip install -e ."

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,13 @@ All sample files are located in the `./samples` directory.
273273

274274
> :warning: Caution: The sample scripts are provided as examples. It is crucial to review, add and/or modify the commands before execution. The container updates automatically with changes, ensuring a seamless development experience. Always exercise caution when executing scripts.
275275
276+
Update the package within container to reflect local changes by running
277+
278+
```bash
279+
make update-container-package
280+
```
281+
This will run `pip install -e .` inside the container to use local package changes.
282+
276283
## Stopping the Docker Container
277284

278285
When you're done with your development or testing, you can stop the Docker container using the following command:

bynder_sdk/client/bynder_client.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
REQUIRED_OAUTH_KWARGS = (
1010
'client_id', 'client_secret', 'redirect_uri', 'scopes')
1111

12+
REQUIRED_OAUTH_KWARGS_CLIENT_CREDENTIALS = ('client_id', 'client_secret')
13+
1214

1315
class BynderClient:
1416
""" Main client used for setting up the OAuth2 session and
@@ -21,22 +23,29 @@ def __init__(self, domain, **kwargs):
2123
self.session = PermanentTokenSession(
2224
domain, kwargs['permanent_token'])
2325
else:
24-
missing = [
25-
kw for kw in REQUIRED_OAUTH_KWARGS
26-
if kwargs.get(kw) is None
27-
]
26+
if kwargs.get('client_credentials', None):
27+
missing = [
28+
kw for kw in REQUIRED_OAUTH_KWARGS_CLIENT_CREDENTIALS
29+
if kwargs.get(kw) is None
30+
]
31+
else:
32+
missing = [
33+
kw for kw in REQUIRED_OAUTH_KWARGS
34+
if kwargs.get(kw) is None
35+
]
36+
2837
if missing:
2938
raise TypeError(
3039
f'Missing required arguments: {missing}'
3140
)
3241

3342
# if client credentials use BackendApplicationClient from oauthlib, client suited for client credentials
34-
client_credentials = BackendApplicationClient(kwargs['client_id']) if kwargs.get('client_credentials', None) == True else None
43+
client_credentials = BackendApplicationClient(kwargs['client_id']) if kwargs.get('client_credentials', None) else None
3544
self.session = BynderOAuth2Session(
3645
domain,
3746
kwargs['client_id'],
38-
scope=kwargs['scopes'],
39-
redirect_uri=kwargs['redirect_uri'],
47+
scope=kwargs['scopes'] if kwargs.get('scopes', None) else None,
48+
redirect_uri=kwargs['redirect_uri'] if kwargs.get('redirect_uri', None) else None,
4049
auto_refresh_kwargs={
4150
'client_id': kwargs['client_id'],
4251
'client_secret': kwargs['client_secret']

0 commit comments

Comments
 (0)