diff --git a/.env.example b/.env.example index 0c0f1c23..200b1aff 100644 --- a/.env.example +++ b/.env.example @@ -24,9 +24,10 @@ TENANT_MIDDLEWARE_EXCLUSION_LIST="/health,/assets/favicon.ico,/pkg/frontend.js,/ SERVICE_PREFIX="" SERVICE_NAME="CAC" AUTH_PROVIDER=DISABLED -## AUTH_PROVIDER=OIDC+http://localhost:8081/realms/users -OIDC_CLIENT_ID=superposition -OIDC_CLIENT_SECRET=superposition_secret -OIDC_TOKEN_ENDPOINT_FORMAT="http://localhost:8081/realms//protocol/openid-connect/token" -OIDC_ISSUER_ENDPOINT_FORMAT="http://http://localhost:8081/realms/" +LOCAL_ORGS=superposition +# AUTH_PROVIDER=OIDC+http://localhost:8081/realms/users +# OIDC_CLIENT_ID=superposition +# OIDC_CLIENT_SECRET=superposition_secret +# OIDC_TOKEN_ENDPOINT_FORMAT="http://localhost:8081/realms//protocol/openid-connect/token" +# OIDC_ISSUER_ENDPOINT_FORMAT="http://http://localhost:8081/realms/" WORKER_ID=1 diff --git a/crates/superposition/src/auth.rs b/crates/superposition/src/auth.rs index aa4db290..254d2275 100644 --- a/crates/superposition/src/auth.rs +++ b/crates/superposition/src/auth.rs @@ -104,7 +104,13 @@ impl AuthHandler { let mut auth = auth_provider.split('+'); let ap: Arc = match auth.next() { - Some("DISABLED") => Arc::new(DisabledAuthenticator), + Some("DISABLED") => Arc::new(DisabledAuthenticator::new( + get_from_env_unsafe::("LOCAL_ORGS") + .unwrap() + .split(",") + .map(String::from) + .collect(), + )), Some("OIDC") => { let url = Url::parse(auth.next().unwrap()) .map_err(|e| e.to_string()) diff --git a/crates/superposition/src/auth/no_auth.rs b/crates/superposition/src/auth/no_auth.rs index 648f7c7a..8121394e 100644 --- a/crates/superposition/src/auth/no_auth.rs +++ b/crates/superposition/src/auth/no_auth.rs @@ -9,7 +9,13 @@ use superposition_types::User; use super::authenticator::{Authenticator, SwitchOrgParams}; -pub struct DisabledAuthenticator; +pub struct DisabledAuthenticator(Vec); + +impl DisabledAuthenticator { + pub fn new(organisations: Vec) -> Self { + Self(organisations) + } +} impl Authenticator for DisabledAuthenticator { fn authenticate(&self, _: &ServiceRequest) -> Result { @@ -21,13 +27,13 @@ impl Authenticator for DisabledAuthenticator { } fn get_organisations(&self, _: &actix_web::HttpRequest) -> HttpResponse { - HttpResponse::Ok().json(serde_json::json!(vec!["superposition"])) + HttpResponse::Ok().json(serde_json::json!(self.0)) } fn switch_organisation( &self, _: &HttpRequest, - _: &Path, + path: &Path, ) -> LocalBoxFuture<'static, actix_web::Result> { let cookie = Cookie::build("org_user", "org_token") .path("/") @@ -35,10 +41,12 @@ impl Authenticator for DisabledAuthenticator { .max_age(Duration::days(1)) .finish(); + let org_id = path.organisation_id.clone(); + Box::pin(async move { Ok(HttpResponse::Found() .cookie(cookie) - .insert_header(("Location", "/")) + .insert_header(("Location", format!("/admin/{org_id}/workspaces"))) .finish()) }) }