pub struct Authenticated<T> {
pub claims: Arc<T>,
pub jwt_encoding_key: Arc<EncodingKey>,
pub algorithm: Algorithm,
}Expand description
Extractable user session which requires presence of JWT in request.
If there’s no JWT endpoint which requires this structure will automatically
returns 401.
Examples:
use actix_web::get;
use actix_web::HttpResponse;
use actix_jwt_session::Authenticated;
#[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 }
}
// If there's no JWT in request server will automatically returns 401
#[get("/session")]
async fn read_session(session: Authenticated<AppClaims>) -> HttpResponse {
let encoded = session.encode().unwrap(); // JWT as encrypted string
HttpResponse::Ok().finish()
}Fields§
§claims: Arc<T>§jwt_encoding_key: Arc<EncodingKey>§algorithm: AlgorithmImplementations§
Trait Implementations§
Source§impl<T: Clone> Clone for Authenticated<T>
impl<T: Clone> Clone for Authenticated<T>
Source§fn clone(&self) -> Authenticated<T>
fn clone(&self) -> Authenticated<T>
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 moreSource§impl<T> Deref for Authenticated<T>
impl<T> Deref for Authenticated<T>
Source§impl<T: Claims> FromRequest for Authenticated<T>
impl<T: Claims> FromRequest for Authenticated<T>
Source§type Future = Ready<Result<Authenticated<T>, Error>>
type Future = Ready<Result<Authenticated<T>, Error>>
Future that resolves to a
Self. Read moreSource§fn from_request(req: &HttpRequest, _payload: &mut Payload) -> Self::Future
fn from_request(req: &HttpRequest, _payload: &mut Payload) -> Self::Future
Create a
Self from request parts asynchronously.Auto Trait Implementations§
impl<T> Freeze for Authenticated<T>
impl<T> RefUnwindSafe for Authenticated<T>where
T: RefUnwindSafe,
impl<T> Send for Authenticated<T>
impl<T> Sync for Authenticated<T>
impl<T> Unpin for Authenticated<T>
impl<T> UnwindSafe for Authenticated<T>where
T: RefUnwindSafe,
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, A> DynAccess<T> for A
impl<T, A> DynAccess<T> for A
Source§fn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
The equivalent of
Access::load.