Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit 0a94dcf7 authored by Pierre Jarriges's avatar Pierre Jarriges
Browse files

wip impl auth middleware

parent 2e96d44b
No related branches found
No related tags found
No related merge requests found
......@@ -23,4 +23,10 @@ pub struct AppArgs {
#[structopt(long = "certs_dir", default_value = "/etc/letsencrypt/live")]
pub ssl_certs_dir: PathBuf,
#[structopt(short = "u", long = "username", default_value = "admin")]
pub admin_id: String,
#[structopt(short = "p", long = "password", default_value = "password")]
pub admin_pwd: String,
}
......@@ -18,6 +18,8 @@ pub struct AppConfig {
pub port_tls: u16,
pub load: Option<PathBuf>,
pub ssl_certs_dir: PathBuf,
pub admin_id: String,
pub admin_pwd: String,
}
impl AppConfig {
......@@ -57,6 +59,8 @@ impl AppConfig {
port_tls: app_args.port_tls,
load: app_args.load,
ssl_certs_dir,
admin_id: app_args.admin_id,
admin_pwd: app_args.admin_pwd,
}
}
pub fn get_log_level(&self) -> String {
......
mod app;
mod middleware;
mod service;
mod static_files;
mod testing;
......
use actix_web::{
dev::{forward_ready, Service, ServiceRequest, ServiceResponse, Transform},
Error,
};
use futures::prelude::future::LocalBoxFuture;
use std::future::{ready, Ready};
pub struct AuthData;
impl<S, B> Transform<S, ServiceRequest> for AuthData
where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
B: 'static,
{
type Response = ServiceResponse<B>;
type Error = Error;
type InitError = ();
type Transform = AuthenticatedMiddleware<S>;
type Future = Ready<Result<Self::Transform, Self::InitError>>;
fn new_transform(&self, service: S) -> Self::Future {
ready(Ok(AuthenticatedMiddleware { service }))
}
}
pub struct AuthenticatedMiddleware<S> {
service: S,
}
impl<S, B> Service<ServiceRequest> for AuthenticatedMiddleware<S>
where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
B: 'static,
{
type Response = ServiceResponse<B>;
type Error = Error;
type Future = LocalBoxFuture<'static, Result<Self::Response, Self::Error>>;
forward_ready!(service);
fn call(&self, req: ServiceRequest) -> Self::Future {
println!("AUTH MW");
let fut = self.service.call(req);
Box::pin(async move {
let res = fut.await?;
println!("RESP");
Ok(res)
})
}
}
mod authentication;
pub use authentication::*;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment