Struct kvarn_auth::Config
source · [−]pub struct Config<T: Serialize + DeserializeOwned + Send + Sync, F: Fn(&str, &str, SocketAddr, &FatRequest) -> Fut + Send + Sync, Fut: Future<Output = Validation<T>> + Send + Sync> { /* private fields */ }
Expand description
The configured authentication. This can be attached to a Kvarn host using the Self::mount
method. You can call Self::login_status
to get a function to use in your extensions to
check for authentication status.
Implementations
sourceimpl<T: Serialize + DeserializeOwned + Send + Sync + 'static, F: Fn(&str, &str, SocketAddr, &FatRequest) -> Fut + Send + Sync + 'static, Fut: Future<Output = Validation<T>> + Send + Sync + 'static> Config<T, F, Fut>
impl<T: Serialize + DeserializeOwned + Send + Sync + 'static, F: Fn(&str, &str, SocketAddr, &FatRequest) -> Fut + Send + Sync + 'static, Fut: Future<Output = Validation<T>> + Send + Sync + 'static> Config<T, F, Fut>
sourcepub fn login_status(&self) -> LoginStatusClosure<T>
pub fn login_status(&self) -> LoginStatusClosure<T>
Returns a closure that can be sent to a Kvarn extension to extract the data from the user’s JWT and validating the authenticity of the client.
This makes it easier to cross the boundary of the Kvarn extension (using the move ||
semantics). See LoginStatusClosure
.
If the closure returns Validation::Unauthorized
, redirect the user to your login page
(Builder::with_auth_page_name
).
sourcepub fn mount(self: &Arc<Self>, extensions: &mut Extensions)
pub fn mount(self: &Arc<Self>, extensions: &mut Extensions)
Create an API route at Builder::with_auth_page_name
and make the JWT token automatically
refresh.
To log in, use JavaScript’s fetch
with method POST or PUT to the auth_page_name
,
with the username length on the first lines, then on the second line,
the username concatenated with the password without any space.
The rest of the body (after username length) is considered to be the password (it can
contains newlines).
To log out, fetch
DELETE to auth_page_name
.
Panics
Panics if this config was created using Builder::build_validate
.
Auto Trait Implementations
impl<T, F, Fut> RefUnwindSafe for Config<T, F, Fut> where
F: RefUnwindSafe,
impl<T, F, Fut> Send for Config<T, F, Fut>
impl<T, F, Fut> Sync for Config<T, F, Fut>
impl<T, F, Fut> Unpin for Config<T, F, Fut>
impl<T, F, Fut> UnwindSafe for Config<T, F, Fut> where
F: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more