Add actix-identity crate
This commit is contained in:
14
src/main.rs
14
src/main.rs
@ -10,6 +10,7 @@ use basic_oidc::data::entity_manager::EntityManager;
|
||||
use basic_oidc::data::user::{hash_password, User};
|
||||
use basic_oidc::actors::users_actor::UsersActor;
|
||||
use actix::Actor;
|
||||
use actix_identity::{IdentityService, CookieIdentityPolicy};
|
||||
|
||||
#[get("/health")]
|
||||
async fn health() -> &'static str {
|
||||
@ -20,7 +21,12 @@ async fn health() -> &'static str {
|
||||
async fn main() -> std::io::Result<()> {
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
|
||||
let config: AppConfig = AppConfig::parse();
|
||||
let mut config: AppConfig = AppConfig::parse();
|
||||
|
||||
// In debug mode only, use dummy token
|
||||
if cfg!(debug_assertions) && config.token_key.is_empty() {
|
||||
config.token_key = String::from_utf8_lossy(&[32; 32]).to_string();
|
||||
}
|
||||
|
||||
if !config.storage_path().exists() {
|
||||
log::error!(
|
||||
@ -55,10 +61,16 @@ async fn main() -> std::io::Result<()> {
|
||||
log::info!("Server will listen on {}", config.listen_address);
|
||||
|
||||
HttpServer::new(move || {
|
||||
let policy = CookieIdentityPolicy::new(config.token_key.as_bytes())
|
||||
.name("auth-cookie")
|
||||
.secure(config.secure_auth_cookie);
|
||||
|
||||
|
||||
App::new()
|
||||
.app_data(web::Data::new(users_actor.clone()))
|
||||
|
||||
.wrap(Logger::default())
|
||||
.wrap(IdentityService::new(policy))
|
||||
|
||||
// /health route
|
||||
.service(health)
|
||||
|
Reference in New Issue
Block a user