Add OpenID routes

This commit is contained in:
2023-09-04 11:25:03 +02:00
parent caaf3d703f
commit 83bd87c6f8
6 changed files with 212 additions and 6 deletions

View File

@ -5,7 +5,9 @@ use actix_session::storage::CookieSessionStore;
use actix_session::SessionMiddleware;
use actix_web::cookie::{Key, SameSite};
use actix_web::middleware::Logger;
use actix_web::web::Data;
use actix_web::{web, App, HttpServer};
use light_openid::basic_state_manager::BasicStateManager;
use std::time::Duration;
use virtweb_backend::app_config::AppConfig;
use virtweb_backend::constants::{
@ -20,7 +22,9 @@ async fn main() -> std::io::Result<()> {
log::info!("Start to listen on {}", AppConfig::get().listen_address);
HttpServer::new(|| {
let state_manager = Data::new(BasicStateManager::new());
HttpServer::new(move || {
let session_mw = SessionMiddleware::builder(
CookieSessionStore::default(),
Key::from(AppConfig::get().secret().as_bytes()),
@ -41,7 +45,8 @@ async fn main() -> std::io::Result<()> {
.wrap(AuthChecker)
.wrap(identity_middleware)
.wrap(session_mw)
.app_data(web::Data::new(RemoteIPConfig {
.app_data(state_manager.clone())
.app_data(Data::new(RemoteIPConfig {
proxy: AppConfig::get().proxy_ip.clone(),
}))
// Server controller
@ -55,10 +60,22 @@ async fn main() -> std::io::Result<()> {
"/api/auth/local",
web::post().to(auth_controller::local_auth),
)
.route(
"/api/auth/start_oidc",
web::get().to(auth_controller::start_oidc),
)
.route(
"/api/auth/finish_oidc",
web::post().to(auth_controller::finish_oidc),
)
.route(
"/api/auth/user",
web::get().to(auth_controller::current_user),
)
.route(
"/api/auth/sign_out",
web::get().to(auth_controller::sign_out),
)
})
.bind(&AppConfig::get().listen_address)?
.run()