-
Hi, I implemented delegation of JWT authentication in middleware. During implementation I run into problem of trying to use async Hyper HTTPS client. I was unable to I suspect my current implementation blocks on Async task implementation and that's bad. I am new to RUST, so I would like to know a better way compared to what I did. If I recall correctly, my initial implementation used futures::executor::block_on but it simply blocked application execution forever. Additional research in this direction indicated that's not a good idea. I was considering that tower-http/tower-http/src/validate_request.rs Line 227 in e8eb549 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I think I found answer in existing code in https://docs.rs/tower-http/latest/tower_http/auth/async_require_authorization/index.html |
Beta Was this translation helpful? Give feedback.
-
well, the complexity of framework type system is killing me. The best I was able to get is utilization of The best I was able to do is to attach it to service route: |
Beta Was this translation helpful? Give feedback.
If you are using axum, I would recommend using middleware::from_fn instead of
AsyncRequireAuthorizationLayer
. The axum function is much more generic, but it really doesn't require much boilerplate to achieve the same. (check auth, on success call the inner service, on failure return an error response)