Skip to content

Commit df080ec

Browse files
committed
Increase OIDC client refresh interval to 1 hour
1 parent 061f540 commit df080ec

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/webserver/oidc.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type LocalBoxFuture<T> = Pin<Box<dyn Future<Output = T> + 'static>>;
3434
const SQLPAGE_AUTH_COOKIE_NAME: &str = "sqlpage_auth";
3535
const SQLPAGE_REDIRECT_URI: &str = "/sqlpage/oidc_callback";
3636
const SQLPAGE_STATE_COOKIE_NAME: &str = "sqlpage_oidc_state";
37+
const OIDC_CLIENT_REFRESH_INTERVAL: Duration = Duration::from_secs(60 * 60);
3738

3839
#[derive(Clone, Debug, Serialize, Deserialize)]
3940
#[serde(transparent)]
@@ -146,8 +147,6 @@ pub struct OidcState {
146147
client: Mutex<ClientWithTime>,
147148
}
148149

149-
const OIDC_CLIENT_REFRESH_INTERVAL: Duration = Duration::from_secs(600);
150-
151150
impl OidcState {
152151
pub async fn new(oidc_cfg: OidcConfig, app_config: AppConfig) -> anyhow::Result<Self> {
153152
let http_client = make_http_client(&app_config)?;
@@ -189,10 +188,12 @@ impl OidcState {
189188
return client_lock;
190189
}
191190
}
191+
log::debug!("OIDC client is older than {OIDC_CLIENT_REFRESH_INTERVAL:?}, refreshing...");
192192
self.refresh().await;
193193
self.client.lock().expect("oidc client")
194194
}
195195

196+
/// Validate and decode the claims of an OIDC token, without refreshing the client.
196197
fn get_token_claims(
197198
&self,
198199
id_token: &OidcToken,
@@ -228,8 +229,8 @@ async fn build_oidc_client(
228229
oidc_cfg: &OidcConfig,
229230
http_client: &Client,
230231
) -> anyhow::Result<OidcClient> {
231-
let provider_metadata =
232-
discover_provider_metadata(http_client, oidc_cfg.issuer_url.clone()).await?;
232+
let issuer_url = oidc_cfg.issuer_url.clone();
233+
let provider_metadata = discover_provider_metadata(http_client, issuer_url.clone()).await?;
233234
let client = make_oidc_client(oidc_cfg, provider_metadata)?;
234235
Ok(client)
235236
}

0 commit comments

Comments
 (0)