Add expiring token lifetime

This commit is contained in:
Curtis McEnroe 2015-12-21 22:16:29 -05:00
parent 397578840d
commit 76dcc305f3
2 changed files with 27 additions and 1 deletions

23
src/token/expiring.rs Normal file
View File

@ -0,0 +1,23 @@
use chrono::{DateTime, UTC};
use super::Lifetime;
/// An expiring token.
pub struct Expiring {
refresh_token: String,
expires: DateTime<UTC>,
}
impl Expiring {
/// Returns the refresh token.
///
/// See [RFC 6749, section 1.5](http://tools.ietf.org/html/rfc6749#section-1.5).
pub fn refresh_token(&self) -> &str { &self.refresh_token }
/// Returns the expiry time of the access token.
pub fn expires(&self) -> &DateTime<UTC> { &self.expires }
}
impl Lifetime for Expiring {
fn expired(&self) -> bool { self.expires < UTC::now() }
}

View File

@ -23,7 +23,7 @@ pub trait Token<L: Lifetime> {
/// OAuth 2.0 token lifetimes. /// OAuth 2.0 token lifetimes.
pub trait Lifetime { pub trait Lifetime {
/// Returns true if the token is no longer valid. /// Returns true if the access token is no longer valid.
fn expired(&self) -> bool; fn expired(&self) -> bool;
} }
@ -32,3 +32,6 @@ mod bearer;
pub use self::statik::Static; pub use self::statik::Static;
mod statik; mod statik;
pub use self::expiring::Expiring;
mod expiring;