diff --git a/como_auth/src/auth.rs b/como_auth/src/auth.rs index 9f09726..ea9281f 100644 --- a/como_auth/src/auth.rs +++ b/como_auth/src/auth.rs @@ -7,7 +7,7 @@ use oauth2::url::Url; use crate::{ introspection::IntrospectionService, - oauth::OAuth, + oauth::{OAuth, ZitadelConfig}, session::{SessionService, User}, AuthClap, AuthEngine, }; @@ -23,16 +23,29 @@ pub trait Auth { pub struct AuthService(Arc); impl AuthService { - pub async fn new(config: &AuthClap) -> anyhow::Result { + pub async fn new(config: &AuthClap, session: SessionService) -> anyhow::Result { match config.engine { AuthEngine::Noop => Ok(Self::new_noop()), - AuthEngine::Zitadel => Ok(Self::new_zitadel()), + AuthEngine::Zitadel => { + let oauth: OAuth = ZitadelConfig::try_from(config.zitadel.clone())?.into(); + let introspection: IntrospectionService = + IntrospectionService::new_zitadel(config).await?; + + Ok(Self::new_zitadel(oauth, introspection, session)) + } } } - pub fn new_zitadel() -> Self { - todo!() - //Self(Arc::new(ZitadelAuthService {})) + pub fn new_zitadel( + oauth: OAuth, + introspection: IntrospectionService, + session: SessionService, + ) -> Self { + Self(Arc::new(ZitadelAuthService { + oauth, + introspection, + session, + })) } pub fn new_noop() -> Self { diff --git a/como_auth/src/lib.rs b/como_auth/src/lib.rs index ee3cd76..9812190 100644 --- a/como_auth/src/lib.rs +++ b/como_auth/src/lib.rs @@ -8,6 +8,7 @@ mod session; pub use auth::{Auth, AuthService}; use session::SessionClap; +pub use session::SessionService; #[derive(clap::ValueEnum, Clone, PartialEq, Eq, Debug)] pub enum AuthEngine { diff --git a/como_auth/src/session.rs b/como_auth/src/session.rs index da2b0f8..4e3a12d 100644 --- a/como_auth/src/session.rs +++ b/como_auth/src/session.rs @@ -4,6 +4,7 @@ use async_sqlx_session::PostgresSessionStore; use async_trait::async_trait; use axum_sessions::async_session::{Session as AxumSession, SessionStore as AxumSessionStore}; use serde::{Deserialize, Serialize}; +use sqlx::PgPool; use crate::{AuthClap, SessionBackend}; @@ -31,7 +32,19 @@ impl SessionService { match config.session_backend { SessionBackend::InMemory => Ok(Self(Arc::new(InMemorySessionService {}))), SessionBackend::Postgresql => { - Ok(Self(Arc::new(PostgresSessionService { store: todo!() }))) + let postgres_session = PostgresSessionStore::new( + config + .session + .postgresql + .conn + .as_ref() + .expect("SESSION_POSTGRES_CONN to be set"), + ) + .await?; + + Ok(Self(Arc::new(PostgresSessionService { + store: postgres_session, + }))) } } } diff --git a/como_infrastructure/src/register.rs b/como_infrastructure/src/register.rs index 7af9805..7aa68e1 100644 --- a/como_infrastructure/src/register.rs +++ b/como_infrastructure/src/register.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use async_sqlx_session::PostgresSessionStore; -use como_auth::AuthService; +use como_auth::{AuthService, SessionService}; use como_core::{items::DynItemService, projects::DynProjectService, users::DynUserService}; use tracing::log::info; @@ -28,7 +28,8 @@ impl ServiceRegister { pub async fn new(pool: ConnectionPool, config: Arc) -> anyhow::Result { info!("creating services"); - let auth = AuthService::new(&config.auth).await?; + let session = SessionService::new(&config.auth).await?; + let auth = AuthService::new(&config.auth, session).await?; let s = match config.database_type { DatabaseType::Postgres => {