Skip to content

Commit

Permalink
Allow the OpenID Connect discover_async method to be Send
Browse files Browse the repository at this point in the history
  • Loading branch information
poljar committed Apr 16, 2024
1 parent c4e28f4 commit c7e1dc3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ thiserror = "1.0"
http = "1.0"
itertools = "0.10"
log = "0.4"
oauth2 = { version = "=5.0.0-alpha.4", default-features = false }
oauth2 = { git = "https://github.com/poljar/oauth2-rs", rev = "f8e28ce5a7f3278ac85b8593ecdd86f2cf51fa2e", default-features = false }
rand = "0.8.5"
hmac = "0.12.1"
rsa = "0.9.2"
Expand Down
16 changes: 8 additions & 8 deletions src/discovery/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,22 +308,22 @@ where
pub fn discover_async<'c, C>(
issuer_url: IssuerUrl,
http_client: &'c C,
) -> impl Future<Output = Result<Self, DiscoveryError<<C as AsyncHttpClient<'c>>::Error>>> + 'c
) -> impl Future<Output = Result<Self, DiscoveryError<<C as AsyncHttpClient<'c>>::Error>>> + 'c + Send
where
Self: 'c,
C: AsyncHttpClient<'c>,
Self: 'c + Send,
C: AsyncHttpClient<'c> + Send + Sync,
{
Box::pin(async move {
let discovery_url = issuer_url
.join(CONFIG_URL_SUFFIX)
.map_err(DiscoveryError::UrlParse)?;

let request = Self::discovery_request(discovery_url.clone()).map_err(|err| {
DiscoveryError::Other(format!("failed to prepare request: {err}"))
})?;

let provider_metadata = http_client
.call(
Self::discovery_request(discovery_url.clone()).map_err(|err| {
DiscoveryError::Other(format!("failed to prepare request: {err}"))
})?,
)
.call(request)
.await
.map_err(DiscoveryError::Request)
.and_then(|http_response| {
Expand Down
14 changes: 9 additions & 5 deletions src/types/jwks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,20 @@ where
pub fn fetch_async<'c, C>(
url: &JsonWebKeySetUrl,
http_client: &'c C,
) -> impl Future<Output = Result<Self, DiscoveryError<<C as AsyncHttpClient<'c>>::Error>>> + 'c
) -> impl Future<Output = Result<Self, DiscoveryError<<C as AsyncHttpClient<'c>>::Error>>> + 'c + Send
where
Self: 'c,
C: AsyncHttpClient<'c>,
C: AsyncHttpClient<'c> + Sync + Send,
{
let fetch_request = Self::fetch_request(url)
.map_err(|err| DiscoveryError::Other(format!("failed to prepare request: {err}")));
let url = url.to_owned();

Box::pin(async move {
let fetch_request = Self::fetch_request(&url).map_err(|err| {
DiscoveryError::Other(format!("failed to prepare request: {err}"))
})?;

http_client
.call(fetch_request?)
.call(fetch_request)
.await
.map_err(DiscoveryError::Request)
.and_then(Self::fetch_response)
Expand Down

0 comments on commit c7e1dc3

Please sign in to comment.