graph_core/identity/
jwks.rs1use jsonwebtoken::TokenData;
2use serde_json::Value;
3use std::collections::{HashMap, HashSet};
4use std::fmt::{Display, Formatter};
5
6#[derive(Clone, Default, Debug, Eq, PartialEq, Serialize, Deserialize)]
7pub struct JwksKeySet {
8 pub keys: HashSet<JwksKey>,
9}
10
11#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Hash)]
12pub struct JwksKey {
13 pub kid: String,
14 #[serde(alias = "n")]
15 pub modulus: String,
16 #[serde(alias = "e")]
17 pub exponent: String,
18}
19
20impl JwksKey {
21 pub fn new(kid: impl ToString, modulus: impl ToString, exponent: impl ToString) -> JwksKey {
22 JwksKey {
23 kid: kid.to_string(),
24 modulus: modulus.to_string(),
25 exponent: exponent.to_string(),
26 }
27 }
28}
29
30#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
31pub struct JwtHeader {
32 pub typ: String,
33 pub alg: String,
34 pub kid: String,
35 pub x5t: Option<String>,
36}
37
38impl Display for JwtHeader {
39 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
40 write!(
41 f,
42 "typ: {}, alg: {}, kid: {}, x5t: {:#?}",
43 self.typ, self.alg, self.kid, self.x5t
44 )
45 }
46}
47
48pub type DecodedJwt = TokenData<Claims>;
49
50#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
51pub struct Claims {
52 pub aud: String,
53 pub iss: String,
54 pub iat: usize,
55 pub nbf: usize,
56 pub exp: usize,
57 pub aio: Option<String>,
58 pub c_hash: Option<String>,
59 pub cc: Option<String>,
60 pub email: Option<String>,
61 pub name: Option<String>,
62 pub nonce: Option<String>,
63 pub oid: Option<String>,
64 pub preferred_username: Option<String>,
65 pub rh: Option<String>,
66 pub sub: Option<String>,
67 pub tid: Option<String>,
68 pub uti: Option<String>,
69 pub ver: Option<String>,
70 #[serde(flatten)]
71 pub additional_fields: HashMap<String, Value>,
72}