Skip to content

API-2197 [BE] Add client credentials auth support for Python SDK #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ run-docker:

.PHONY: stop-docker
stop-docker:
docker-compose down
docker-compose down

.PHONY: update-container-package
update-container-package:
docker-compose exec bynder-python-sdk sh -c "pip install -e ."
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ All sample files are located in the `./samples` directory.

> :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.

Update the package within container to reflect local changes by running

```bash
make update-container-package
```
This will run `pip install -e .` inside the container to use local package changes.

## Stopping the Docker Container

When you're done with your development or testing, you can stop the Docker container using the following command:
Expand Down
23 changes: 16 additions & 7 deletions bynder_sdk/client/bynder_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
REQUIRED_OAUTH_KWARGS = (
'client_id', 'client_secret', 'redirect_uri', 'scopes')

REQUIRED_OAUTH_KWARGS_CLIENT_CREDENTIALS = ('client_id', 'client_secret')


class BynderClient:
""" Main client used for setting up the OAuth2 session and
Expand All @@ -21,22 +23,29 @@ def __init__(self, domain, **kwargs):
self.session = PermanentTokenSession(
domain, kwargs['permanent_token'])
else:
missing = [
kw for kw in REQUIRED_OAUTH_KWARGS
if kwargs.get(kw) is None
]
if kwargs.get('client_credentials', None):
missing = [
kw for kw in REQUIRED_OAUTH_KWARGS_CLIENT_CREDENTIALS
if kwargs.get(kw) is None
]
else:
missing = [
kw for kw in REQUIRED_OAUTH_KWARGS
if kwargs.get(kw) is None
]

if missing:
raise TypeError(
f'Missing required arguments: {missing}'
)

# if client credentials use BackendApplicationClient from oauthlib, client suited for client credentials
client_credentials = BackendApplicationClient(kwargs['client_id']) if kwargs.get('client_credentials', None) == True else None
client_credentials = BackendApplicationClient(kwargs['client_id']) if kwargs.get('client_credentials', None) else None
self.session = BynderOAuth2Session(
domain,
kwargs['client_id'],
scope=kwargs['scopes'],
redirect_uri=kwargs['redirect_uri'],
scope=kwargs['scopes'] if kwargs.get('scopes', None) else None,
redirect_uri=kwargs['redirect_uri'] if kwargs.get('redirect_uri', None) else None,
auto_refresh_kwargs={
'client_id': kwargs['client_id'],
'client_secret': kwargs['client_secret']
Expand Down