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