1- import urllib .parse
21from collections .abc import Awaitable , Callable
32from typing import Any
43
@@ -148,41 +147,18 @@ def create_auth_routes(
148147 return routes
149148
150149
151- def modify_url_path (url : AnyHttpUrl , path_mapper : Callable [[str ], str ]) -> AnyHttpUrl :
152- return AnyHttpUrl .build (
153- scheme = url .scheme ,
154- username = url .username ,
155- password = url .password ,
156- host = url .host ,
157- port = url .port ,
158- path = path_mapper (url .path or "" ),
159- query = url .query ,
160- fragment = url .fragment ,
161- )
162-
163-
164150def build_metadata (
165151 issuer_url : AnyHttpUrl ,
166152 service_documentation_url : AnyHttpUrl | None ,
167153 client_registration_options : ClientRegistrationOptions ,
168154 revocation_options : RevocationOptions ,
169- ) -> OAuthMetadata :
170- def append_path (path : str , endpoint_path : str ) -> str :
171- # Ensures the path ends with a slash
172- path = f"{ path } /"
173-
174- # Ensures the endpoint path does not start with a slash
175- endpoint_path_lstrip = endpoint_path .lstrip ("/" )
176-
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 ("/" )
180-
181-
182- authorization_url = modify_url_path (
183- issuer_url , lambda path : append_path (path , AUTHORIZATION_PATH )
155+ ) -> OAuthMetadata :
156+ authorization_url = AnyHttpUrl (
157+ str (issuer_url ).rstrip ("/" ) + AUTHORIZATION_PATH
158+ )
159+ token_url = AnyHttpUrl (
160+ str (issuer_url ).rstrip ("/" ) + TOKEN_PATH
184161 )
185- token_url = modify_url_path (issuer_url , lambda path : append_path (path , TOKEN_PATH ))
186162
187163 # Create metadata
188164 metadata = OAuthMetadata (
@@ -205,14 +181,14 @@ def append_path(path: str, endpoint_path: str) -> str:
205181
206182 # Add registration endpoint if supported
207183 if client_registration_options .enabled :
208- metadata .registration_endpoint = modify_url_path (
209- issuer_url , lambda path : append_path ( path , REGISTRATION_PATH )
184+ metadata .registration_endpoint = AnyHttpUrl (
185+ str ( issuer_url ). rstrip ( "/" ) + REGISTRATION_PATH
210186 )
211187
212188 # Add revocation endpoint if supported
213189 if revocation_options .enabled :
214- metadata .revocation_endpoint = modify_url_path (
215- issuer_url , lambda path : append_path ( path , REVOCATION_PATH )
190+ metadata .revocation_endpoint = AnyHttpUrl (
191+ str ( issuer_url ). rstrip ( "/" ) + REVOCATION_PATH
216192 )
217193 metadata .revocation_endpoint_auth_methods_supported = ["client_secret_post" ]
218194
0 commit comments