diff --git a/jwt-authorizer/src/layer.rs b/jwt-authorizer/src/layer.rs index 947a9a7..874b955 100644 --- a/jwt-authorizer/src/layer.rs +++ b/jwt-authorizer/src/layer.rs @@ -1,5 +1,4 @@ -use axum::body::Body; -use axum::http::Request; +use axum::extract::Request; use futures_core::ready; use futures_util::future::{self, BoxFuture}; use jsonwebtoken::TokenData; @@ -17,28 +16,25 @@ use crate::authorizer::Authorizer; use crate::AuthError; /// Trait for authorizing requests. -pub trait Authorize { - type RequestBody; - type Future: Future, AuthError>>; +pub trait Authorize { + type Future: Future>; /// Authorize the request. /// /// If the future resolves to `Ok(request)` then the request is allowed through, otherwise not. - fn authorize(&self, request: Request) -> Self::Future; + fn authorize(&self, request: Request) -> Self::Future; } -impl Authorize for AuthorizationService +impl Authorize for AuthorizationService where - B: Send + 'static, - C: Clone + DeserializeOwned + Send + 'static, + C: Clone + DeserializeOwned + Send + Sync + 'static, { - type RequestBody = B; - type Future = BoxFuture<'static, Result, AuthError>>; + type Future = BoxFuture<'static, Result>; /// The authorizers are sequentially applied (check_auth) until one of them validates the token. /// If no authorizer validates the token the request is rejected. /// - fn authorize(&self, mut request: Request) -> Self::Future { + fn authorize(&self, mut request: Request) -> Self::Future { let tkns_auths: Vec<(String, Arc>)> = self .auths .iter() @@ -160,9 +156,9 @@ where } } -impl Service> for AuthorizationService +impl Service for AuthorizationService where - S: Service> + Clone, + S: Service + Clone, S::Response: From, C: Clone + DeserializeOwned + Send + Sync + 'static, { @@ -174,7 +170,7 @@ where self.inner.poll_ready(cx) } - fn call(&mut self, req: Request) -> Self::Future { + fn call(&mut self, req: Request) -> Self::Future { let inner = self.inner.clone(); // take the service that was ready let inner = std::mem::replace(&mut self.inner, inner); @@ -192,11 +188,11 @@ where /// Response future for [`AuthorizationService`]. pub struct ResponseFuture where - S: Service>, + S: Service, C: Clone + DeserializeOwned + Send + Sync + 'static, { #[pin] - state: State< as Authorize>::Future, S::Future>, + state: State< as Authorize>::Future, S::Future>, service: S, } @@ -214,7 +210,7 @@ enum State { impl Future for ResponseFuture where - S: Service>, + S: Service, S::Response: From, C: Clone + DeserializeOwned + Send + Sync, { diff --git a/jwt-authorizer/tests/integration_tests.rs b/jwt-authorizer/tests/integration_tests.rs index f31a253..87fbb55 100644 --- a/jwt-authorizer/tests/integration_tests.rs +++ b/jwt-authorizer/tests/integration_tests.rs @@ -8,8 +8,7 @@ use std::{ time::Duration, }; -use axum::body::Body; -use axum::{response::Response, routing::get, Json, Router}; +use axum::{body::Body, response::Response, routing::get, Json, Router}; use http::{header::AUTHORIZATION, Request, StatusCode}; use jwt_authorizer::{IntoLayer, JwtAuthorizer, JwtClaims, Refresh, RefreshStrategy, Validation}; use lazy_static::lazy_static; @@ -127,7 +126,8 @@ fn init_test() { } async fn make_proteced_request(app: &mut Router, bearer: &str) -> Response { - >>::ready(app) + app.as_service() + .ready() .await .unwrap() .call( @@ -142,7 +142,8 @@ async fn make_proteced_request(app: &mut Router, bearer: &str) -> Response { } async fn make_public_request(app: &mut Router) -> Response { - >>::ready(app) + app.as_service() + .ready() .await .unwrap() .call(Request::builder().uri("/public").body(Body::empty()).unwrap())