Skip to content

Commit 18769eb

Browse files
committed
Skip OIDC auth for non-protected paths later in middleware
We still want to be able to access authenticated user's info in non-authenticated parts of the app. We crucially need to check request.path() == SQLPAGE_REDIRECT_URI before the protected_paths check
1 parent b3da7a6 commit 18769eb

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/webserver/oidc.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ pub struct OidcService<S> {
181181
oidc_state: Arc<OidcState>,
182182
}
183183

184-
impl<S> OidcService<S> {
184+
impl<S> OidcService<S>
185+
where
186+
S: Service<ServiceRequest, Response = ServiceResponse<BoxBody>, Error = Error>,
187+
S::Future: 'static,
188+
{
185189
pub fn new(service: S, oidc_state: Arc<OidcState>) -> Self {
186190
Self {
187191
service,
@@ -199,6 +203,20 @@ impl<S> OidcService<S> {
199203
return self.handle_oidc_callback(request);
200204
}
201205

206+
if !self
207+
.oidc_state
208+
.config
209+
.protected_paths
210+
.iter()
211+
.any(|path| request.path().starts_with(path))
212+
{
213+
log::debug!(
214+
"The request path {} is not in a protected path, skipping OIDC authentication",
215+
request.path()
216+
);
217+
return Box::pin(self.service.call(request));
218+
}
219+
202220
log::debug!("Redirecting to OIDC provider");
203221

204222
let response = build_auth_provider_redirect_response(
@@ -245,18 +263,6 @@ where
245263
fn call(&self, request: ServiceRequest) -> Self::Future {
246264
log::trace!("Started OIDC middleware request handling");
247265

248-
let protected_paths = &self.oidc_state.config.protected_paths;
249-
if !protected_paths
250-
.iter()
251-
.any(|path| request.path().starts_with(path))
252-
{
253-
log::debug!(
254-
"The request path {} is not in a protected path, skipping OIDC authentication",
255-
request.path()
256-
);
257-
return Box::pin(self.service.call(request));
258-
}
259-
260266
let oidc_client = Arc::clone(&self.oidc_state.client);
261267
match get_authenticated_user_info(&oidc_client, &request) {
262268
Ok(Some(claims)) => {

0 commit comments

Comments
 (0)