inth_oauth2_async/token/
mod.rs

1//! Tokens.
2//!
3//! Access token types are abstracted through the `Token` trait. See
4//! [RFC 6749, section 7.1](http://tools.ietf.org/html/rfc6749#section-7.1).
5//!
6//! Expiring and non-expiring tokens are abstracted through the `Lifetime` trait.
7
8mod bearer;
9mod expiring;
10mod refresh;
11mod statik;
12
13pub use self::bearer::Bearer;
14pub use self::expiring::Expiring;
15pub use self::refresh::Refresh;
16pub use self::statik::Static;
17
18use crate::client::response::FromResponse;
19
20/// OAuth 2.0 tokens.
21///
22/// See [RFC 6749, section 5](http://tools.ietf.org/html/rfc6749#section-5).
23pub trait Token<L: Lifetime>: FromResponse {
24    /// Returns the access token.
25    ///
26    /// See [RF C6749, section 1.4](http://tools.ietf.org/html/rfc6749#section-1.4).
27    fn access_token(&self) -> &str;
28
29    /// Returns the scope, if available.
30    fn scope(&self) -> Option<&str>;
31
32    /// Returns the ID token, if available. Returned by Google providers in some cases.
33    fn id_token(&self) -> Option<&str>;
34
35    /// Returns the token lifetime.
36    fn lifetime(&self) -> &L;
37}
38
39/// OAuth 2.0 token lifetimes.
40pub trait Lifetime: FromResponse {
41    /// Returns true if the access token is no longer valid.
42    fn expired(&self) -> bool;
43}