Struct actix_jwt_session::Authenticated
source · 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: Algorithm
Implementations§
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 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<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§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> 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§
§impl<T, A, P> Access<T> for P
impl<T, A, P> Access<T> for P
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