Skip to content

Commit

Permalink
Create new client if old client is older than 60 s
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenvh1 committed Jul 16, 2024
1 parent f5fbb30 commit c6b951d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/daemon/auth/providers/openid_connect/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ use std::{
HashMap,
},
ops::Deref,
sync::Arc,
sync::Arc,
time::Instant,
};

use tokio::sync::{RwLock, RwLockReadGuard};
Expand Down Expand Up @@ -151,6 +152,7 @@ pub struct ProviderConnectionProperties {
client: FlexibleClient,
email_scope_supported: bool,
userinfo_endpoint_supported: bool,
time_established: Instant,
logout_mode: LogoutMode,
}

Expand Down Expand Up @@ -179,7 +181,8 @@ impl OpenIDConnectAuthProvider {
async fn initialize_connection_if_needed(&self) -> KrillResult<()> {
let mut conn_guard = self.conn.write().await;

if conn_guard.is_none() {
if conn_guard.is_none() || conn_guard.as_ref().unwrap()
.time_established.elapsed().as_secs() >= 60 {
*conn_guard = Some(self.initialize_connection().await?);
}

Expand All @@ -194,10 +197,12 @@ impl OpenIDConnectAuthProvider {
let (email_scope_supported, userinfo_endpoint_supported, logout_mode) =
self.check_provider_capabilities(&meta)?;
let client = self.build_client(meta, &logout_mode)?;
let time_established = Instant::now();
let conn = ProviderConnectionProperties {
client,
email_scope_supported,
userinfo_endpoint_supported,
time_established,
logout_mode,
};
trace!("OpenID Connect: Provider connection initialized");
Expand Down

0 comments on commit c6b951d

Please sign in to comment.