Get identity from middleware

This commit is contained in:
2022-04-02 17:03:51 +02:00
parent ad58d2de7e
commit cb4daa1112
3 changed files with 26 additions and 6 deletions

View File

@ -3,9 +3,14 @@
use std::future::{Future, ready, Ready};
use std::pin::Pin;
use std::rc::Rc;
use actix_identity::RequestIdentity;
use actix_web::{dev::{forward_ready, Service, ServiceRequest, ServiceResponse, Transform}, Error, HttpResponse};
use actix_web::{dev::{forward_ready, Service, ServiceRequest, ServiceResponse, Transform}, Error, FromRequest, HttpMessage, HttpResponse};
use actix_web::body::EitherBody;
use actix_web::cookie::{Cookie, CookieJar};
use actix_web::http::header::http_percent_encode;
use crate::constants::SESSION_COOKIE_NAME;
// There are two steps in middleware processing.
// 1. Middleware initialization, middleware factory gets called with
@ -33,6 +38,13 @@ impl<S, B> Transform<S, ServiceRequest> for AuthMiddleware
}
}
#[derive(Debug)]
enum SessionStatus {
SignedOut,
RegularUser,
Admin
}
pub struct AuthInnerMiddleware<S> {
service: Rc<S>,
}
@ -45,11 +57,13 @@ impl<S, B> Service<ServiceRequest> for AuthInnerMiddleware<S>
{
type Response = ServiceResponse<EitherBody<B>>;
type Error = Error;
#[allow(clippy::type_complexity)]
type Future = Pin<Box<dyn Future<Output=Result<Self::Response, Self::Error>>>>;
forward_ready!(service);
fn call(&self, req: ServiceRequest) -> Self::Future {
fn call(&self, mut req: ServiceRequest) -> Self::Future {
println!("Hi from start. You requested: {}", req.path());
let service = Rc::clone(&self.service);
@ -64,6 +78,9 @@ impl<S, B> Service<ServiceRequest> for AuthInnerMiddleware<S>
));
}
let identity = req.get_identity();
println!("identity: {:?}", identity);
service
.call(req)
.await