Skip to content

Commit

Permalink
chore : further linting and code quality modification
Browse files Browse the repository at this point in the history
  • Loading branch information
HatemMn committed Oct 11, 2024
1 parent 0450c94 commit bb8317c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,15 @@ where
*/
if let Some(configurations) = self.jwt_configurations.clone() {
return Box::pin(async move { manage_jwt_request(service, configurations, req).await });
} else {
let fut = self.service.call(req);
Box::pin(async move {
let res = fut.await?;

println!("Hi from response");
Ok(res.map_into_left_body())
})
}
// todo!("TODO: NOT IMPLEMENTED TOKEN AUTH")
// Box::pin(async move { manage_api_token_request(service, req).await })
let fut = self.service.call(req);
Box::pin(async move {
let res = fut.await?;

println!("Hi from response");
Ok(res.map_into_left_body())
})
}
// todo!("TODO: NOT IMPLEMENTED TOKEN AUTH")
// Box::pin(async move { manage_api_token_request(service, req).await })
}
2 changes: 1 addition & 1 deletion src/middlewares/jwks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl JwksManager {
/// Lock `jwks` to replace it
fn set_jwks(&self, new_jwks: HashMap<String, JWKS>) -> LoginResult<()> {
let mut jwks = self.jwks.write().map_err(|e| {
LoginError::ServerError((format!("cannot lock JWKS for write. Error: {e:?}")))
LoginError::ServerError(format!("cannot lock JWKS for write. Error: {e:?}"))
})?;
*jwks = new_jwks;
Ok(())
Expand Down
8 changes: 4 additions & 4 deletions src/middlewares/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ impl JwtConfig {

tracing::trace!("JWK has been found:\n{jwk:?}");

let valid_jwt = alcoholic_jwt::validate(token, &jwk, validations).map_err(|err| {
LoginError::Unauthorized(("Cannot validate token: {err:?}".to_owned()))
let valid_jwt = alcoholic_jwt::validate(token, &jwk, validations).map_err(|_err| {
LoginError::Unauthorized("Cannot validate token: {err:?}".to_owned())
})?;

debug!("JWT is valid, the claims are {0:?}", valid_jwt.claims);

let payload = serde_json::from_value(valid_jwt.claims).map_err(|err| {
LoginError::Unauthorized(("JWT claims is malformed: {err:?}".to_owned()))
let payload = serde_json::from_value(valid_jwt.claims).map_err(|_err| {
LoginError::Unauthorized("JWT claims is malformed: {err:?}".to_owned())
})?;

debug!("JWT payload: {payload:?}");
Expand Down
1 change: 0 additions & 1 deletion src/middlewares/jwt_token_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use actix_web::{
http::header,
Error, FromRequest, HttpMessage, HttpResponse,
};
use serde::de;
use tracing::{debug, error, trace};

use super::{error::LoginError, types::LoginResult, JwtConfig, UserClaim};
Expand Down
4 changes: 2 additions & 2 deletions src/middlewares/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod authMiddleware;
pub(crate) use authMiddleware::LoginTransformerFactory;
mod auth_middleware;
pub(crate) use auth_middleware::LoginTransformerFactory;

mod jwt_token_auth;
pub(crate) use jwt_token_auth::{manage_jwt_request, JwtAuthClaim}; // NO // Y
Expand Down

0 comments on commit bb8317c

Please sign in to comment.