1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use std::time::Duration;

use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};

#[derive(Debug)]
pub struct JwkConfiguration {
    pub jwk_url: String,
    pub audience: String,
    pub issuer: String,
}

#[derive(Debug, Deserialize)]
pub struct KeyResponse {
    pub keys: Vec<JwkKey>,
}

#[derive(Clone, Debug, Deserialize)]
pub struct JwkKey {
    pub e: String,
    pub alg: String,
    pub kty: String,
    pub kid: String,
    pub n: String,
}

/// The Jwt claims decoded from the user token. Can also be viewed as the Firebase User
/// information.
#[derive(Serialize, Deserialize)]
pub struct FirebaseUser {
    pub provider_id: Option<String>,
    pub name: Option<String>,
    pub picture: Option<String>,
    pub iss: String,
    pub aud: String,
    pub auth_time: u64,
    pub user_id: String,
    pub sub: String,
    pub iat: u64,
    pub exp: u64,
    pub email: Option<String>,
    pub email_verified: Option<bool>,
    pub firebase: FirebaseProvider,
}

#[derive(Serialize, Deserialize)]
pub struct FirebaseProvider {
    sign_in_provider: String,
    identities: Map<String, Value>,
}

#[derive(Debug, Clone)]
pub struct JwkKeys {
    pub keys: Vec<JwkKey>,
    pub max_age: Duration,
}

#[derive(Debug)]
pub enum PublicKeysError {
    NoCacheControlHeader,
    MaxAgeValueEmpty,
    NonNumericMaxAge,
    NoMaxAgeSpecified,
    CannotParsePublicKey,
}