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§
source§impl<Data, Handler> AuthMiddleware<Data, Handler>
impl<Data, Handler> AuthMiddleware<Data, Handler>
pub fn from_source(source: AuthSource) -> Self
source§impl<Data, Handler> AuthMiddleware<Data, Handler>
impl<Data, Handler> AuthMiddleware<Data, Handler>
pub fn new( source: AuthSource, validation: AuthValidation, handler: Handler ) -> Self
Trait Implementations§
source§impl<Data, Handler> Clone for AuthMiddleware<Data, Handler>where
Handler: Clone,
impl<Data, Handler> Clone for AuthMiddleware<Data, Handler>where
Handler: Clone,
source§impl<Data, Handler> Middleware for AuthMiddleware<Data, Handler>
impl<Data, Handler> Middleware for AuthMiddleware<Data, Handler>
source§impl<Data, Handler> NewMiddleware for AuthMiddleware<Data, Handler>
impl<Data, Handler> NewMiddleware for AuthMiddleware<Data, Handler>
§type Instance = AuthMiddleware<Data, Handler>
type Instance = AuthMiddleware<Data, Handler>
The type of
Middleware
created by the NewMiddleware
.source§fn new_middleware(&self) -> Result<Self>
fn new_middleware(&self) -> Result<Self>
Create and return a new
Middleware
value.Auto Trait Implementations§
impl<Data, Handler> !Freeze for AuthMiddleware<Data, Handler>
impl<Data, Handler> RefUnwindSafe for AuthMiddleware<Data, Handler>where
Handler: RefUnwindSafe,
Data: RefUnwindSafe,
impl<Data, Handler> Send for AuthMiddleware<Data, Handler>
impl<Data, Handler> Sync for AuthMiddleware<Data, Handler>
impl<Data, Handler> Unpin for AuthMiddleware<Data, Handler>
impl<Data, Handler> UnwindSafe for AuthMiddleware<Data, Handler>where
Handler: UnwindSafe,
Data: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> IntoSql for T
impl<T> IntoSql for T
source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
Convert
self
to an expression for Diesel’s query builder. Read moresource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
Convert
&self
to an expression for Diesel’s query builder. Read more