Skip to content

Commit cfca0cf

Browse files
cursoragentlovasoa
andcommitted
Checkpoint before follow-up message
Co-authored-by: contact <[email protected]>
1 parent f775297 commit cfca0cf

File tree

1 file changed

+18
-32
lines changed

1 file changed

+18
-32
lines changed

src/webserver/oidc.rs

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ use openidconnect::core::{
2424
};
2525
use openidconnect::{
2626
core::CoreAuthenticationFlow, url::Url, AsyncHttpClient, Audience, CsrfToken, EndpointMaybeSet,
27-
EndpointNotSet, EndpointSet, IssuerUrl, Nonce, OAuth2TokenResponse, RedirectUrl, Scope,
28-
TokenResponse,
27+
EndpointNotSet, EndpointSet, EndSessionUrl, IssuerUrl, LogoutRequest, Nonce, OAuth2TokenResponse,
28+
PostLogoutRedirectUrl, ProviderMetadataWithLogout, RedirectUrl, Scope, TokenResponse,
2929
};
3030
use openidconnect::{
3131
EmptyExtraTokenFields, IdTokenFields, IdTokenVerifier, StandardErrorResponse,
@@ -154,7 +154,7 @@ fn get_app_host(config: &AppConfig) -> String {
154154

155155
pub struct ClientWithTime {
156156
client: OidcClient,
157-
end_session_endpoint: Option<Url>,
157+
end_session_endpoint: Option<EndSessionUrl>,
158158
last_update: Instant,
159159
}
160160

@@ -216,7 +216,7 @@ impl OidcState {
216216
)
217217
}
218218

219-
pub async fn get_end_session_endpoint(&self) -> Option<Url> {
219+
pub async fn get_end_session_endpoint(&self) -> Option<EndSessionUrl> {
220220
self.client.read().await.end_session_endpoint.clone()
221221
}
222222

@@ -253,18 +253,21 @@ pub async fn initialize_oidc_state(
253253
async fn build_oidc_client_from_appdata(
254254
cfg: &OidcConfig,
255255
req: &ServiceRequest,
256-
) -> anyhow::Result<(OidcClient, Option<Url>)> {
256+
) -> anyhow::Result<(OidcClient, Option<EndSessionUrl>)> {
257257
let http_client = get_http_client_from_appdata(req)?;
258258
build_oidc_client(cfg, http_client).await
259259
}
260260

261261
async fn build_oidc_client(
262262
oidc_cfg: &OidcConfig,
263263
http_client: &Client,
264-
) -> anyhow::Result<(OidcClient, Option<Url>)> {
264+
) -> anyhow::Result<(OidcClient, Option<EndSessionUrl>)> {
265265
let issuer_url = oidc_cfg.issuer_url.clone();
266-
let (provider_metadata, end_session_endpoint) =
267-
discover_provider_metadata(http_client, issuer_url.clone()).await?;
266+
let provider_metadata = discover_provider_metadata(http_client, issuer_url.clone()).await?;
267+
let end_session_endpoint = provider_metadata
268+
.additional_metadata()
269+
.end_session_endpoint
270+
.clone();
268271
let client = make_oidc_client(oidc_cfg, provider_metadata)?;
269272
Ok((client, end_session_endpoint))
270273
}
@@ -284,37 +287,20 @@ impl OidcMiddleware {
284287
async fn discover_provider_metadata(
285288
http_client: &awc::Client,
286289
issuer_url: IssuerUrl,
287-
) -> anyhow::Result<(openidconnect::core::CoreProviderMetadata, Option<Url>)> {
290+
) -> anyhow::Result<ProviderMetadataWithLogout> {
288291
log::debug!("Discovering provider metadata for {issuer_url}");
289-
290-
let discovery_url = issuer_url
291-
.join(".well-known/openid-configuration")
292-
.with_context(|| {
293-
format!("Failed to construct discovery URL from issuer URL: {issuer_url}")
294-
})?;
295-
296-
let response = http_client
297-
.get(discovery_url.as_str())
298-
.send()
299-
.await
300-
.map_err(|e| anyhow!("Failed to fetch OIDC discovery document: {e}"))?
301-
.body()
302-
.await
303-
.map_err(|e| anyhow!("Failed to read OIDC discovery document body: {e}"))?;
304-
305-
let extra_metadata: DiscoveryMetadata = serde_json::from_slice(&response)
306-
.with_context(|| "Failed to parse end_session_endpoint from discovery document")?;
307-
308-
let provider_metadata = openidconnect::core::CoreProviderMetadata::discover_async(
292+
let provider_metadata = ProviderMetadataWithLogout::discover_async(
309293
issuer_url,
310294
&AwcHttpClient::from_client(http_client),
311295
)
312296
.await
313297
.with_context(|| "Failed to discover OIDC provider metadata".to_string())?;
314298
log::debug!("Provider metadata discovered: {provider_metadata:?}");
315-
log::debug!("end_session_endpoint: {:?}", extra_metadata.end_session_endpoint);
316-
317-
Ok((provider_metadata, extra_metadata.end_session_endpoint))
299+
log::debug!(
300+
"end_session_endpoint: {:?}",
301+
provider_metadata.additional_metadata().end_session_endpoint
302+
);
303+
Ok(provider_metadata)
318304
}
319305

320306
impl<S> Transform<S, ServiceRequest> for OidcMiddleware

0 commit comments

Comments
 (0)