Skip to content

Commit

Permalink
Include discovery URL in error message (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
Timshel authored Dec 27, 2023
1 parent d796cca commit 502ad93
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,11 @@ where
.join(CONFIG_URL_SUFFIX)
.map_err(DiscoveryError::UrlParse)?;

http_client(Self::discovery_request(discovery_url))
http_client(Self::discovery_request(discovery_url.clone()))
.map_err(DiscoveryError::Request)
.and_then(|http_response| Self::discovery_response(issuer_url, http_response))
.and_then(|http_response| {
Self::discovery_response(issuer_url, &discovery_url, http_response)
})
.and_then(|provider_metadata| {
JsonWebKeySet::fetch(provider_metadata.jwks_uri(), http_client).map(|jwks| Self {
jwks,
Expand All @@ -330,10 +332,12 @@ where
.join(CONFIG_URL_SUFFIX)
.map_err(DiscoveryError::UrlParse)?;

let provider_metadata = http_client(Self::discovery_request(discovery_url))
let provider_metadata = http_client(Self::discovery_request(discovery_url.clone()))
.await
.map_err(DiscoveryError::Request)
.and_then(|http_response| Self::discovery_response(&issuer_url, http_response))?;
.and_then(|http_response| {
Self::discovery_response(&issuer_url, &discovery_url, http_response)
})?;

JsonWebKeySet::fetch_async(provider_metadata.jwks_uri(), http_client)
.await
Expand All @@ -356,6 +360,7 @@ where

fn discovery_response<RE>(
issuer_url: &IssuerUrl,
discovery_url: &url::Url,
discovery_response: HttpResponse,
) -> Result<Self, DiscoveryError<RE>>
where
Expand All @@ -365,7 +370,10 @@ where
return Err(DiscoveryError::Response(
discovery_response.status_code,
discovery_response.body,
format!("HTTP status code {}", discovery_response.status_code),
format!(
"HTTP status code {} at {}",
discovery_response.status_code, discovery_url
),
));
}

Expand Down

0 comments on commit 502ad93

Please sign in to comment.