diff options
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -127,23 +127,28 @@ After a successful authentication you can build a session id cookie for example as follows: ```rust -let expiry_date = OffsetDateTime::now_utc() + Duration::hours(24); +let expiry_date = SystemTime::now() + Duration::from_secs(24 * 60 * 60); let mut cookie = Cookie::new("userid", key.sign( &encode_expiring_claim(&userid, expiry_date) )); -cookie.set_secure(Some(true)); -cookie.set_expires(expiry_date); -cookie.set_same_site(SameSite::Lax); -headers.set_cookie(cookie); +headers.set_cookie(Cookie{ + name: "userid".into(), + value: key.sign( + &encode_expiring_claim(&userid, expiry_date) + ), + secure: Some(true), + expires: Some(expiry_date), + same_site: SameSite::Lax, +}); ``` This session id cookie can then be retrieved and verified as follows: ```rust -let userid = req.cookies().get("userid") +let userid = req.cookies().find(|(name, _value)| *name == "userid") .ok_or_else(|| "expected userid cookie".to_owned()) - .and_then(|cookie| key.verify(cookie.value()) + .and_then(|(_name, value)| key.verify(value)) .and_then(|value| decode_expiring_claim(value).map_err(|e| format!("failed to decode userid cookie: {}", e))); ``` |