inth_oauth2/token/
statik.rs1use serde_json::Value;
2
3use client::response::{FromResponse, ParseError};
4use token::Lifetime;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8pub struct Static;
9
10impl Lifetime for Static {
11 fn expired(&self) -> bool { false }
12}
13
14impl FromResponse for Static {
15 fn from_response(json: &Value) -> Result<Self, ParseError> {
16 let obj = json.as_object().ok_or(ParseError::ExpectedType("object"))?;
17 if obj.contains_key("expires_in") {
18 return Err(ParseError::UnexpectedField("expires_in"));
19 }
20 Ok(Static)
21 }
22}
23
24#[cfg(test)]
25mod tests {
26 use client::response::{FromResponse, ParseError};
27 use super::Static;
28
29 #[test]
30 fn from_response() {
31 let json = "{}".parse().unwrap();
32 assert_eq!(Static, Static::from_response(&json).unwrap());
33 }
34
35 #[test]
36 fn from_response_with_expires_in() {
37 let json = r#"{"expires_in":3600}"#.parse().unwrap();
38 assert_eq!(
39 ParseError::UnexpectedField("expires_in"),
40 Static::from_response(&json).unwrap_err()
41 );
42 }
43}