From 76dcc305f39d0a1ce884ac4e388e53d855917a5e Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Mon, 21 Dec 2015 22:16:29 -0500 Subject: [PATCH] Add expiring token lifetime --- src/token/expiring.rs | 23 +++++++++++++++++++++++ src/token/mod.rs | 5 ++++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/token/expiring.rs diff --git a/src/token/expiring.rs b/src/token/expiring.rs new file mode 100644 index 0000000..4c2ae45 --- /dev/null +++ b/src/token/expiring.rs @@ -0,0 +1,23 @@ +use chrono::{DateTime, UTC}; + +use super::Lifetime; + +/// An expiring token. +pub struct Expiring { + refresh_token: String, + expires: DateTime, +} + +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 { &self.expires } +} + +impl Lifetime for Expiring { + fn expired(&self) -> bool { self.expires < UTC::now() } +} diff --git a/src/token/mod.rs b/src/token/mod.rs index fe89d50..5952333 100644 --- a/src/token/mod.rs +++ b/src/token/mod.rs @@ -23,7 +23,7 @@ pub trait Token { /// OAuth 2.0 token lifetimes. 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; } @@ -32,3 +32,6 @@ mod bearer; pub use self::statik::Static; mod statik; + +pub use self::expiring::Expiring; +mod expiring;