Skip to content

Commit

Permalink
Merge pull request #7 from arthuRHD/main
Browse files Browse the repository at this point in the history
✨ Add proxy param to support corporate access
  • Loading branch information
sebastien-ollivier authored Jul 2, 2024
2 parents 70f8023 + 310fd3f commit ecdee4f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ session.auth = SGConnectAuth(client_id, client_secret, scopes=['myscope'], env='
request = session.get('https://api.sgmarkets.com/foo/v1/bar')
```

#### Corporate proxy

By default, no proxies are configured.

```python
proxies = {'https': '...', 'http': '...'}
session.auth = SGConnectAuth(client_id, client_secret, scopes=['...'], proxies=proxies)
```

### Development

```sh
Expand Down
4 changes: 3 additions & 1 deletion pysgconnect/sg_connect_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SGConnectAuth(AuthBase):
Authentication class to use with requests to protect calls by SGConnect OAuth2 protocol
"""

def __init__(self, client_id, client_secret, env="PRD", scopes=None):
def __init__(self, client_id, client_secret, env="PRD", scopes=None, proxies=None):
if isinstance(scopes, str):
scopes = [scopes]

Expand All @@ -23,6 +23,7 @@ def __init__(self, client_id, client_secret, env="PRD", scopes=None):
self._token: Token = Token()

self._credentials = (client_id, client_secret)
self._proxies: dict = proxies
self._scopes: list[str] | None = scopes

def __call__(self, request):
Expand All @@ -42,6 +43,7 @@ def _check_token(self) -> None:
self._endpoint,
verify=True,
auth=self._credentials,
proxies=self._proxies,
data={"grant_type": "client_credentials", "scope": " ".join(self._scopes)},
)

Expand Down

0 comments on commit ecdee4f

Please sign in to comment.