2015-11-28 18:09:43 +00:00
|
|
|
use chrono::{DateTime, UTC};
|
|
|
|
|
|
|
|
/// OAuth 2.0 access token.
|
2015-11-29 04:33:58 +00:00
|
|
|
///
|
|
|
|
/// See [RFC6749 section 5](http://tools.ietf.org/html/rfc6749#section-5).
|
2015-11-29 04:38:59 +00:00
|
|
|
#[derive(Debug, Clone)]
|
2015-11-28 18:09:43 +00:00
|
|
|
pub struct Token {
|
2015-11-29 04:33:58 +00:00
|
|
|
/// The access token issued by the authorization server.
|
2015-11-28 18:09:43 +00:00
|
|
|
pub access_token: String,
|
2015-11-29 04:33:58 +00:00
|
|
|
|
|
|
|
/// The type of the token issued.
|
|
|
|
///
|
|
|
|
/// See [RFC6749 section 7.1](http://tools.ietf.org/html/rfc6749#section-7.1).
|
2015-11-28 18:09:43 +00:00
|
|
|
pub token_type: String,
|
2015-11-29 04:33:58 +00:00
|
|
|
|
|
|
|
/// The expiry time of the access token.
|
2015-11-28 18:09:43 +00:00
|
|
|
pub expires: Option<DateTime<UTC>>,
|
2015-11-29 04:33:58 +00:00
|
|
|
|
|
|
|
/// The refresh token, which can be used to obtain new access tokens.
|
2015-11-28 18:09:43 +00:00
|
|
|
pub refresh_token: Option<String>,
|
2015-11-29 04:33:58 +00:00
|
|
|
|
|
|
|
/// The scope of the access token.
|
2015-11-28 18:09:43 +00:00
|
|
|
pub scope: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Token {
|
|
|
|
/// Returns true if token is expired.
|
|
|
|
pub fn expired(&self) -> bool {
|
|
|
|
self.expires.map_or(false, |dt| dt < UTC::now())
|
|
|
|
}
|
|
|
|
}
|