|
1 |
| -use napi_derive::napi; |
2 |
| -use serde::{Deserialize, Serialize}; |
3 |
| -use serde_json::{Map, Number, Value}; |
| 1 | +use indexmap::IndexMap; |
| 2 | +use serde_json::Value; |
4 | 3 |
|
5 |
| -#[napi(object)] |
6 |
| -#[derive(Debug, Serialize, Deserialize)] |
7 |
| -pub struct Claims { |
8 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
9 |
| - pub data: Option<Map<String, Value>>, |
10 |
| - // Recipient for which the JWT is intended |
11 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
12 |
| - pub aud: Option<String>, |
13 |
| - // Time after which the JWT expires (as UTC timestamp, seconds from epoch time) |
14 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
15 |
| - pub exp: Option<Number>, |
16 |
| - // Time at which the JWT was issued (as UTC timestamp, seconds from epoch time) |
17 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
18 |
| - pub iat: Option<Number>, |
19 |
| - // Issuer of JWT |
20 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
21 |
| - pub iss: Option<String>, |
22 |
| - // [JWT id] Unique identifier |
23 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
24 |
| - pub jti: Option<String>, |
25 |
| - // [not-before-time] Time before which the JWT must not be accepted for processing (as UTC timestamp, seconds from epoch time) |
26 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
27 |
| - pub nbf: Option<Number>, |
28 |
| - // Subject of JWT (the user) |
29 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
30 |
| - pub sub: Option<String>, |
31 |
| -} |
32 |
| - |
33 |
| -impl Claims { |
34 |
| - #[inline] |
35 |
| - pub fn merge(self, other: Self) -> Self { |
36 |
| - Self { |
37 |
| - data: self.data, |
38 |
| - aud: self.aud.or(other.aud), |
39 |
| - exp: self.exp.or(other.exp), |
40 |
| - iat: self.iat.or(other.iat), |
41 |
| - iss: self.iss.or(other.iss), |
42 |
| - jti: self.jti.or(other.jti), |
43 |
| - nbf: self.nbf.or(other.nbf), |
44 |
| - sub: self.sub.or(other.sub), |
45 |
| - } |
46 |
| - } |
47 |
| -} |
48 |
| - |
49 |
| -impl Default for Claims { |
50 |
| - #[inline] |
51 |
| - fn default() -> Self { |
52 |
| - Self { |
53 |
| - data: Some(Map::new()), |
54 |
| - aud: None, |
55 |
| - exp: None, |
56 |
| - iat: Some(jsonwebtoken::get_current_timestamp().into()), |
57 |
| - iss: None, |
58 |
| - jti: None, |
59 |
| - nbf: None, |
60 |
| - sub: None, |
61 |
| - } |
62 |
| - } |
63 |
| -} |
| 4 | +pub type Claims = IndexMap<String, Value>; |
0 commit comments