Skip to content

Commit 6c4d36c

Browse files
committed
feat: support httpx
1 parent c164f66 commit 6c4d36c

File tree

4 files changed

+117
-2
lines changed

4 files changed

+117
-2
lines changed

poetry.lock

Lines changed: 95 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ MacFSEvents = { version = "*", platform = "darwin" }
6969
pync = { version = "*", platform = "darwin" }
7070

7171
mkdocs = ">=1.4.2"
72+
httpx = "^0.28.1"
7273

7374
[tool.black]
7475

solid_client_credentials/solid_client_credentials_auth.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ def __call__(self, r: PreparedRequest) -> PreparedRequest:
1313
if not r.url:
1414
raise Exception(f"Unexpected request without url: {r}")
1515

16+
# for httpx, r.url is an URL object and not a string
17+
# so we convert it here
18+
url = str(r.url)
19+
1620
access_token = self._token_provider.get_uptodate_access_token()
17-
dpop_header = self._token_provider.get_dpop_header(r.url, method)
21+
dpop_header = self._token_provider.get_dpop_header(url, method)
1822

1923
r.headers["Authorization"] = f"DPoP {access_token}"
2024
r.headers["DPoP"] = dpop_header

tests/test_auth.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# pylint: disable=redefined-outer-name,unused-variable,expression-not-assigned,singleton-comparison
2+
import httpx
23
import requests
34

45
from solid_client_credentials import DpopTokenProvider, SolidClientCredentialsAuth
@@ -37,3 +38,18 @@ def can_make_request_with_query_param(expect, random_css_account: CssAcount):
3738
private_url = f"{random_css_account.pod_base_url}profile/?somekey=removeme"
3839
res = requests.get(private_url, auth=auth, timeout=5000)
3940
expect(res.status_code) == 200
41+
42+
def can_use_httpx(expect, random_css_account: CssAcount):
43+
credentials = get_client_credentials(random_css_account)
44+
issuer = random_css_account.css_base_url
45+
46+
token_provider = DpopTokenProvider(
47+
issuer_url=issuer,
48+
client_id=credentials.client_id,
49+
client_secret=credentials.client_secret,
50+
)
51+
auth = SolidClientCredentialsAuth(token_provider)
52+
53+
private_url = f"{random_css_account.pod_base_url}profile/"
54+
res = httpx.get(private_url, auth=auth, timeout=5000) # type: ignore
55+
expect(res.status_code) == 200

0 commit comments

Comments
 (0)