pub struct SessionMiddlewareFactory<ClaimsType: Claims> { /* private fields */ }
Expand description
Factory creates middlware for every single request.
All fields here are immutable and have atomic access and only pointer is copied so are very cheap
Example:
use std::sync::Arc;
use actix_jwt_session::*;
// create redis connection
let redis = {
use deadpool_redis::{Config, Runtime};
let cfg = Config::from_url("redis://localhost:6379");
let pool = cfg.create_pool(Some(Runtime::Tokio1)).unwrap();
pool
};
// load or create new keys in `./config`
let keys = JwtSigningKeys::load_or_create();
// create new [SessionStorage] and [SessionMiddlewareFactory]
let (storage, factory) = SessionMiddlewareFactory::<AppClaims>::build(
Arc::new(keys.encoding_key),
Arc::new(keys.decoding_key),
Algorithm::EdDSA
)
// pass redis connection
.with_redis_pool(redis.clone())
// Check if header "Authorization" exists and contains Bearer with encoded JWT
.with_jwt_header("Authorization")
// Check if cookie "jwt" exists and contains encoded JWT
.with_jwt_cookie("acx-a")
.with_refresh_header("ACX-Refresh")
// Check if cookie "jwt" exists and contains encoded JWT
.with_refresh_cookie("acx-r")
.finish();
Implementations§
source§impl<ClaimsType: Claims> SessionMiddlewareFactory<ClaimsType>
impl<ClaimsType: Claims> SessionMiddlewareFactory<ClaimsType>
pub fn build_ed_dsa() -> SessionMiddlewareBuilder<ClaimsType>
pub fn build( jwt_encoding_key: Arc<EncodingKey>, jwt_decoding_key: Arc<DecodingKey>, algorithm: Algorithm ) -> SessionMiddlewareBuilder<ClaimsType>
Trait Implementations§
source§impl<ClaimsType: Clone + Claims> Clone for SessionMiddlewareFactory<ClaimsType>
impl<ClaimsType: Clone + Claims> Clone for SessionMiddlewareFactory<ClaimsType>
source§fn clone(&self) -> SessionMiddlewareFactory<ClaimsType>
fn clone(&self) -> SessionMiddlewareFactory<ClaimsType>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<S, B, ClaimsType> Transform<S, ServiceRequest> for SessionMiddlewareFactory<ClaimsType>where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
ClaimsType: Claims,
impl<S, B, ClaimsType> Transform<S, ServiceRequest> for SessionMiddlewareFactory<ClaimsType>where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
ClaimsType: Claims,
§type Response = ServiceResponse<B>
type Response = ServiceResponse<B>
Responses produced by the service.
§type Transform = SessionMiddleware<S, ClaimsType>
type Transform = SessionMiddleware<S, ClaimsType>
The
TransformService
value created by this factory§type Future = Ready<Result<<SessionMiddlewareFactory<ClaimsType> as Transform<S, ServiceRequest>>::Transform, <SessionMiddlewareFactory<ClaimsType> as Transform<S, ServiceRequest>>::InitError>>
type Future = Ready<Result<<SessionMiddlewareFactory<ClaimsType> as Transform<S, ServiceRequest>>::Transform, <SessionMiddlewareFactory<ClaimsType> as Transform<S, ServiceRequest>>::InitError>>
The future response value.
source§fn new_transform(&self, service: S) -> Self::Future
fn new_transform(&self, service: S) -> Self::Future
Creates and returns a new Transform component, asynchronously
Auto Trait Implementations§
impl<ClaimsType> !RefUnwindSafe for SessionMiddlewareFactory<ClaimsType>
impl<ClaimsType> Send for SessionMiddlewareFactory<ClaimsType>
impl<ClaimsType> Sync for SessionMiddlewareFactory<ClaimsType>
impl<ClaimsType> Unpin for SessionMiddlewareFactory<ClaimsType>
impl<ClaimsType> !UnwindSafe for SessionMiddlewareFactory<ClaimsType>
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