On server config route, add OIDC config
This commit is contained in:
@ -87,6 +87,30 @@ pub struct AppConfig {
|
||||
default_value = "http://localhost:3000/reset_password#TOKEN"
|
||||
)]
|
||||
pub reset_password_url: String,
|
||||
|
||||
/// URL where the OpenID configuration can be found
|
||||
#[arg(long, env, default_value = "url")]
|
||||
pub oidc_configuration_url: String,
|
||||
|
||||
/// Disable OpenID authentication
|
||||
#[arg(long, env)]
|
||||
pub disable_oidc: bool,
|
||||
|
||||
/// OpenID provider name
|
||||
#[arg(long, env, default_value = "3rd party provider")]
|
||||
pub oidc_provider_name: String,
|
||||
|
||||
/// OpenID client ID
|
||||
#[arg(long, env, default_value = "client")]
|
||||
pub oidc_client_id: String,
|
||||
|
||||
/// OpenID client secret
|
||||
#[arg(long, env, default_value = "secret")]
|
||||
pub oidc_client_secret: String,
|
||||
|
||||
/// OpenID login callback URL
|
||||
#[arg(long, env, default_value = "http://localhost:3000/oidc_cb")]
|
||||
pub oidc_callback_url: String,
|
||||
}
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
@ -125,4 +149,31 @@ impl AppConfig {
|
||||
pub fn get_password_reset_url(&self, token: &str) -> String {
|
||||
self.reset_password_url.replace("TOKEN", token)
|
||||
}
|
||||
|
||||
/// Get OpenID providers configuration
|
||||
pub fn openid_providers(&self) -> Vec<OIDCProvider> {
|
||||
if self.disable_oidc {
|
||||
return vec![];
|
||||
}
|
||||
|
||||
return vec![OIDCProvider {
|
||||
id: "first_prov".to_string(),
|
||||
client_id: self.oidc_client_id.to_string(),
|
||||
client_secret: self.oidc_client_secret.to_string(),
|
||||
configuration_url: self.oidc_configuration_url.to_string(),
|
||||
name: self.oidc_provider_name.to_string(),
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
pub struct OIDCProvider {
|
||||
pub id: String,
|
||||
#[serde(skip_serializing)]
|
||||
pub client_id: String,
|
||||
#[serde(skip_serializing)]
|
||||
pub client_secret: String,
|
||||
#[serde(skip_serializing)]
|
||||
pub configuration_url: String,
|
||||
pub name: String,
|
||||
}
|
||||
|
Reference in New Issue
Block a user