fix(auth): remove rest of todos for hot path
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
7a71f9b106
commit
1f13172ec0
@ -7,7 +7,7 @@ use oauth2::url::Url;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
introspection::IntrospectionService,
|
introspection::IntrospectionService,
|
||||||
oauth::OAuth,
|
oauth::{OAuth, ZitadelConfig},
|
||||||
session::{SessionService, User},
|
session::{SessionService, User},
|
||||||
AuthClap, AuthEngine,
|
AuthClap, AuthEngine,
|
||||||
};
|
};
|
||||||
@ -23,16 +23,29 @@ pub trait Auth {
|
|||||||
pub struct AuthService(Arc<dyn Auth + Send + Sync + 'static>);
|
pub struct AuthService(Arc<dyn Auth + Send + Sync + 'static>);
|
||||||
|
|
||||||
impl AuthService {
|
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 {
|
match config.engine {
|
||||||
AuthEngine::Noop => Ok(Self::new_noop()),
|
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 {
|
pub fn new_zitadel(
|
||||||
todo!()
|
oauth: OAuth,
|
||||||
//Self(Arc::new(ZitadelAuthService {}))
|
introspection: IntrospectionService,
|
||||||
|
session: SessionService,
|
||||||
|
) -> Self {
|
||||||
|
Self(Arc::new(ZitadelAuthService {
|
||||||
|
oauth,
|
||||||
|
introspection,
|
||||||
|
session,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_noop() -> Self {
|
pub fn new_noop() -> Self {
|
||||||
|
@ -8,6 +8,7 @@ mod session;
|
|||||||
|
|
||||||
pub use auth::{Auth, AuthService};
|
pub use auth::{Auth, AuthService};
|
||||||
use session::SessionClap;
|
use session::SessionClap;
|
||||||
|
pub use session::SessionService;
|
||||||
|
|
||||||
#[derive(clap::ValueEnum, Clone, PartialEq, Eq, Debug)]
|
#[derive(clap::ValueEnum, Clone, PartialEq, Eq, Debug)]
|
||||||
pub enum AuthEngine {
|
pub enum AuthEngine {
|
||||||
|
@ -4,6 +4,7 @@ use async_sqlx_session::PostgresSessionStore;
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use axum_sessions::async_session::{Session as AxumSession, SessionStore as AxumSessionStore};
|
use axum_sessions::async_session::{Session as AxumSession, SessionStore as AxumSessionStore};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use sqlx::PgPool;
|
||||||
|
|
||||||
use crate::{AuthClap, SessionBackend};
|
use crate::{AuthClap, SessionBackend};
|
||||||
|
|
||||||
@ -31,7 +32,19 @@ impl SessionService {
|
|||||||
match config.session_backend {
|
match config.session_backend {
|
||||||
SessionBackend::InMemory => Ok(Self(Arc::new(InMemorySessionService {}))),
|
SessionBackend::InMemory => Ok(Self(Arc::new(InMemorySessionService {}))),
|
||||||
SessionBackend::Postgresql => {
|
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,
|
||||||
|
})))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use async_sqlx_session::PostgresSessionStore;
|
use async_sqlx_session::PostgresSessionStore;
|
||||||
use como_auth::AuthService;
|
use como_auth::{AuthService, SessionService};
|
||||||
use como_core::{items::DynItemService, projects::DynProjectService, users::DynUserService};
|
use como_core::{items::DynItemService, projects::DynProjectService, users::DynUserService};
|
||||||
use tracing::log::info;
|
use tracing::log::info;
|
||||||
|
|
||||||
@ -28,7 +28,8 @@ impl ServiceRegister {
|
|||||||
pub async fn new(pool: ConnectionPool, config: Arc<AppConfig>) -> anyhow::Result<Self> {
|
pub async fn new(pool: ConnectionPool, config: Arc<AppConfig>) -> anyhow::Result<Self> {
|
||||||
info!("creating services");
|
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 {
|
let s = match config.database_type {
|
||||||
DatabaseType::Postgres => {
|
DatabaseType::Postgres => {
|
||||||
|
Loading…
Reference in New Issue
Block a user