Add basic providers configuration
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@ -2,7 +2,7 @@ use std::path::{Path, PathBuf};
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
use crate::constants::{APP_NAME, CLIENTS_LIST_FILE, USERS_LIST_FILE};
|
||||
use crate::constants::{APP_NAME, CLIENTS_LIST_FILE, PROVIDERS_LIST_FILE, USERS_LIST_FILE};
|
||||
|
||||
/// Basic OIDC provider
|
||||
#[derive(Parser, Debug, Clone)]
|
||||
@ -72,6 +72,10 @@ impl AppConfig {
|
||||
self.storage_path().join(CLIENTS_LIST_FILE)
|
||||
}
|
||||
|
||||
pub fn providers_file(&self) -> PathBuf {
|
||||
self.storage_path().join(PROVIDERS_LIST_FILE)
|
||||
}
|
||||
|
||||
pub fn full_url(&self, uri: &str) -> String {
|
||||
if uri.starts_with('/') {
|
||||
format!("{}{}", self.website_origin, uri)
|
||||
|
@ -11,6 +11,7 @@ pub mod jwt_signer;
|
||||
pub mod login_redirect;
|
||||
pub mod open_id_user_info;
|
||||
pub mod openid_config;
|
||||
pub mod provider;
|
||||
pub mod remote_ip;
|
||||
pub mod session_identity;
|
||||
pub mod totp_key;
|
||||
|
60
src/data/provider.rs
Normal file
60
src/data/provider.rs
Normal file
@ -0,0 +1,60 @@
|
||||
use crate::data::entity_manager::EntityManager;
|
||||
use crate::utils::string_utils::apply_env_vars;
|
||||
|
||||
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, Eq, PartialEq)]
|
||||
pub struct ProviderID(pub String);
|
||||
|
||||
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub struct Provider {
|
||||
/// The ID of the provider
|
||||
pub id: ProviderID,
|
||||
|
||||
/// The human-readable name of the client
|
||||
pub name: String,
|
||||
|
||||
/// A logo presented to the users of the provider
|
||||
pub logo: String,
|
||||
|
||||
/// The registration id of BasicOIDC on the provider
|
||||
pub client_id: String,
|
||||
|
||||
/// The registration secret of BasicOIDC on the provider
|
||||
pub client_secret: String,
|
||||
|
||||
/// Specify the URL of the OpenID configuration URL
|
||||
///
|
||||
/// (.well-known/openid-configuration endpoint)
|
||||
pub configuration_url: String,
|
||||
}
|
||||
|
||||
impl PartialEq for Provider {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.id.eq(&other.id)
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for Provider {}
|
||||
|
||||
pub type ProvidersManager = EntityManager<Provider>;
|
||||
|
||||
impl EntityManager<Provider> {
|
||||
pub fn find_by_id(&self, u: &ProviderID) -> Option<Provider> {
|
||||
for entry in self.iter() {
|
||||
if entry.id.eq(u) {
|
||||
return Some(entry.clone());
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn apply_environment_variables(&mut self) {
|
||||
for c in self.iter_mut() {
|
||||
c.id = ProviderID(apply_env_vars(&c.id.0));
|
||||
c.name = apply_env_vars(&c.name);
|
||||
c.logo = apply_env_vars(&c.logo);
|
||||
c.client_id = apply_env_vars(&c.client_id);
|
||||
c.client_secret = apply_env_vars(&c.client_secret);
|
||||
c.configuration_url = apply_env_vars(&c.configuration_url);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user