From e1c123c4e39345c3d677c9764bfeeb40c13b3ce3 Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Tue, 3 Aug 2021 13:57:24 -0600 Subject: [PATCH] add cookie expiration --- appmgr/src/auth.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/appmgr/src/auth.rs b/appmgr/src/auth.rs index dba5167c5..27ed089f4 100644 --- a/appmgr/src/auth.rs +++ b/appmgr/src/auth.rs @@ -26,6 +26,19 @@ pub fn parse_metadata(_: &str, _: &ArgMatches<'_>) -> Result { })) } +#[test] +fn gen_pwd() { + println!( + "{:?}", + argon2::hash_encoded( + b"testing1234", + &rand::random::<[u8; 16]>()[..], + &argon2::Config::default() + ) + .unwrap() + ) +} + #[command(display(display_none), metadata(authenticated = false))] pub async fn login( #[context] ctx: EitherContext, @@ -69,8 +82,11 @@ pub async fn login( .await?; res.headers.insert( "set-cookie", - HeaderValue::from_str(&format!("session={}; HttpOnly; SameSite=Strict", token)) - .with_kind(crate::ErrorKind::Unknown)?, // Should be impossible, but don't want to panic + HeaderValue::from_str(&format!( + "session={}; HttpOnly; SameSite=Strict; Expires=Fri, 31 Dec 9999 23:59:59 GMT;", + token + )) + .with_kind(crate::ErrorKind::Unknown)?, // Should be impossible, but don't want to panic ); Ok(())