Skip to content

Commit

Permalink
Skip authentication if it's disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
shuni64 committed Nov 13, 2019
1 parent e76f795 commit 4fa02af
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,18 +239,23 @@ fn verify_auth(
auth_header: Option<String>,
config: Arc<RwLock<Configuration>>,
) -> Result<(), Rejection> {
if let Some(auth_header) = auth_header {
if let Ok(_bearer) = jsonwebtoken::decode::<Claims>(
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::<Claims>(
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(())
}
}

Expand Down

0 comments on commit 4fa02af

Please sign in to comment.