diff --git a/Cargo.toml b/Cargo.toml index c7878be..58f715f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,6 @@ keywords = ["authentication", "authorization", "auth", "oauth"] authors = ["Curtis McEnroe "] license = "ISC" -documentation = "https://cmcenroe.me/inth-oauth2/inth_oauth2" repository = "https://github.com/programble/inth-oauth2" readme = "README.md" diff --git a/src/client/error.rs b/src/client/error.rs index c8ae57c..a2356c2 100644 --- a/src/client/error.rs +++ b/src/client/error.rs @@ -13,14 +13,19 @@ use error::OAuth2Error; pub enum ClientError { /// IO error. Io(io::Error), + /// URL error. Url(url::ParseError), + /// Hyper error. Hyper(hyper::Error), + /// JSON error. Json(serde_json::Error), + /// Response parse error. Parse(ParseError), + /// OAuth 2.0 error. OAuth2(OAuth2Error), } diff --git a/src/client/mod.rs b/src/client/mod.rs index 0a9764b..e6efdf3 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -1,5 +1,10 @@ //! Client. +mod error; + +pub mod response; +pub use self::error::ClientError; + use std::marker::PhantomData; use hyper::{self, header, mime}; @@ -7,16 +12,11 @@ use serde_json::{self, Value}; use url::Url; use url::form_urlencoded::Serializer; +use client::response::FromResponse; use error::OAuth2Error; use provider::Provider; use token::{Token, Lifetime, Refresh}; -use self::response::FromResponse; -pub mod response; - -pub use self::error::ClientError; -mod error; - /// OAuth 2.0 client. #[derive(Debug, Clone, PartialEq, Eq)] pub struct Client { @@ -79,7 +79,7 @@ impl Client

{ /// ``` pub fn auth_uri(&self, scope: Option<&str>, state: Option<&str>) -> Result { - let mut uri = try!(Url::parse(P::auth_uri())); + let mut uri = Url::parse(P::auth_uri())?; { let mut query = uri.query_pairs_mut(); @@ -128,7 +128,7 @@ impl Client

{ .header(header::ContentType::form_url_encoded()) .body(&body); - let mut response = try!(request.send()); + let mut response = request.send()?; let json = serde_json::from_reader(&mut response)?; let error = OAuth2Error::from_response(&json); @@ -156,8 +156,8 @@ impl Client

{ body.append_pair("redirect_uri", redirect_uri); } - let json = try!(self.post_token(http_client, body)); - let token = try!(P::Token::from_response(&json)); + let json = self.post_token(http_client, body)?; + let token = P::Token::from_response(&json)?; Ok(token) } } @@ -180,8 +180,8 @@ impl Client

where P::Token: Token { body.append_pair("scope", scope); } - let json = try!(self.post_token(http_client, body)); - let token = try!(P::Token::from_response_inherit(&json, &token)); + let json = self.post_token(http_client, body)?; + let token = P::Token::from_response_inherit(&json, &token)?; Ok(token) } diff --git a/src/error.rs b/src/error.rs index f3427e1..8556a78 100644 --- a/src/error.rs +++ b/src/error.rs @@ -71,12 +71,12 @@ pub struct OAuth2Error { impl fmt::Display for OAuth2Error { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - try!(write!(f, "{:?}", self.code)); + write!(f, "{:?}", self.code)?; if let Some(ref description) = self.description { - try!(write!(f, ": {}", description)); + write!(f, ": {}", description)?; } if let Some(ref uri) = self.uri { - try!(write!(f, " ({})", uri)); + write!(f, " ({})", uri)?; } Ok(()) } diff --git a/src/token/bearer.rs b/src/token/bearer.rs index 1d7e102..efbb8b1 100644 --- a/src/token/bearer.rs +++ b/src/token/bearer.rs @@ -1,8 +1,8 @@ use hyper::header; use serde_json::Value; -use super::{Token, Lifetime}; use client::response::{FromResponse, ParseError}; +use token::{Token, Lifetime}; /// The bearer token type. /// diff --git a/src/token/expiring.rs b/src/token/expiring.rs index 054b991..28e5edc 100644 --- a/src/token/expiring.rs +++ b/src/token/expiring.rs @@ -1,8 +1,8 @@ use chrono::{DateTime, UTC, Duration}; use serde_json::Value; -use super::Lifetime; use client::response::{FromResponse, ParseError}; +use token::Lifetime; /// An expiring token. #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] diff --git a/src/token/mod.rs b/src/token/mod.rs index 94f953d..c003045 100644 --- a/src/token/mod.rs +++ b/src/token/mod.rs @@ -5,6 +5,16 @@ //! //! Expiring and non-expiring tokens are abstracted through the `Lifetime` trait. +mod bearer; +mod expiring; +mod refresh; +mod statik; + +pub use self::bearer::Bearer; +pub use self::expiring::Expiring; +pub use self::refresh::Refresh; +pub use self::statik::Static; + use client::response::FromResponse; /// OAuth 2.0 tokens. @@ -28,13 +38,3 @@ pub trait Lifetime: FromResponse { /// Returns true if the access token is no longer valid. fn expired(&self) -> bool; } - -mod bearer; -mod expiring; -mod refresh; -mod statik; - -pub use self::bearer::Bearer; -pub use self::expiring::Expiring; -pub use self::refresh::Refresh; -pub use self::statik::Static; diff --git a/src/token/refresh.rs b/src/token/refresh.rs index 503d1ed..8698ef7 100644 --- a/src/token/refresh.rs +++ b/src/token/refresh.rs @@ -1,8 +1,8 @@ use chrono::{DateTime, UTC, Duration}; use serde_json::Value; -use super::Lifetime; use client::response::{FromResponse, ParseError}; +use token::Lifetime; /// An expiring token which can be refreshed. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/src/token/statik.rs b/src/token/statik.rs index 64e9a98..86164e7 100644 --- a/src/token/statik.rs +++ b/src/token/statik.rs @@ -1,7 +1,7 @@ use serde_json::Value; -use super::Lifetime; use client::response::{FromResponse, ParseError}; +use token::Lifetime; /// A static, non-expiring token. #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]