Trait tower_http::auth::AuthorizeRequest [−][src]
pub trait AuthorizeRequest { type Output; type ResponseBody: Body; fn authorize<B>(&mut self, request: &Request<B>) -> Option<Self::Output>; fn unauthorized_response<B>(
&mut self,
request: &Request<B>
) -> Response<Self::ResponseBody>; fn on_authorized<B>(
&mut self,
_request: &mut Request<B>,
_output: Self::Output
) { ... } }
This is supported on crate feature
auth
only.Expand description
Trait for authorizing requests.
Associated Types
type Output
[src]
type Output
[src]The output type of doing the authorization.
Use ()
if authorization doesn’t produce any meaningful output.
type ResponseBody: Body
[src]
type ResponseBody: Body
[src]The body type used for responses to unauthorized requests.
Required methods
fn authorize<B>(&mut self, request: &Request<B>) -> Option<Self::Output>
[src]
fn authorize<B>(&mut self, request: &Request<B>) -> Option<Self::Output>
[src]Authorize the request.
If Some(_)
is returned then the request is allowed through, otherwise not.
fn unauthorized_response<B>(
&mut self,
request: &Request<B>
) -> Response<Self::ResponseBody>
[src]
fn unauthorized_response<B>(
&mut self,
request: &Request<B>
) -> Response<Self::ResponseBody>
[src]Create the response for an unauthorized request.
Provided methods
fn on_authorized<B>(&mut self, _request: &mut Request<B>, _output: Self::Output)
[src]
fn on_authorized<B>(&mut self, _request: &mut Request<B>, _output: Self::Output)
[src]Callback for when a request has been successfully authorized.
For example this allows you to save Self::Output
in a request extension to make it
available to services further down the stack. This could for example be the “claims” for a
valid JWT.
Defaults to doing nothing.
See the module docs for an example.
Implementors
impl<ResBody> AuthorizeRequest for Basic<ResBody> where
ResBody: Body + Default,
[src]
impl<ResBody> AuthorizeRequest for Basic<ResBody> where
ResBody: Body + Default,
[src]type Output = ()
type ResponseBody = ResBody
fn authorize<B>(&mut self, request: &Request<B>) -> Option<Self::Output>
[src]
fn unauthorized_response<B>(
&mut self,
_request: &Request<B>
) -> Response<Self::ResponseBody>
[src]
&mut self,
_request: &Request<B>
) -> Response<Self::ResponseBody>
impl<ResBody> AuthorizeRequest for Bearer<ResBody> where
ResBody: Body + Default,
[src]
impl<ResBody> AuthorizeRequest for Bearer<ResBody> where
ResBody: Body + Default,
[src]type Output = ()
type ResponseBody = ResBody
fn authorize<B>(&mut self, request: &Request<B>) -> Option<Self::Output>
[src]
fn unauthorized_response<B>(
&mut self,
_request: &Request<B>
) -> Response<Self::ResponseBody>
[src]
&mut self,
_request: &Request<B>
) -> Response<Self::ResponseBody>