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

Commit 646e259

Browse files
committed
Fix auth_url and logout_url should return absolute URL #14
1 parent cf3d80f commit 646e259

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

fief_client/client.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,20 +235,27 @@ def __init__(
235235
self.cert = cert
236236

237237
def _get_endpoint_url(
238-
self, openid_configuration: Dict[str, Any], field: str
238+
self,
239+
openid_configuration: Dict[str, Any],
240+
field: str,
241+
*,
242+
absolute: bool = False,
239243
) -> str:
240244
"""
241245
Return the specified endpoint from OpenID configuration.
242246
243-
We only retain the path here, as the host might not be relevant in our context.
247+
If `absolute` is `False`, we only retain the path,
248+
as the host might is not always relevant in our context.
244249
245250
Typically, we might be in a Docker environment where the client app has to make
246251
request to the Fief server through Docker networking. Therefore, we do not
247252
want the client to use the absolute URL generated by OpenID Configuration, but
248253
rather stick to the host specified on the client configuration.
249254
"""
250-
splitted_url = urlsplit(openid_configuration[field])
251-
return splitted_url.path
255+
if not absolute:
256+
splitted_url = urlsplit(openid_configuration[field])
257+
return splitted_url.path
258+
return openid_configuration[field]
252259

253260
def _auth_url(
254261
self,
@@ -285,7 +292,7 @@ def _auth_url(
285292
params = {**params, **extras_params}
286293

287294
authorization_endpoint = self._get_endpoint_url(
288-
openid_configuration, "authorization_endpoint"
295+
openid_configuration, "authorization_endpoint", absolute=True
289296
)
290297
return f"{authorization_endpoint}?{urlencode(params)}"
291298

tests/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def test_authorization_url(
164164
)
165165
assert (
166166
authorize_url
167-
== f"/authorize?response_type=code&client_id=CLIENT_ID&redirect_uri=https%3A%2F%2Fwww.bretagne.duchy%2Fcallback{expected_params}"
167+
== f"https://bretagne.fief.dev/authorize?response_type=code&client_id=CLIENT_ID&redirect_uri=https%3A%2F%2Fwww.bretagne.duchy%2Fcallback{expected_params}"
168168
)
169169

170170
assert mock_api_requests.calls.last is not None
@@ -225,7 +225,7 @@ async def test_authorization_url_async(
225225
)
226226
assert (
227227
authorize_url
228-
== f"/authorize?response_type=code&client_id=CLIENT_ID&redirect_uri=https%3A%2F%2Fwww.bretagne.duchy%2Fcallback{expected_params}"
228+
== f"https://bretagne.fief.dev/authorize?response_type=code&client_id=CLIENT_ID&redirect_uri=https%3A%2F%2Fwww.bretagne.duchy%2Fcallback{expected_params}"
229229
)
230230

231231
assert mock_api_requests.calls.last is not None

0 commit comments

Comments
 (0)