From 0408dc8593c531d5f1b0e1310fbc14edfdd74349 Mon Sep 17 00:00:00 2001 From: alemi Date: Mon, 6 Mar 2023 18:52:47 +0100 Subject: [PATCH] feat: make sure tokens are not expired token lifetime is configured per-session serverside --- src/main.rs | 4 ++++ src/routes/auth.rs | 7 ++++++- src/routes/session.rs | 5 ++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index ed9a102..489ff55 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,6 +31,10 @@ struct ConfigArgs { #[arg(short, long, default_value = "127.0.0.1:26656")] bind_addr: String, + /// Access tokens lifetime, in seconds + #[arg(long, default_value_t = 3600)] + token_lifetime: u32, + /// Valid time for join requests, in seconds #[arg(short, long, default_value_t = 10)] time_window: u32, diff --git a/src/routes/auth.rs b/src/routes/auth.rs index 7922c39..27f4aea 100644 --- a/src/routes/auth.rs +++ b/src/routes/auth.rs @@ -13,7 +13,12 @@ pub async fn validate(State(state): State, Json(payload): Json Duration::seconds(state.cfg.token_lifetime as i64) { + warn!(target: "AUTH", "[VALIDATE] expired token!"); + return Err(StatusCode::UNAUTHORIZED); + } + Ok(StatusCode::NO_CONTENT) } else { warn!(target: "AUTH", "[VALIDATE] invalid token!"); diff --git a/src/routes/session.rs b/src/routes/session.rs index 3d5342f..02a3464 100644 --- a/src/routes/session.rs +++ b/src/routes/session.rs @@ -22,7 +22,10 @@ pub async fn join(State(state): State, Json(payload): Json