fix(auth): remove rest of todos for hot path
Some checks failed
continuous-integration/drone/push Build is failing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2023-08-20 16:29:07 +02:00
parent 7a71f9b106
commit 1f13172ec0
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394
4 changed files with 37 additions and 9 deletions

View File

@ -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<dyn Auth + Send + Sync + 'static>);
impl AuthService {
pub async fn new(config: &AuthClap) -> anyhow::Result<Self> {
pub async fn new(config: &AuthClap, session: SessionService) -> anyhow::Result<Self> {
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 {

View File

@ -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 {

View File

@ -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,
})))
}
}
}

View File

@ -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<AppConfig>) -> anyhow::Result<Self> {
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 => {