Skip to content

Commit 4d65a75

Browse files
committed
Add support for Auth client
1 parent 0a342e9 commit 4d65a75

3 files changed

Lines changed: 40 additions & 16 deletions

File tree

auth0/v3/asyncify.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,40 @@ def __init__(
2929
protocol="https",
3030
rest_options=None,
3131
):
32-
super(AsyncClient, self).__init__(
33-
domain,
34-
token,
35-
telemetry,
36-
timeout,
37-
protocol,
38-
rest_options,
39-
)
32+
if token is None:
33+
# Wrap the auth client
34+
super(AsyncClient, self).__init__(domain, telemetry, timeout, protocol)
35+
else:
36+
# Wrap the mngtmt client
37+
super(AsyncClient, self).__init__(
38+
domain, token, telemetry, timeout, protocol, rest_options
39+
)
4040
self.client = AsyncRestClient(
4141
jwt=token, telemetry=telemetry, timeout=timeout, options=rest_options
4242
)
4343

4444
class Wrapper(cls):
45-
def __init__(self, *args, **kwargs):
46-
super(Wrapper, self).__init__(*args, **kwargs)
47-
self._async_client = AsyncClient(*args, **kwargs)
45+
def __init__(
46+
self,
47+
domain,
48+
token=None,
49+
telemetry=True,
50+
timeout=5.0,
51+
protocol="https",
52+
rest_options=None,
53+
):
54+
if token is None:
55+
# Wrap the auth client
56+
super(Wrapper, self).__init__(domain, telemetry, timeout, protocol)
57+
else:
58+
# Wrap the mngtmt client
59+
super(Wrapper, self).__init__(
60+
domain, token, telemetry, timeout, protocol, rest_options
61+
)
62+
63+
self._async_client = AsyncClient(
64+
domain, token, telemetry, timeout, protocol, rest_options
65+
)
4866
for method in methods:
4967
setattr(
5068
self,

auth0/v3/authentication/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(self, domain, telemetry=True, timeout=5.0, protocol="https"):
2828
self.domain = domain
2929
self.protocol = protocol
3030
self.client = RestClient(
31-
jwt=None,
31+
None,
3232
options=RestClientOptions(telemetry=telemetry, timeout=timeout, retries=0),
3333
)
3434

auth0/v3/rest_async.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ async def _request(self, *args, **kwargs):
6464
async with session.request(*args, **kwargs) as response:
6565
return await self._process_response(response)
6666

67-
async def get(self, url, params=None):
67+
async def get(self, url, params=None, headers=None):
68+
request_headers = self.base_headers.copy()
69+
request_headers.update(headers or {})
6870
# Track the API request attempt number
6971
attempt = 0
7072

@@ -77,7 +79,9 @@ async def get(self, url, params=None):
7779
attempt += 1
7880

7981
try:
80-
response = await self._request("get", url, params=params)
82+
response = await self._request(
83+
"get", url, params=params, headers=request_headers
84+
)
8185
return response
8286
except RateLimitError as e:
8387
# If the attempt number is greater than the configured retries, raise RateLimitError
@@ -91,8 +95,10 @@ async def get(self, url, params=None):
9195
# sleep() functions in seconds, so convert the milliseconds formula above accordingly
9296
await asyncio.sleep(wait / 1000)
9397

94-
async def post(self, url, data=None):
95-
return await self._request("post", url, json=data)
98+
async def post(self, url, data=None, headers=None):
99+
request_headers = self.base_headers.copy()
100+
request_headers.update(headers or {})
101+
return await self._request("post", url, json=data, headers=request_headers)
96102

97103
async def file_post(self, url, data=None, files=None):
98104
headers = self.base_headers.copy()

0 commit comments

Comments
 (0)