|
1 |
| -import posixpath |
2 | 1 | import urllib.parse
|
3 | 2 | from collections.abc import Awaitable, Callable
|
4 | 3 | from typing import Any
|
@@ -167,23 +166,18 @@ def build_metadata(
|
167 | 166 | service_documentation_url: AnyHttpUrl | None,
|
168 | 167 | client_registration_options: ClientRegistrationOptions,
|
169 | 168 | revocation_options: RevocationOptions,
|
170 |
| -) -> OAuthMetadata: |
| 169 | +) -> OAuthMetadata: |
| 170 | + def append_path(path: str, endpoint_path: str) -> str: |
| 171 | + # Ensures the path ends with a slash |
| 172 | + path = f"{path}/" |
171 | 173 |
|
172 |
| - def append_path(issuer_url: str, endpoint_path: str) -> str: |
173 |
| - parsed = urllib.parse.urlparse(issuer_url) |
| 174 | + # Ensures the endpoint path does not start with a slash |
| 175 | + endpoint_path_lstrip = endpoint_path.lstrip("/") |
174 | 176 |
|
175 |
| - base_path = parsed.path.rstrip("/") |
176 |
| - endpoint_path = endpoint_path.lstrip("/") |
177 |
| - new_path = posixpath.join(base_path, endpoint_path) |
178 |
| - |
179 |
| - if not new_path.startswith("/"): |
180 |
| - new_path = "/" + new_path |
| 177 | + # Join the two paths and remove leading slashes This ensures that the final |
| 178 | + # path doesn't have double slashes between the host and the endpoint |
| 179 | + return urllib.parse.urljoin(path, endpoint_path_lstrip).lstrip("/") |
181 | 180 |
|
182 |
| - new_url = urllib.parse.urlunparse(parsed._replace(path=new_path)) |
183 |
| - |
184 |
| - if new_url.startswith("/"): |
185 |
| - new_url = new_url[1:] |
186 |
| - return new_url |
187 | 181 |
|
188 | 182 | authorization_url = modify_url_path(
|
189 | 183 | issuer_url, lambda path: append_path(path, AUTHORIZATION_PATH)
|
|
0 commit comments