Skip to content
This repository was archived by the owner on Apr 26, 2025. It is now read-only.

Commit 137d6d9

Browse files
committed
Fix relative URL getter when host is set
1 parent 6eb4aa4 commit 137d6d9

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

fief_client/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ def _get_endpoint_url(
253253
rather stick to the host specified on the client configuration.
254254
"""
255255
if not absolute:
256-
return openid_configuration[field].split(self.base_url)[1]
256+
issuer = openid_configuration["issuer"]
257+
return openid_configuration[field].split(issuer)[1]
257258
return openid_configuration[field]
258259

259260
def _auth_url(

tests/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def _get_api_requests_mock(
119119
openid_configuration_route.return_value = Response(
120120
200,
121121
json={
122+
"issuer": f"{hostname}{path_prefix}",
122123
"authorization_endpoint": f"{hostname}{path_prefix}/authorize",
123124
"token_endpoint": f"{hostname}{path_prefix}/token",
124125
"userinfo_endpoint": f"{hostname}{path_prefix}/userinfo",
@@ -132,7 +133,9 @@ def _get_api_requests_mock(
132133
json={"keys": [signature_key.export(private_key=False, as_dict=True)]},
133134
)
134135

136+
print("YIELD")
135137
yield respx_mock
138+
print("RESET")
136139

137140
return _get_api_requests_mock
138141

tests/test_client.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -242,24 +242,13 @@ async def test_authorization_url_async(
242242
assert request.url.host == request.headers["Host"]
243243

244244
def test_authorization_url_tenant(
245-
self, fief_client_tenant: Fief, mock_api_requests: respx.MockRouter
245+
self, fief_client_tenant: Fief, get_api_requests_mock: GetAPIRequestsMock
246246
):
247-
openid_configuration_route = mock_api_requests.get(
248-
"/secondary/.well-known/openid-configuration"
249-
)
250-
openid_configuration_route.return_value = Response(
251-
200,
252-
json={
253-
"authorization_endpoint": "https://bretagne.fief.dev/secondary/authorize",
254-
"token_endpoint": "https://bretagne.fief.dev/secondary/token",
255-
"userinfo_endpoint": "https://bretagne.fief.dev/secondary/userinfo",
256-
"jwks_uri": "https://bretagne.fief.dev/secondary/.well-known/jwks.json",
257-
},
258-
)
247+
with get_api_requests_mock(path_prefix="/secondary"):
248+
authorize_url = fief_client_tenant.auth_url(
249+
"https://www.bretagne.duchy/callback"
250+
)
259251

260-
authorize_url = fief_client_tenant.auth_url(
261-
"https://www.bretagne.duchy/callback"
262-
)
263252
assert (
264253
authorize_url
265254
== "https://bretagne.fief.dev/secondary/authorize?response_type=code&client_id=CLIENT_ID&redirect_uri=https%3A%2F%2Fwww.bretagne.duchy%2Fcallback"

0 commit comments

Comments
 (0)