diff --git a/src/server.rs b/src/server.rs index 5d1e94b..d9fa218 100644 --- a/src/server.rs +++ b/src/server.rs @@ -239,18 +239,23 @@ fn verify_auth( auth_header: Option, config: Arc>, ) -> Result<(), Rejection> { - if let Some(auth_header) = auth_header { - if let Ok(_bearer) = jsonwebtoken::decode::( - auth_header.trim_start_matches("Bearer "), - config.read().unwrap().authentication.secret_key.as_ref(), - &Validation::default(), - ) { - Ok(()) + let config = config.read().unwrap(); + if config.authentication.enabled { + if let Some(auth_header) = auth_header { + if let Ok(_bearer) = jsonwebtoken::decode::( + auth_header.trim_start_matches("Bearer "), + config.authentication.secret_key.as_ref(), + &Validation::default(), + ) { + Ok(()) + } else { + Err(warp::reject::custom(Error::InvalidJwtToken)) + } } else { - Err(warp::reject::custom(Error::InvalidJwtToken)) + Err(warp::reject::custom(Error::MissingAuthHeader)) } } else { - Err(warp::reject::custom(Error::MissingAuthHeader)) + Ok(()) } }