Style cleanup

This commit is contained in:
Curtis McEnroe 2017-06-04 20:22:29 -04:00
parent f3906e71d0
commit 80a7a02050
No known key found for this signature in database
GPG Key ID: CEA2F97ADCFCD77C
9 changed files with 34 additions and 30 deletions

View File

@ -8,7 +8,6 @@ keywords = ["authentication", "authorization", "auth", "oauth"]
authors = ["Curtis McEnroe <programble@gmail.com>"]
license = "ISC"
documentation = "https://cmcenroe.me/inth-oauth2/inth_oauth2"
repository = "https://github.com/programble/inth-oauth2"
readme = "README.md"

View File

@ -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),
}

View File

@ -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<P: Provider> {
@ -79,7 +79,7 @@ impl<P: Provider> Client<P> {
/// ```
pub fn auth_uri(&self, scope: Option<&str>, state: Option<&str>) -> Result<Url, ClientError>
{
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<P: Provider> Client<P> {
.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<P: Provider> Client<P> {
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<P: Provider> Client<P> where P::Token: Token<Refresh> {
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)
}

View File

@ -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(())
}

View File

@ -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.
///

View File

@ -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)]

View File

@ -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;

View File

@ -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)]

View File

@ -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)]