Some checks failed
CI / Format (push) Failing after 2s
CI / Clippy (push) Successful in 2m54s
CI / Security Audit (push) Has been skipped
CI / Tests (push) Has been skipped
CI / Clippy (pull_request) Successful in 3m4s
CI / Security Audit (pull_request) Has been skipped
CI / Tests (pull_request) Has been skipped
CI / Format (pull_request) Failing after 2s
When KEYCLOAK_URL is not set, the dashboard runs without auth, treating all users as authenticated "Local User". Auth middleware and check-auth endpoint gracefully skip when Keycloak is unconfigured. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
56 lines
1.4 KiB
Rust
56 lines
1.4 KiB
Rust
/// Keycloak OpenID Connect settings.
|
|
#[derive(Debug)]
|
|
pub struct KeycloakConfig {
|
|
pub url: String,
|
|
pub realm: String,
|
|
pub client_id: String,
|
|
pub redirect_uri: String,
|
|
pub app_url: String,
|
|
}
|
|
|
|
impl KeycloakConfig {
|
|
pub fn from_env() -> Option<Self> {
|
|
let url = std::env::var("KEYCLOAK_URL").ok()?;
|
|
let realm = std::env::var("KEYCLOAK_REALM").ok()?;
|
|
let client_id = std::env::var("KEYCLOAK_CLIENT_ID").ok()?;
|
|
let redirect_uri = std::env::var("REDIRECT_URI").ok()?;
|
|
let app_url = std::env::var("APP_URL").ok()?;
|
|
Some(Self {
|
|
url,
|
|
realm,
|
|
client_id,
|
|
redirect_uri,
|
|
app_url,
|
|
})
|
|
}
|
|
|
|
pub fn auth_endpoint(&self) -> String {
|
|
format!(
|
|
"{}/realms/{}/protocol/openid-connect/auth",
|
|
self.url, self.realm
|
|
)
|
|
}
|
|
|
|
pub fn token_endpoint(&self) -> String {
|
|
format!(
|
|
"{}/realms/{}/protocol/openid-connect/token",
|
|
self.url, self.realm
|
|
)
|
|
}
|
|
|
|
pub fn userinfo_endpoint(&self) -> String {
|
|
format!(
|
|
"{}/realms/{}/protocol/openid-connect/userinfo",
|
|
self.url, self.realm
|
|
)
|
|
}
|
|
|
|
pub fn logout_endpoint(&self) -> String {
|
|
format!(
|
|
"{}/realms/{}/protocol/openid-connect/logout",
|
|
self.url, self.realm
|
|
)
|
|
}
|
|
}
|
|
|