Struct gotham_restful::AuthMiddleware
source · [−]pub struct AuthMiddleware<Data, Handler> { /* private fields */ }
Expand description
This is the auth middleware. To use it, first make sure you have the auth
feature enabled. Then
simply add it to your pipeline and request it inside your handler:
#[derive(Resource)]
#[resource(read_all)]
struct AuthResource;
#[derive(Debug, Deserialize, Clone)]
struct AuthData {
sub: String,
exp: u64
}
#[read_all]
fn read_all(auth : &AuthStatus<AuthData>) -> Success<String> {
format!("{:?}", auth).into()
}
fn main() {
let auth: AuthMiddleware<AuthData, _> = AuthMiddleware::new(
AuthSource::AuthorizationHeader,
AuthValidation::default(),
StaticAuthHandler::from_array(b"zlBsA2QXnkmpe0QTh8uCvtAEa4j33YAc")
);
let (chain, pipelines) = single_pipeline(new_pipeline().add(auth).build());
gotham::start("127.0.0.1:8080", build_router(chain, pipelines, |route| {
route.resource::<AuthResource>("auth");
}));
}
Implementations
sourceimpl<Data, Handler> AuthMiddleware<Data, Handler> where
Data: DeserializeOwned + Send,
Handler: AuthHandler<Data> + Default,
impl<Data, Handler> AuthMiddleware<Data, Handler> where
Data: DeserializeOwned + Send,
Handler: AuthHandler<Data> + Default,
pub fn from_source(source: AuthSource) -> Self
sourceimpl<Data, Handler> AuthMiddleware<Data, Handler> where
Data: DeserializeOwned + Send,
Handler: AuthHandler<Data>,
impl<Data, Handler> AuthMiddleware<Data, Handler> where
Data: DeserializeOwned + Send,
Handler: AuthHandler<Data>,
pub fn new(
source: AuthSource,
validation: AuthValidation,
handler: Handler
) -> Self
Trait Implementations
sourceimpl<Data, Handler> Clone for AuthMiddleware<Data, Handler> where
Handler: Clone,
impl<Data, Handler> Clone for AuthMiddleware<Data, Handler> where
Handler: Clone,
sourceimpl<Data: Debug, Handler: Debug> Debug for AuthMiddleware<Data, Handler>
impl<Data: Debug, Handler: Debug> Debug for AuthMiddleware<Data, Handler>
sourceimpl<Data, Handler> Middleware for AuthMiddleware<Data, Handler> where
Data: DeserializeOwned + Send + 'static,
Handler: AuthHandler<Data>,
impl<Data, Handler> Middleware for AuthMiddleware<Data, Handler> where
Data: DeserializeOwned + Send + 'static,
Handler: AuthHandler<Data>,
sourceimpl<Data, Handler> NewMiddleware for AuthMiddleware<Data, Handler> where
Self: Clone + Middleware + Sync + RefUnwindSafe,
impl<Data, Handler> NewMiddleware for AuthMiddleware<Data, Handler> where
Self: Clone + Middleware + Sync + RefUnwindSafe,
type Instance = Self
type Instance = Self
The type of Middleware
created by the NewMiddleware
.
sourcefn new_middleware(&self) -> Result<Self>
fn new_middleware(&self) -> Result<Self>
Create and return a new Middleware
value.
Auto Trait Implementations
impl<Data, Handler> RefUnwindSafe for AuthMiddleware<Data, Handler> where
Data: RefUnwindSafe,
Handler: RefUnwindSafe,
impl<Data, Handler> Send for AuthMiddleware<Data, Handler> where
Data: Send,
Handler: Send,
impl<Data, Handler> Sync for AuthMiddleware<Data, Handler> where
Data: Sync,
Handler: Sync,
impl<Data, Handler> Unpin for AuthMiddleware<Data, Handler> where
Data: Unpin,
Handler: Unpin,
impl<Data, Handler> UnwindSafe for AuthMiddleware<Data, Handler> where
Data: UnwindSafe,
Handler: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> IntoSql for T
impl<T> IntoSql for T
sourcefn into_sql<T>(self) -> Self::Expression where
Self: AsExpression<T>,
fn into_sql<T>(self) -> Self::Expression where
Self: AsExpression<T>,
Convert self
to an expression for Diesel’s query builder. Read more
sourcefn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression where
&'a Self: AsExpression<T>,
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression where
&'a Self: AsExpression<T>,
Convert &self
to an expression for Diesel’s query builder. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more