Skip to content

Commit 1f300a5

Browse files
committed
Remove associated_client
1 parent 89892b0 commit 1f300a5

4 files changed

Lines changed: 29 additions & 28 deletions

File tree

packages/auth0_api_python/README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,8 @@ async def main():
9898
api_client = ApiClient(ApiClientOptions(
9999
domain="<AUTH0_DOMAIN>",
100100
audience="<AUTH0_AUDIENCE>",
101-
associated_client={
102-
"client_id": "<AUTH0_CLIENT_ID>",
103-
"client_secret": "<AUTH0_CLIENT_SECRET>"
104-
}
101+
client_id="<AUTH0_CLIENT_ID>",
102+
client_secret="<AUTH0_CLIENT_SECRET>",
105103
))
106104
connection = "my-connection" # The Auth0 connection to the upstream idp
107105
access_token = "..." # The Auth0 access token to exchange

packages/auth0_api_python/src/auth0_api_python/api_client.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,10 @@ async def get_access_token_for_connection(self, options: dict[str, Any]) -> dict
422422
if not access_token:
423423
raise MissingRequiredArgumentError("access_token")
424424

425-
associated_client = self.options.associated_client
426-
if not associated_client:
427-
raise GetAccessTokenForConnectionError("You must configure the SDK with an associated_client to use get_access_token_for_connection.")
425+
client_id = self.options.client_id
426+
client_secret = self.options.client_secret
427+
if not client_id or not client_secret:
428+
raise GetAccessTokenForConnectionError("You must configure the SDK with a client_id and client_secret to use get_access_token_for_connection.")
428429

429430
metadata = await self._discover()
430431

@@ -437,7 +438,7 @@ async def get_access_token_for_connection(self, options: dict[str, Any]) -> dict
437438
"connection": connection,
438439
"requested_token_type": REQUESTED_TOKEN_TYPE_FEDERATED_CONNECTION_ACCESS_TOKEN,
439440
"grant_type": GRANT_TYPE_FEDERATED_CONNECTION_ACCESS_TOKEN,
440-
"client_id": associated_client["client_id"],
441+
"client_id": client_id,
441442
"subject_token": access_token,
442443
"subject_token_type": SUBJECT_TYPE_ACCESS_TOKEN,
443444
}
@@ -450,7 +451,7 @@ async def get_access_token_for_connection(self, options: dict[str, Any]) -> dict
450451
response = await client.post(
451452
token_endpoint,
452453
data=params,
453-
auth=(associated_client["client_id"], associated_client["client_secret"])
454+
auth=(client_id, client_secret)
454455
)
455456

456457
if response.status_code != 200:

packages/auth0_api_python/src/auth0_api_python/config.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
from typing import Callable, Optional
66

7-
from auth0_api_python.errors import MissingRequiredArgumentError
8-
97

108
class ApiClientOptions:
119
"""
@@ -19,8 +17,8 @@ class ApiClientOptions:
1917
dpop_required: Whether DPoP is required (default: False, allows both Bearer and DPoP).
2018
dpop_iat_leeway: Leeway in seconds for DPoP proof iat claim (default: 30).
2119
dpop_iat_offset: Maximum age in seconds for DPoP proof iat claim (default: 300).
22-
associated_client: Optional required if you want to use get_access_token_for_connection.
23-
Must be a dict with 'client_id' and 'client_secret' keys.
20+
client_id: Optional required if you want to use get_access_token_for_connection.
21+
client_secret: Optional required if you want to use get_access_token_for_connection.
2422
"""
2523
def __init__(
2624
self,
@@ -31,7 +29,8 @@ def __init__(
3129
dpop_required: bool = False,
3230
dpop_iat_leeway: int = 30,
3331
dpop_iat_offset: int = 300,
34-
associated_client: Optional[dict] = None,
32+
client_id: Optional[str] = None,
33+
client_secret: Optional[str] = None,
3534
):
3635
self.domain = domain
3736
self.audience = audience
@@ -40,9 +39,5 @@ def __init__(
4039
self.dpop_required = dpop_required
4140
self.dpop_iat_leeway = dpop_iat_leeway
4241
self.dpop_iat_offset = dpop_iat_offset
43-
self.associated_client = associated_client
44-
if associated_client:
45-
if not associated_client.get("client_id"):
46-
raise MissingRequiredArgumentError("associated_client.client_id")
47-
if not associated_client.get("client_secret"):
48-
raise MissingRequiredArgumentError("associated_client.client_secret")
42+
self.client_id = client_id
43+
self.client_secret = client_secret

packages/auth0_api_python/tests/test_api_client.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,8 @@ async def test_get_access_token_for_connection_success(httpx_mock: HTTPXMock):
16091609
options = ApiClientOptions(
16101610
domain="auth0.local",
16111611
audience="my-audience",
1612-
associated_client={"client_id": "cid", "client_secret": "csecret"}
1612+
client_id="cid",
1613+
client_secret="csecret",
16131614
)
16141615
api_client = ApiClient(options)
16151616
result = await api_client.get_access_token_for_connection({
@@ -1637,7 +1638,8 @@ async def test_get_access_token_for_connection_with_login_hint(httpx_mock: HTTPX
16371638
options = ApiClientOptions(
16381639
domain="auth0.local",
16391640
audience="my-audience",
1640-
associated_client={"client_id": "cid", "client_secret": "csecret"}
1641+
client_id="cid",
1642+
client_secret="csecret",
16411643
)
16421644
api_client = ApiClient(options)
16431645
result = await api_client.get_access_token_for_connection({
@@ -1658,7 +1660,8 @@ async def test_get_access_token_for_connection_missing_connection():
16581660
options = ApiClientOptions(
16591661
domain="auth0.local",
16601662
audience="my-audience",
1661-
associated_client={"client_id": "cid", "client_secret": "csecret"}
1663+
client_id="cid",
1664+
client_secret="csecret",
16621665
)
16631666
api_client = ApiClient(options)
16641667
with pytest.raises(MissingRequiredArgumentError):
@@ -1672,7 +1675,8 @@ async def test_get_access_token_for_connection_missing_access_token():
16721675
options = ApiClientOptions(
16731676
domain="auth0.local",
16741677
audience="my-audience",
1675-
associated_client={"client_id": "cid", "client_secret": "csecret"}
1678+
client_id="cid",
1679+
client_secret="csecret",
16761680
)
16771681
api_client = ApiClient(options)
16781682
with pytest.raises(MissingRequiredArgumentError):
@@ -1682,19 +1686,21 @@ async def test_get_access_token_for_connection_missing_access_token():
16821686

16831687

16841688
@pytest.mark.asyncio
1685-
async def test_get_access_token_for_connection_no_associated_client():
1689+
async def test_get_access_token_for_connection_no_client_id():
16861690
options = ApiClientOptions(
16871691
domain="auth0.local",
16881692
audience="my-audience"
1689-
# associated_client missing
1693+
# client_id missing
16901694
)
16911695
api_client = ApiClient(options)
1692-
with pytest.raises(GetAccessTokenForConnectionError):
1696+
with pytest.raises(GetAccessTokenForConnectionError) as err:
16931697
await api_client.get_access_token_for_connection({
16941698
"connection": "test-conn",
16951699
"access_token": "user-token"
16961700
})
16971701

1702+
assert "You must configure the SDK with a client_id and client_secret to use get_access_token_for_connection." == str(err.value)
1703+
16981704

16991705
@pytest.mark.asyncio
17001706
async def test_get_access_token_for_connection_token_endpoint_error(httpx_mock: HTTPXMock):
@@ -1714,7 +1720,8 @@ async def test_get_access_token_for_connection_token_endpoint_error(httpx_mock:
17141720
options = ApiClientOptions(
17151721
domain="auth0.local",
17161722
audience="my-audience",
1717-
associated_client={"client_id": "cid", "client_secret": "csecret"}
1723+
client_id="cid",
1724+
client_secret="csecret",
17181725
)
17191726
api_client = ApiClient(options)
17201727
with pytest.raises(ApiError) as err:

0 commit comments

Comments
 (0)