Skip to content

Commit

Permalink
fix: Redirect to workspaces after selecting org_id in local
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushjain17 authored and Datron committed Jan 2, 2025
1 parent 80acad9 commit c885e1c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
11 changes: 6 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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/<organisation>/protocol/openid-connect/token"
OIDC_ISSUER_ENDPOINT_FORMAT="http://http://localhost:8081/realms/<organisation>"
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/<organisation>/protocol/openid-connect/token"
# OIDC_ISSUER_ENDPOINT_FORMAT="http://http://localhost:8081/realms/<organisation>"
WORKER_ID=1
8 changes: 7 additions & 1 deletion crates/superposition/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ impl AuthHandler {
let mut auth = auth_provider.split('+');

let ap: Arc<dyn Authenticator> = match auth.next() {
Some("DISABLED") => Arc::new(DisabledAuthenticator),
Some("DISABLED") => Arc::new(DisabledAuthenticator::new(
get_from_env_unsafe::<String>("LOCAL_ORGS")
.unwrap()
.split(",")
.map(String::from)
.collect(),
)),
Some("OIDC") => {
let url = Url::parse(auth.next().unwrap())
.map_err(|e| e.to_string())
Expand Down
16 changes: 12 additions & 4 deletions crates/superposition/src/auth/no_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ use superposition_types::User;

use super::authenticator::{Authenticator, SwitchOrgParams};

pub struct DisabledAuthenticator;
pub struct DisabledAuthenticator(Vec<String>);

impl DisabledAuthenticator {
pub fn new(organisations: Vec<String>) -> Self {
Self(organisations)
}
}

impl Authenticator for DisabledAuthenticator {
fn authenticate(&self, _: &ServiceRequest) -> Result<User, actix_web::HttpResponse> {
Expand All @@ -21,24 +27,26 @@ 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<SwitchOrgParams>,
path: &Path<SwitchOrgParams>,
) -> LocalBoxFuture<'static, actix_web::Result<HttpResponse>> {
let cookie = Cookie::build("org_user", "org_token")
.path("/")
.http_only(true)
.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())
})
}
Expand Down

0 comments on commit c885e1c

Please sign in to comment.