chore: add settings adn load values to use openid with casdoor for Single Sign-On
This commit is contained in:
parent
7cc24d167d
commit
4cbdf902f8
@ -18,6 +18,7 @@ use crate::{
|
||||
};
|
||||
|
||||
use std::path::Path;
|
||||
use crate::defs::OpenidConf;
|
||||
|
||||
// use crate::tools::generate_uuid;
|
||||
// fn default_server_uid() -> String {
|
||||
@ -84,9 +85,8 @@ fn default_config_totp_mode() -> TotpMode {
|
||||
fn default_config_password_score() -> u8 {
|
||||
0
|
||||
}
|
||||
fn default_config_trace_level() -> u8 {
|
||||
1
|
||||
}
|
||||
fn default_config_trace_level() -> u8 { 1 }
|
||||
fn default_config_openid_auths() -> HashMap<String,OpenidConf> { HashMap::new() }
|
||||
#[derive(Debug, Clone, Serialize, Deserialize,Default)]
|
||||
pub struct SubMenuItem {
|
||||
#[serde(default = "default_config_empty")]
|
||||
@ -289,6 +289,11 @@ pub struct Config {
|
||||
pub path_menu_items: String,
|
||||
#[serde(default = "default_config_resource")]
|
||||
pub path_serv_paths: String,
|
||||
|
||||
#[serde(default = "default_config_empty")]
|
||||
pub openid_access_token_url: String,
|
||||
#[serde(default = "default_config_openid_auths")]
|
||||
pub openid_auths: HashMap<String,OpenidConf>,
|
||||
}
|
||||
|
||||
impl FromFile for Config {
|
||||
|
@ -73,6 +73,7 @@ use defs::{
|
||||
AppConnectInfo,
|
||||
};
|
||||
use users::UserStore;
|
||||
use defs::collect_openid_clients;
|
||||
|
||||
use tera_tpls::init_tera;
|
||||
use tower_cookies::CookieManagerLayer;
|
||||
@ -263,7 +264,10 @@ async fn main() {
|
||||
init_tera(&config.templates_path), context
|
||||
)
|
||||
);
|
||||
let middleware =
|
||||
let openid_clients = Arc::new(
|
||||
collect_openid_clients(config.to_owned(), "https://tiicl.tls13.io:8800/from_openid?response_type=code").await
|
||||
);
|
||||
let middleware =
|
||||
axum::middleware::from_fn_with_state(app_dbs.clone(),rewrite_request_uri);
|
||||
// apply the layer around the whole `Router`
|
||||
// this way the middleware will run before `Router` receives the request
|
||||
@ -306,7 +310,7 @@ async fn main() {
|
||||
let mut os_rng = OsRng{};
|
||||
os_rng.fill_bytes(&mut key);
|
||||
let random = ChaCha8Rng::seed_from_u64(OsRng.next_u64());
|
||||
|
||||
|
||||
web_router = web_router
|
||||
.merge(users_router_handlers())
|
||||
.merge(admin_router_handlers())
|
||||
@ -314,6 +318,7 @@ async fn main() {
|
||||
.layer(ServiceBuilder::new().layer(middleware))
|
||||
.layer(CookieManagerLayer::new())
|
||||
.layer(Extension(app_dbs))
|
||||
.layer(Extension(openid_clients))
|
||||
.layer(Extension(Arc::new(Mutex::new(random))))
|
||||
.fallback_service(handle_404.into_service())
|
||||
;
|
||||
|
Loading…
Reference in New Issue
Block a user