1+ import posixpath
2+
13from collections .abc import Awaitable , Callable
24from typing import Any
35
@@ -166,11 +168,14 @@ def build_metadata(
166168 client_registration_options : ClientRegistrationOptions ,
167169 revocation_options : RevocationOptions ,
168170) -> OAuthMetadata :
171+ def append_path (base : str , suffix : str ) -> str :
172+ return posixpath .join (base .rstrip ("/" ), suffix .lstrip ("/" ))
173+
169174 authorization_url = modify_url_path (
170- issuer_url , lambda path : path . rstrip ( "/" ) + AUTHORIZATION_PATH . lstrip ( "/" )
175+ issuer_url , lambda path : append_path ( path , AUTHORIZATION_PATH )
171176 )
172177 token_url = modify_url_path (
173- issuer_url , lambda path : path . rstrip ( "/" ) + TOKEN_PATH . lstrip ( "/" )
178+ issuer_url , lambda path : append_path ( path , TOKEN_PATH )
174179 )
175180 # Create metadata
176181 metadata = OAuthMetadata (
@@ -194,13 +199,13 @@ def build_metadata(
194199 # Add registration endpoint if supported
195200 if client_registration_options .enabled :
196201 metadata .registration_endpoint = modify_url_path (
197- issuer_url , lambda path : path . rstrip ( "/" ) + REGISTRATION_PATH . lstrip ( "/" )
202+ issuer_url , lambda path : append_path ( path , REGISTRATION_PATH )
198203 )
199204
200205 # Add revocation endpoint if supported
201206 if revocation_options .enabled :
202207 metadata .revocation_endpoint = modify_url_path (
203- issuer_url , lambda path : path . rstrip ( "/" ) + REVOCATION_PATH . lstrip ( "/" )
208+ issuer_url , lambda path : append_path ( path , REVOCATION_PATH )
204209 )
205210 metadata .revocation_endpoint_auth_methods_supported = ["client_secret_post" ]
206211
0 commit comments