Load server config on react app
This commit is contained in:
@ -81,19 +81,11 @@ pub struct AppConfig {
|
||||
pub smtp_password: Option<String>,
|
||||
|
||||
/// Password reset URL
|
||||
#[clap(
|
||||
long,
|
||||
env,
|
||||
default_value = "http://localhost:3000/reset_password#TOKEN"
|
||||
)]
|
||||
#[clap(long, env, default_value = "APP_ORIGIN/reset_password#TOKEN")]
|
||||
pub reset_password_url: String,
|
||||
|
||||
/// Delete account URL
|
||||
#[clap(
|
||||
long,
|
||||
env,
|
||||
default_value = "http://localhost:3000/delete_account#TOKEN"
|
||||
)]
|
||||
#[clap(long, env, default_value = "APP_ORIGIN/delete_account#TOKEN")]
|
||||
pub delete_account_url: String,
|
||||
|
||||
/// URL where the OpenID configuration can be found
|
||||
@ -121,8 +113,8 @@ pub struct AppConfig {
|
||||
pub oidc_client_secret: String,
|
||||
|
||||
/// OpenID login redirect URL
|
||||
#[arg(long, env, default_value = "http://localhost:3000/oidc_cb")]
|
||||
pub oidc_redirect_url: String,
|
||||
#[arg(long, env, default_value = "APP_ORIGIN/oidc_cb")]
|
||||
oidc_redirect_url: String,
|
||||
}
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
@ -159,12 +151,16 @@ impl AppConfig {
|
||||
|
||||
/// Get password reset URL
|
||||
pub fn get_password_reset_url(&self, token: &str) -> String {
|
||||
self.reset_password_url.replace("TOKEN", token)
|
||||
self.reset_password_url
|
||||
.replace("APP_ORIGIN", &self.website_origin)
|
||||
.replace("TOKEN", token)
|
||||
}
|
||||
|
||||
/// Get account delete URL
|
||||
pub fn get_account_delete_url(&self, token: &str) -> String {
|
||||
self.delete_account_url.replace("TOKEN", token)
|
||||
self.delete_account_url
|
||||
.replace("APP_ORIGIN", &self.website_origin)
|
||||
.replace("TOKEN", token)
|
||||
}
|
||||
|
||||
/// Get OpenID providers configuration
|
||||
@ -181,6 +177,12 @@ impl AppConfig {
|
||||
name: self.oidc_provider_name.as_str(),
|
||||
}]
|
||||
}
|
||||
|
||||
/// Get OIDC callback URL
|
||||
pub fn oidc_redirect_url(&self) -> String {
|
||||
self.oidc_redirect_url
|
||||
.replace("APP_ORIGIN", &self.website_origin)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
|
@ -1,3 +1,4 @@
|
||||
use actix_cors::Cors;
|
||||
use actix_remote_ip::RemoteIPConfig;
|
||||
use actix_web::middleware::Logger;
|
||||
use actix_web::{web, App, HttpServer};
|
||||
@ -12,6 +13,14 @@ async fn main() -> std::io::Result<()> {
|
||||
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.wrap(
|
||||
Cors::default()
|
||||
.allowed_origin(&AppConfig::get().website_origin)
|
||||
.allowed_methods(vec!["GET", "POST"])
|
||||
.allowed_header("X-Auth-Token")
|
||||
.supports_credentials()
|
||||
.max_age(3600),
|
||||
)
|
||||
.wrap(Logger::default())
|
||||
.app_data(web::Data::new(RemoteIPConfig {
|
||||
proxy: AppConfig::get().proxy_ip.clone(),
|
||||
|
@ -96,7 +96,7 @@ pub async fn start_login(prov_id: &str, ip: IpAddr) -> anyhow::Result<String> {
|
||||
Ok(prov.conf.gen_authorization_url(
|
||||
prov.prov.client_id,
|
||||
&state_key,
|
||||
&AppConfig::get().oidc_redirect_url,
|
||||
&AppConfig::get().oidc_redirect_url(),
|
||||
))
|
||||
}
|
||||
|
||||
@ -133,7 +133,7 @@ pub async fn finish_login(
|
||||
prov.prov.client_id,
|
||||
prov.prov.client_secret,
|
||||
code,
|
||||
&AppConfig::get().oidc_redirect_url,
|
||||
&AppConfig::get().oidc_redirect_url(),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| OpenIDServiceError::QueryTokenEndpoint(e.to_string()))?;
|
||||
|
Reference in New Issue
Block a user