jwt_service/struct.rs
1use super::*;
2
3/// JWT configuration struct containing secret key, expiration time, and issuer.
4#[derive(Clone, Debug, Default)]
5pub struct JwtConfig {
6 /// The secret key used for signing JWT tokens.
7 pub(super) secret: String,
8 /// Token expiration time in seconds.
9 pub(super) expiration_seconds: u64,
10 /// The issuer of the JWT token.
11 pub(super) issuer: String,
12}
13
14/// Standard JWT claims struct with common fields.
15#[derive(Clone, Debug, Default, Deserialize, Serialize)]
16pub struct JwtExtraJwtClaims {
17 /// The subject (user identifier) of the token.
18 pub(super) sub: String,
19 /// The issuer of the token.
20 pub(super) iss: String,
21 /// Expiration time as a Unix timestamp.
22 pub(super) exp: usize,
23 /// Issued at time as a Unix timestamp.
24 pub(super) iat: usize,
25 /// Not before time as a Unix timestamp.
26 pub(super) nbf: usize,
27}
28
29/// JWT token response struct containing the token and metadata.
30#[derive(Clone, Debug, Default)]
31pub struct JwtToken {
32 /// The encoded JWT token string.
33 pub(super) token: String,
34 /// The token type (typically "Bearer").
35 pub(super) token_type: String,
36 /// Token expiration time in seconds.
37 pub(super) expires_in: u64,
38}
39
40/// JWT service struct providing token generation and validation functionality.
41#[derive(Clone, Debug)]
42pub struct JwtService {
43 /// The JWT configuration.
44 pub(super) config: JwtConfig,
45 /// The encoding key for signing tokens.
46 pub(super) encoding_key: EncodingKey,
47 /// The decoding key for verifying tokens.
48 pub(super) decoding_key: DecodingKey,
49 /// The validation settings for token verification.
50 pub(super) validation: Validation,
51}
52
53/// Generic JWT claims struct that supports custom payload data.
54#[derive(Clone, Debug, Default, Deserialize, Serialize)]
55pub struct CustomExtraJwtClaims<T: Default> {
56 /// The custom payload data.
57 #[serde(flatten)]
58 pub(super) custom: T,
59 /// The subject (user identifier) of the token.
60 pub(super) sub: String,
61 /// The issuer of the token.
62 pub(super) iss: String,
63 /// Expiration time as a Unix timestamp.
64 pub(super) exp: usize,
65 /// Issued at time as a Unix timestamp.
66 pub(super) iat: usize,
67}
68
69/// Extended JWT claims struct with support for custom extra fields.
70#[derive(Clone, Debug, Default, Deserialize, Serialize)]
71pub struct ExtraJwtClaims {
72 /// The subject (user identifier) of the token.
73 pub(super) sub: String,
74 /// The issuer of the token.
75 pub(super) iss: String,
76 /// Expiration time as a Unix timestamp.
77 pub(super) exp: usize,
78 /// Issued at time as a Unix timestamp.
79 pub(super) iat: usize,
80 /// Additional custom claims.
81 #[serde(flatten)]
82 pub(super) extra: HashMap<String, Value>,
83}