vw_small

Hardened fork of Vaultwarden (https://github.com/dani-garcia/vaultwarden) with fewer features.
git clone https://git.philomathiclife.com/repos/vw_small
Log | Files | Refs | README

commit 55030f3687cb0ddb708efed7fcbd5f4740fb5171
parent dfd63f85c07dd2e31bac13f26d453774b8bd2c53
Author: Daniel GarcĂ­a <dani-garcia@users.noreply.github.com>
Date:   Sun,  9 Oct 2022 16:22:33 +0200

Merge branch 'stefan0xC-return-token-expired-message'

Diffstat:
Msrc/auth.rs | 18+++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/auth.rs b/src/auth.rs @@ -1,18 +1,14 @@ -// // JWT Handling // use chrono::{Duration, Utc}; use num_traits::FromPrimitive; use once_cell::sync::Lazy; -use jsonwebtoken::{self, Algorithm, DecodingKey, EncodingKey, Header}; +use jsonwebtoken::{self, errors::ErrorKind, Algorithm, DecodingKey, EncodingKey, Header}; use serde::de::DeserializeOwned; use serde::ser::Serialize; -use crate::{ - error::{Error, MapResult}, - CONFIG, -}; +use crate::{error::Error, CONFIG}; const JWT_ALGORITHM: Algorithm = Algorithm::RS256; @@ -61,7 +57,15 @@ fn decode_jwt<T: DeserializeOwned>(token: &str, issuer: String) -> Result<T, Err validation.set_issuer(&[issuer]); let token = token.replace(char::is_whitespace, ""); - jsonwebtoken::decode(&token, &PUBLIC_RSA_KEY, &validation).map(|d| d.claims).map_res("Error decoding JWT") + match jsonwebtoken::decode(&token, &PUBLIC_RSA_KEY, &validation) { + Ok(d) => Ok(d.claims), + Err(err) => match *err.kind() { + ErrorKind::InvalidToken => err!("Token is invalid"), + ErrorKind::InvalidIssuer => err!("Issuer is invalid"), + ErrorKind::ExpiredSignature => err!("Token has expired"), + _ => err!("Error decoding JWT"), + }, + } } pub fn decode_login(token: &str) -> Result<LoginJwtClaims, Error> {