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

Commit 6c01a2f

Browse files
committed
Force client to use relative URL to ease integration with Docker
1 parent bcec07d commit 6c01a2f

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

fief_client/client.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import uuid
44
from enum import Enum
55
from typing import Any, Dict, List, Mapping, Optional, Tuple, TypedDict, Union
6-
from urllib.parse import urlencode
6+
from urllib.parse import urlencode, urlsplit
77

88
import httpx
99
from httpx._types import CertTypes, VerifyTypes
@@ -237,7 +237,18 @@ def __init__(
237237
def _get_endpoint_url(
238238
self, openid_configuration: Dict[str, Any], field: str
239239
) -> str:
240-
return openid_configuration[field]
240+
"""
241+
Return the specified endpoint from OpenID configuration.
242+
243+
We only retain the path here, as the host might not be relevant in our context.
244+
245+
Typically, we might be in a Docker environment where the client app has to make
246+
request to the Fief server through Docker networking. Therefore, we do not
247+
want the client to use the absolute URL generated by OpenID Configuration, but
248+
rather stick to the host specified on the client configuration.
249+
"""
250+
splitted_url = urlsplit(openid_configuration[field])
251+
return splitted_url.path
241252

242253
def _auth_url(
243254
self,

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"https://bretagne.fief.dev/authorize?response_type=code&client_id=CLIENT_ID&redirect_uri=https%3A%2F%2Fwww.bretagne.duchy%2Fcallback{expected_params}"
167+
== f"/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"https://bretagne.fief.dev/authorize?response_type=code&client_id=CLIENT_ID&redirect_uri=https%3A%2F%2Fwww.bretagne.duchy%2Fcallback{expected_params}"
228+
== f"/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)