Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Route Guard mechanism #123

Closed
Murtuzakabul opened this issue Aug 18, 2022 · 8 comments
Closed

Route Guard mechanism #123

Murtuzakabul opened this issue Aug 18, 2022 · 8 comments

Comments

@Murtuzakabul
Copy link
Contributor

Middleware can be deployed for authentication. However having route guard type of mechanism can help greatly in organizing authorization code.

Implement additional guard on routes

Similar functionality is already available in Actix which helps a lot in properly organizing the authorization logic. At the point of route guard processing, the user might already have authenticated and the the guard only decides if the user can access the route based on the data in the request.

@chrislearn
Copy link
Member

I don't quite understand the feature you said, can you give example actix code about it?

@Murtuzakabul
Copy link
Contributor Author

https://docs.rs/actix-web/3.3.3/actix_web/guard/index.html
A guard is simply a function which returns a boolean which determines if the route could be navigated to or not. This function gets invoked before the route gets executed and if the function returns false, the route does not get executed and may return 404 or 401 as configured.

@chrislearn
Copy link
Member

It looks like Router's filter. In salvo, Router::get, Router::post... are just filter.
https://docs.rs/salvo_core/latest/salvo_core/routing/struct.Router.html#method.filter_fn

@Murtuzakabul
Copy link
Contributor Author

Seems like the correct solution.

@sysmat
Copy link

sysmat commented Oct 27, 2022

  • filter_fn can't be async is there any other way to , let say in filter_fn must do some async validation operation
  • should in async scenario to be hoop with async_trait

@sysmat
Copy link

sysmat commented Oct 27, 2022

is it possible to have routes guard/grant by roles some thing like https://crates.io/crates/actix-web-grants

@chrislearn
Copy link
Member

Filter is not supports async in current version.
If you want to protected your router, you can use middleware.

Router::with_path("aaa").push(Router::with_hoop(check).path("bb"))

@DDtKey
Copy link

DDtKey commented May 29, 2024

For anyone interested: https://github.com/DDtKey/protect-endpoints now supports salvo 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants