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
use client::Client;
use error::Error;
#[derive(Debug, Deserialize)]
pub struct IdInfo {
pub iss: String,
pub sub: String,
pub azp: String,
pub aud: String,
pub iat: String,
pub exp: String,
pub hd: Option<String>,
pub email: Option<String>,
pub email_verified: Option<String>,
pub name: Option<String>,
pub picture: Option<String>,
pub given_name: Option<String>,
pub family_name: Option<String>,
pub locale: Option<String>,
}
impl IdInfo {
pub fn verify(&self, client: &Client) -> Result<(), Error> {
match self.iss.as_str() {
"accounts.google.com" | "https://accounts.google.com" => {}
_ => { return Err(Error::InvalidIssuer); }
}
if client.audiences.len() > 0 && !client.audiences.contains(&self.aud) {
return Err(Error::InvalidAudience);
}
if client.hosted_domains.len() > 0 {
match self.hd {
Some(ref domain) if client.hosted_domains.contains(domain) => {}
_ => { return Err(Error::InvalidHostedDomain); }
}
}
Ok(())
}
}