1 use crate::settings::structs::Settings;
3 use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, TokenData, Validation};
4 use serde::{Deserialize, Serialize};
8 #[derive(Debug, Serialize, Deserialize)]
10 /// local_user_id, standard claim by RFC 7519.
13 /// Time when this token was issued as UNIX-timestamp in seconds
18 pub fn decode(jwt: &str) -> Result<TokenData<Claims>, jsonwebtoken::errors::Error> {
21 ..Validation::default()
25 &DecodingKey::from_secret(Settings::get().jwt_secret.as_ref()),
30 pub fn jwt(local_user_id: i32) -> Result<Jwt, jsonwebtoken::errors::Error> {
31 let my_claims = Claims {
33 iss: Settings::get().hostname,
34 iat: Utc::now().timestamp(),
39 &EncodingKey::from_secret(Settings::get().jwt_secret.as_ref()),