From 0406b0dc8dc1ffa09c7125d829d5fde5ef05056e Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Mon, 28 Nov 2022 19:59:42 +0000 Subject: [PATCH] fix redirect. config for login domain --- config/example.toml | 1 + web3_proxy/src/config.rs | 1 + web3_proxy/src/frontend/rpc_proxy_ws.rs | 6 +++--- web3_proxy/src/frontend/users.rs | 13 ++++++++++--- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/config/example.toml b/config/example.toml index 996b5ecf..9dad8262 100644 --- a/config/example.toml +++ b/config/example.toml @@ -35,6 +35,7 @@ redirect_rpc_key_url = "https://llamanodes.com/dashboard/keys?key={rpc_key_id}" public_max_concurrent_requests = 3 # 0 = block all public requests public_requests_per_period = 200 +login_domain = "llamanodes.com" # 10GB of cache response_cache_max_bytes = 10_000_000_000 diff --git a/web3_proxy/src/config.rs b/web3_proxy/src/config.rs index 98a38d22..c884082e 100644 --- a/web3_proxy/src/config.rs +++ b/web3_proxy/src/config.rs @@ -79,6 +79,7 @@ pub struct AppConfig { /// Restrict user registration. /// None = no code needed pub invite_code: Option, + pub login_domain: Option, /// Rate limit for bearer token authenticated entrypoints. /// This is separate from the rpc limits. diff --git a/web3_proxy/src/frontend/rpc_proxy_ws.rs b/web3_proxy/src/frontend/rpc_proxy_ws.rs index d8df70d3..9768ff83 100644 --- a/web3_proxy/src/frontend/rpc_proxy_ws.rs +++ b/web3_proxy/src/frontend/rpc_proxy_ws.rs @@ -56,7 +56,7 @@ pub async fn websocket_handler( None => { if let Some(redirect) = &app.config.redirect_public_url { // this is not a websocket. redirect to a friendly page - Ok(Redirect::to(redirect).into_response()) + Ok(Redirect::permanent(redirect).into_response()) } else { // TODO: do not use an anyhow error. send the user a 400 Err( @@ -117,7 +117,7 @@ pub async fn websocket_handler_with_key( None, )), (Some(redirect_public_url), _, None) => { - Ok(Redirect::to(redirect_public_url).into_response()) + Ok(Redirect::permanent(redirect_public_url).into_response()) } (_, Some(redirect_rpc_key_url), rpc_key_id) => { let reg = Handlebars::new(); @@ -138,7 +138,7 @@ pub async fn websocket_handler_with_key( .expect("templating should always work"); // this is not a websocket. redirect to a page for this user - Ok(Redirect::to(&redirect_rpc_key_url).into_response()) + Ok(Redirect::permanent(&redirect_rpc_key_url).into_response()) } } // any other combinations get a simple error diff --git a/web3_proxy/src/frontend/users.rs b/web3_proxy/src/frontend/users.rs index 4cd4ab1f..5b93681c 100644 --- a/web3_proxy/src/frontend/users.rs +++ b/web3_proxy/src/frontend/users.rs @@ -85,13 +85,20 @@ pub async fn user_login_get( // TODO: map_err so this becomes a 401 .context("bad input")?; + let login_domain = app + .config + .login_domain + .clone() + .unwrap_or_else(|| "llamanodes.com".to_string()); + // TODO: get most of these from the app config let message = Message { - // TODO: get this from app config - domain: "llamanodes.com".parse().unwrap(), + // TODO: don't unwrap + domain: login_domain.parse().unwrap(), address: user_address.to_fixed_bytes(), statement: Some("🦙🦙🦙🦙🦙".to_string()), - uri: "https://llamanodes.com/".parse().unwrap(), + // TODO: don't unwrap + uri: format!("https://{}/", login_domain).parse().unwrap(), version: siwe::Version::V1, chain_id: 1, expiration_time: Some(expiration_time.into()),