Add middleware to check authentication

This commit is contained in:
2023-09-02 19:15:11 +02:00
parent 849bf0cdfb
commit caaf3d703f
7 changed files with 126 additions and 8 deletions

View File

@ -12,6 +12,7 @@ use virtweb_backend::constants::{
MAX_INACTIVITY_DURATION, MAX_SESSION_DURATION, SESSION_COOKIE_NAME,
};
use virtweb_backend::controllers::{auth_controller, server_controller};
use virtweb_backend::middlewares::auth_middleware::AuthChecker;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
@ -37,6 +38,7 @@ async fn main() -> std::io::Result<()> {
App::new()
.wrap(Logger::default())
.wrap(AuthChecker)
.wrap(identity_middleware)
.wrap(session_mw)
.app_data(web::Data::new(RemoteIPConfig {
@ -53,6 +55,10 @@ async fn main() -> std::io::Result<()> {
"/api/auth/local",
web::post().to(auth_controller::local_auth),
)
.route(
"/api/auth/user",
web::get().to(auth_controller::current_user),
)
})
.bind(&AppConfig::get().listen_address)?
.run()