diff --git a/proto b/proto index 1b8f7c5..d069a0e 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 1b8f7c5cfccf7e4f3a7a8422215c9db1d6fcc68e +Subproject commit d069a0e5304281cfc8b09e949a8e7a9feb5fc115 diff --git a/src/handlers/enrollment.rs b/src/handlers/enrollment.rs index 9a7c4ec..bb8d5da 100644 --- a/src/handlers/enrollment.rs +++ b/src/handlers/enrollment.rs @@ -82,12 +82,11 @@ pub async fn activate_user( let payload = get_core_response(rx).await?; debug!("Receving payload from the core service. Trying to remove private cookie..."); if let core_response::Payload::Empty(()) = payload { + info!("Activated user - phone number {phone:?}"); if let Some(cookie) = private_cookies.get(ENROLLMENT_COOKIE_NAME) { - info!("Activated user - phone number {phone:?}"); debug!("Enrollment finished. Removing session cookie"); private_cookies = private_cookies.remove(cookie); } - Ok(private_cookies) } else { error!("Received invalid gRPC response type: {payload:#?}"); diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 1fb53e9..6531087 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -1,7 +1,3 @@ -pub(crate) mod desktop_client_mfa; -pub(crate) mod enrollment; -pub(crate) mod password_reset; - use crate::{error::ApiError, proto::core_response::Payload}; use axum::{extract::FromRequestParts, http::request::Parts}; use axum_client_ip::{InsecureClientIp, LeftmostXForwardedFor}; @@ -11,6 +7,11 @@ use tokio::{sync::oneshot::Receiver, time::timeout}; use super::proto::DeviceInfo; +pub(crate) mod desktop_client_mfa; +pub(crate) mod enrollment; +pub(crate) mod password_reset; +pub(crate) mod polling; + // timeout in seconds for awaiting core response const CORE_RESPONSE_TIMEOUT: u64 = 5; diff --git a/src/handlers/polling.rs b/src/handlers/polling.rs new file mode 100644 index 0000000..3820196 --- /dev/null +++ b/src/handlers/polling.rs @@ -0,0 +1,28 @@ +use axum::{extract::State, Json}; + +use crate::{ + error::ApiError, + handlers::get_core_response, + http::AppState, + proto::{core_request, core_response, InstanceInfoRequest, InstanceInfoResponse}, +}; + +#[instrument(level = "debug", skip(state))] +pub async fn info( + State(state): State, + Json(req): Json, +) -> Result, ApiError> { + debug!("Retrieving info for polling request"); + let rx = state + .grpc_server + .send(Some(core_request::Payload::InstanceInfo(req.clone())), None)?; + let payload = get_core_response(rx).await?; + + if let core_response::Payload::InstanceInfo(response) = payload { + info!("Retrieved info for polling request"); + Ok(Json(response)) + } else { + error!("Received invalid gRPC response type: {payload:#?}"); + Err(ApiError::InvalidResponseType) + } +} diff --git a/src/http.rs b/src/http.rs index 3bdfa7a..a6be8d3 100644 --- a/src/http.rs +++ b/src/http.rs @@ -10,7 +10,7 @@ use axum::{ body::Body, extract::{ConnectInfo, FromRef, State}, http::{Request, StatusCode}, - routing::get, + routing::{get, post}, serve, Json, Router, }; use axum_extra::extract::cookie::Key; @@ -29,7 +29,7 @@ use crate::{ config::Config, error::ApiError, grpc::ProxyServer, - handlers::{desktop_client_mfa, enrollment, password_reset}, + handlers::{desktop_client_mfa, enrollment, password_reset, polling}, proto::proxy_server, }; @@ -188,6 +188,7 @@ pub async fn run_server(config: Config) -> anyhow::Result<()> { .nest("/enrollment", enrollment::router()) .nest("/password-reset", password_reset::router()) .nest("/client-mfa", desktop_client_mfa::router()) + .route("/poll", post(polling::info)) .route("/health", get(healthcheck)) .route("/health-grpc", get(healthcheckgrpc)) .route("/info", get(app_info)), diff --git a/web/vite.config.ts b/web/vite.config.ts index ee11a88..2504172 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -8,7 +8,7 @@ export default defineConfig({ plugins: [react()], server: { strictPort: true, - port: 3000, + port: 3002, proxy: { '/api': { target: 'http://127.0.0.1:8080/',