Replies: 1 comment
-
Solved with some help from the rust discord: use std::{pin::Pin, future::Future};
use axum::{Router, body::{BoxBody, Body}, response::IntoResponse, http::{Request, Response}};
use tower_http::auth::{AsyncAuthorizeRequest, AsyncRequireAuthorizationLayer};
# From futures-util
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'static>>;
pub trait AppAsyncAuthorizeRequest: AsyncAuthorizeRequest<Body, RequestBody = Body, ResponseBody = BoxBody, Future = BoxFuture<'static, Result<Request<Body>, Response<BoxBody>>>> + Send + Clone + 'static {}
pub fn make_app<Auth: AppAsyncAuthorizeRequest>(validator: Auth) -> Router
{
Router::new()
.route("/a", axum::routing::get(|| async { "Hello".into_response() }))
.route_layer(AsyncRequireAuthorizationLayer::new(validator))
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a make_app function which I want to pass in validators to, so I can use a different validator for testing. What type should I use to pass an
AsyncAuthorizeRequest
? Here's one attempt:Am I missing something obvious, or is the type for validator just extremely complicated when passing it around?
Beta Was this translation helpful? Give feedback.
All reactions