fix(iam): keep service account JWT expiry consistent (#2410)

This commit is contained in:
weisd
2026-04-07 11:00:07 +08:00
committed by GitHub
parent 97b06afd6c
commit 898857d1c9
5 changed files with 221 additions and 23 deletions
+11
View File
@@ -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};