mirror of
https://github.com/sadoyan/aralez.git
synced 2026-04-30 06:48:37 +08:00
17 lines
519 B
Rust
17 lines
519 B
Rust
use jsonwebtoken::{decode, Algorithm, DecodingKey, Validation};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
pub(crate) struct Claims {
|
|
pub(crate) user: String,
|
|
pub(crate) exp: u64,
|
|
}
|
|
pub fn check_jwt(input: &str, secret: &str) -> bool {
|
|
let validation = Validation::new(Algorithm::HS256);
|
|
let token_data = decode::<Claims>(&input, &DecodingKey::from_secret(secret.as_ref()), &validation);
|
|
match token_data {
|
|
Ok(_) => true,
|
|
Err(_) => false,
|
|
}
|
|
}
|