@@ -20,7 +20,8 @@ pub type Result<T, E = Error> = std::result::Result<T, E>;
2020pub const CLIENT_ID_SECRET_KEY : & str = "clientId" ;
2121pub const CLIENT_SECRET_SECRET_KEY : & str = "clientSecret" ;
2222
23- const DEFAULT_WELLKNOWN_OIDC_CONFIG_PATH : & str = ".well-known/openid-configuration" ;
23+ /// Do *not* use this for [`Url::join`], as the leading slash will erase the existing path!
24+ const DEFAULT_WELLKNOWN_OIDC_CONFIG_PATH : & str = "/.well-known/openid-configuration" ;
2425
2526#[ derive( Debug , PartialEq , Snafu ) ]
2627pub enum Error {
@@ -31,13 +32,6 @@ pub enum Error {
3132 "failed to set OIDC endpoint scheme '{scheme}' for endpoint url \" {endpoint}\" "
3233 ) ) ]
3334 SetOidcEndpointScheme { endpoint : Url , scheme : String } ,
34-
35- #[ snafu( display( "failed to join the path {path:?} to URL \" {url}\" " ) ) ]
36- JoinPath {
37- source : ParseError ,
38- url : Url ,
39- path : String ,
40- } ,
4135}
4236
4337/// This struct contains configuration values to configure an OpenID Connect
@@ -155,21 +149,23 @@ impl AuthenticationProvider {
155149
156150 /// Returns the well-known [`Url`] without a trailing slash.
157151 ///
158- /// It is basically the [`Self::endpoint_url`] joined with
159- /// "./. well-known/openid-configuration", while watching out for URL joining madness .
152+ /// The returned url is a combination of [`Self::endpoint_url`] joined with
153+ /// the well-known OIDC configuration path `DEFAULT_WELLKNOWN_OIDC_CONFIG_PATH` .
160154 pub fn well_known_config_url ( & self ) -> Result < Url > {
161155 let mut url = self . base_url ( ) ?;
162156
163- // Url::join cuts of the part after the last slash :/
164- // So we need to make sure we have a trailing slash, so that nothing get's cut of.
157+ // Taken from https://docs.rs/url/latest/url/struct.Url.html#method.join:
158+ // A trailing slash is significant. Without it, the last path component is considered to be
159+ // a “file” name to be removed to get at the “directory” that is used as the base.
160+ //
161+ // Because of that behavior, we first need to make sure that the root path doesn't contain
162+ // any trailing slashes to finally append the well-known config path to the url. The path
163+ // already contains a prefixed slash.
165164 let mut root_path_with_trailing_slash = self . root_path . trim_end_matches ( '/' ) . to_string ( ) ;
166- root_path_with_trailing_slash. push ( '/' ) ;
165+ root_path_with_trailing_slash. push_str ( DEFAULT_WELLKNOWN_OIDC_CONFIG_PATH ) ;
167166 url. set_path ( & root_path_with_trailing_slash) ;
168- url. join ( DEFAULT_WELLKNOWN_OIDC_CONFIG_PATH )
169- . with_context ( |_| JoinPathSnafu {
170- url : url. clone ( ) ,
171- path : DEFAULT_WELLKNOWN_OIDC_CONFIG_PATH . to_owned ( ) ,
172- } )
167+
168+ Ok ( url)
173169 }
174170
175171 /// Returns the port to be used, which is either user configured or defaulted based upon TLS usage
0 commit comments