better claims for jwt over public routes
This commit is contained in:
@@ -47,20 +47,19 @@ impl JwtMiddleware {
|
||||
|
||||
impl Middleware for JwtMiddleware {
|
||||
fn run(&self, mut req: Request<Incoming>) -> MiddlewareFuture<'_> {
|
||||
let path = req.uri().path().to_string();
|
||||
let public_routes = self.public_routes.clone();
|
||||
let is_public_path = self.public_routes.contains(&req.uri().path().to_string());
|
||||
|
||||
Box::pin(async move {
|
||||
if public_routes.contains(&path) {
|
||||
return MiddlewareResult::Continue(req);
|
||||
}
|
||||
|
||||
match self.validate_request(&req) {
|
||||
Ok(claims) => {
|
||||
req.extensions_mut().insert(claims);
|
||||
MiddlewareResult::Continue(req)
|
||||
}
|
||||
Err(e) => {
|
||||
if is_public_path {
|
||||
return MiddlewareResult::Continue(req);
|
||||
}
|
||||
|
||||
error!(target: "auth", "JWT validation failed: {}", e);
|
||||
let res = Responder::unauthorized().expect("Responder failed");
|
||||
MiddlewareResult::Respond(res)
|
||||
|
||||
Reference in New Issue
Block a user