Add expiring token lifetime
This commit is contained in:
parent
397578840d
commit
76dcc305f3
|
@ -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() }
|
||||
}
|
|
@ -23,7 +23,7 @@ pub trait Token<L: Lifetime> {
|
|||
|
||||
/// 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;
|
||||
|
|
Loading…
Reference in New Issue