diff --git a/src/main.rs b/src/main.rs index 3a6926a..71b2152 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,8 +31,12 @@ struct ConfigArgs { #[arg(short, long, default_value = "127.0.0.1:26656")] bind_addr: String, - /// Access tokens lifetime, in seconds + /// How long an access token stays valid, in seconds #[arg(long, default_value_t = 3600)] + token_duration: u32, + + /// How long an access token is refreshable, in hours + #[arg(long, default_value_t = 168)] token_lifetime: u32, /// Valid time for join requests, in seconds @@ -76,7 +80,7 @@ async fn main() -> Result<(), Box> { let db = Database::connect(cfg.database.clone()).await?; - purge_expired_tokens(&db, Duration::seconds(cfg.token_lifetime.into())).await?; + purge_expired_tokens(&db, Duration::hours(cfg.token_lifetime.into())).await?; let secret = load_secret(&db).await?; diff --git a/src/routes/auth.rs b/src/routes/auth.rs index e3c7129..6242143 100644 --- a/src/routes/auth.rs +++ b/src/routes/auth.rs @@ -14,7 +14,7 @@ pub async fn validate(State(state): State, Json(payload): Json Duration::seconds(state.cfg.token_lifetime as i64) { + if Utc::now() - t.created_at > Duration::seconds(state.cfg.token_duration as i64) { warn!(target: "AUTH", "[VALIDATE] expired token!"); return Err(StatusCode::UNAUTHORIZED); } diff --git a/src/routes/session.rs b/src/routes/session.rs index 02a3464..355af00 100644 --- a/src/routes/session.rs +++ b/src/routes/session.rs @@ -24,7 +24,7 @@ pub async fn join(State(state): State, Json(payload): Json