mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-27 15:37:02 +00:00
fix(iam): keep service account JWT expiry consistent (#2410)
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
use jsonwebtoken::{Algorithm, DecodingKey, EncodingKey, Header};
|
||||
use rand::{Rng, RngExt};
|
||||
use serde::{Serialize, de::DeserializeOwned};
|
||||
use std::collections::HashSet;
|
||||
use std::io::{Error, Result};
|
||||
|
||||
/// Generates a random access key of the specified length.
|
||||
@@ -98,6 +99,16 @@ pub fn extract_claims<T: DeserializeOwned + Clone>(
|
||||
)
|
||||
}
|
||||
|
||||
pub fn extract_claims_allow_missing_exp<T: DeserializeOwned + Clone>(
|
||||
token: &str,
|
||||
secret: &str,
|
||||
) -> std::result::Result<jsonwebtoken::TokenData<T>, jsonwebtoken::errors::Error> {
|
||||
let mut validation = jsonwebtoken::Validation::new(Algorithm::HS512);
|
||||
validation.required_spec_claims = HashSet::new();
|
||||
|
||||
jsonwebtoken::decode::<T>(token, &DecodingKey::from_secret(secret.as_bytes()), &validation)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{extract_claims, gen_access_key, gen_secret_key, generate_jwt};
|
||||
|
||||
Reference in New Issue
Block a user