pub struct SessionStorage { /* private fields */ }
Expand description
Allow to save, read and remove session from storage.
Implementations§
Source§impl SessionStorage
impl SessionStorage
Sourcepub fn new(
storage: Arc<dyn TokenStorage>,
jwt_encoding_key: Arc<EncodingKey>,
algorithm: Algorithm,
) -> Self
pub fn new( storage: Arc<dyn TokenStorage>, jwt_encoding_key: Arc<EncodingKey>, algorithm: Algorithm, ) -> Self
Abstraction layer over database holding tokens information
It allows read/write/update/delete operation on tokens
Sourcepub async fn find_jwt<ClaimsType: Claims>(
&self,
jti: Uuid,
) -> Result<ClaimsType, Error>
pub async fn find_jwt<ClaimsType: Claims>( &self, jti: Uuid, ) -> Result<ClaimsType, Error>
Load claims from storage or returns Error if record does not exists or there was other error while trying to fetch data from storage.
Sourcepub async fn refresh<ClaimsType: Claims>(
&self,
refresh_jti: Uuid,
) -> Result<Pair<ClaimsType>, Error>
pub async fn refresh<ClaimsType: Claims>( &self, refresh_jti: Uuid, ) -> Result<Pair<ClaimsType>, Error>
Changes RefreshToken::issues_at allowing Claims and RefreshToken to be accessible longer
Examples:
use actix_jwt_session::SessionStorage;
use actix_web::{Error, HttpResponse};
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct AppClaims { id: uuid::Uuid, sub: String }
impl actix_jwt_session::Claims for AppClaims {
fn jti(&self) -> uuid::Uuid { self.id }
fn subject(&self) -> &str { &self.sub }
}
async fn extend_tokens_lifetime(
session_storage: SessionStorage,
jti: uuid::Uuid
) -> Result<HttpResponse, Error> {
session_storage.refresh::<AppClaims>(jti).await?;
Ok(HttpResponse::Ok().finish())
}
Sourcepub async fn store<ClaimsType: Claims>(
&self,
claims: ClaimsType,
access_ttl: JwtTtl,
refresh_ttl: RefreshTtl,
) -> Result<Pair<ClaimsType>, Error>
pub async fn store<ClaimsType: Claims>( &self, claims: ClaimsType, access_ttl: JwtTtl, refresh_ttl: RefreshTtl, ) -> Result<Pair<ClaimsType>, Error>
Save claims in storage in a way claims can be loaded from database using
jti
as uuid::Uuid (JWT ID)
Trait Implementations§
Source§impl Clone for SessionStorage
impl Clone for SessionStorage
Source§fn clone(&self) -> SessionStorage
fn clone(&self) -> SessionStorage
Returns a duplicate 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 moreAuto Trait Implementations§
impl Freeze for SessionStorage
impl !RefUnwindSafe for SessionStorage
impl Send for SessionStorage
impl Sync for SessionStorage
impl Unpin for SessionStorage
impl !UnwindSafe for SessionStorage
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