1 use crate::settings::Settings;
2 use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, TokenData, Validation};
3 use serde::{Deserialize, Serialize};
7 #[derive(Debug, Serialize, Deserialize)]
9 /// User id, for backward compatibility with client apps.
10 /// Claim [sub](Claims::sub) is used in server-side checks.
12 /// User id, standard claim by RFC 7519.
15 /// Time when this token was issued as UNIX-timestamp in seconds
20 pub fn decode(jwt: &str) -> Result<TokenData<Claims>, jsonwebtoken::errors::Error> {
23 ..Validation::default()
27 &DecodingKey::from_secret(Settings::get().jwt_secret.as_ref()),
32 pub fn jwt(user_id: i32, hostname: String) -> Result<Jwt, jsonwebtoken::errors::Error> {
33 let my_claims = Claims {
37 iat: chrono::Utc::now().timestamp_millis() / 1000,
42 &EncodingKey::from_secret(Settings::get().jwt_secret.as_ref()),