From 37b212427c80a1c56db748510ebe6dee4d218b4a Mon Sep 17 00:00:00 2001 From: BlackDex Date: Mon, 16 Mar 2020 16:38:00 +0100 Subject: [PATCH] Updated jsonwebtoken Updated to the latest version of jsonwebtoken. Some small code changes to match the new versions. --- src/api/admin.rs | 2 +- src/auth.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/admin.rs b/src/api/admin.rs index 54dbdf95..23bc65fe 100644 --- a/src/api/admin.rs +++ b/src/api/admin.rs @@ -91,7 +91,7 @@ fn post_admin_login(data: Form, mut cookies: Cookies, ip: ClientIp) - let cookie = Cookie::build(COOKIE_NAME, jwt) .path(admin_path()) - .max_age(chrono::Duration::minutes(20)) + .max_age(time::Duration::minutes(20)) .same_site(SameSite::Strict) .http_only(true) .finish(); diff --git a/src/auth.rs b/src/auth.rs index 425524fd..f5aeaa1e 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -6,7 +6,7 @@ use chrono::{Duration, Utc}; use once_cell::sync::Lazy; use num_traits::FromPrimitive; -use jsonwebtoken::{self, Algorithm, Header}; +use jsonwebtoken::{self, Algorithm, Header, EncodingKey, DecodingKey}; use serde::de::DeserializeOwned; use serde::ser::Serialize; @@ -32,7 +32,7 @@ static PUBLIC_RSA_KEY: Lazy> = Lazy::new(|| match read_file(&CONFIG.publ }); pub fn encode_jwt(claims: &T) -> String { - match jsonwebtoken::encode(&JWT_HEADER, claims, &PRIVATE_RSA_KEY) { + match jsonwebtoken::encode(&JWT_HEADER, claims, &EncodingKey::from_rsa_der(&PRIVATE_RSA_KEY)) { Ok(token) => token, Err(e) => panic!("Error encoding jwt {}", e), } @@ -51,7 +51,7 @@ fn decode_jwt(token: &str, issuer: String) -> Result