Style cleanup
This commit is contained in:
parent
f3906e71d0
commit
80a7a02050
|
@ -8,7 +8,6 @@ keywords = ["authentication", "authorization", "auth", "oauth"]
|
||||||
authors = ["Curtis McEnroe <programble@gmail.com>"]
|
authors = ["Curtis McEnroe <programble@gmail.com>"]
|
||||||
license = "ISC"
|
license = "ISC"
|
||||||
|
|
||||||
documentation = "https://cmcenroe.me/inth-oauth2/inth_oauth2"
|
|
||||||
repository = "https://github.com/programble/inth-oauth2"
|
repository = "https://github.com/programble/inth-oauth2"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
|
||||||
|
|
|
@ -13,14 +13,19 @@ use error::OAuth2Error;
|
||||||
pub enum ClientError {
|
pub enum ClientError {
|
||||||
/// IO error.
|
/// IO error.
|
||||||
Io(io::Error),
|
Io(io::Error),
|
||||||
|
|
||||||
/// URL error.
|
/// URL error.
|
||||||
Url(url::ParseError),
|
Url(url::ParseError),
|
||||||
|
|
||||||
/// Hyper error.
|
/// Hyper error.
|
||||||
Hyper(hyper::Error),
|
Hyper(hyper::Error),
|
||||||
|
|
||||||
/// JSON error.
|
/// JSON error.
|
||||||
Json(serde_json::Error),
|
Json(serde_json::Error),
|
||||||
|
|
||||||
/// Response parse error.
|
/// Response parse error.
|
||||||
Parse(ParseError),
|
Parse(ParseError),
|
||||||
|
|
||||||
/// OAuth 2.0 error.
|
/// OAuth 2.0 error.
|
||||||
OAuth2(OAuth2Error),
|
OAuth2(OAuth2Error),
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
//! Client.
|
//! Client.
|
||||||
|
|
||||||
|
mod error;
|
||||||
|
|
||||||
|
pub mod response;
|
||||||
|
pub use self::error::ClientError;
|
||||||
|
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use hyper::{self, header, mime};
|
use hyper::{self, header, mime};
|
||||||
|
@ -7,16 +12,11 @@ use serde_json::{self, Value};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use url::form_urlencoded::Serializer;
|
use url::form_urlencoded::Serializer;
|
||||||
|
|
||||||
|
use client::response::FromResponse;
|
||||||
use error::OAuth2Error;
|
use error::OAuth2Error;
|
||||||
use provider::Provider;
|
use provider::Provider;
|
||||||
use token::{Token, Lifetime, Refresh};
|
use token::{Token, Lifetime, Refresh};
|
||||||
|
|
||||||
use self::response::FromResponse;
|
|
||||||
pub mod response;
|
|
||||||
|
|
||||||
pub use self::error::ClientError;
|
|
||||||
mod error;
|
|
||||||
|
|
||||||
/// OAuth 2.0 client.
|
/// OAuth 2.0 client.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct Client<P: Provider> {
|
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>
|
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();
|
let mut query = uri.query_pairs_mut();
|
||||||
|
@ -128,7 +128,7 @@ impl<P: Provider> Client<P> {
|
||||||
.header(header::ContentType::form_url_encoded())
|
.header(header::ContentType::form_url_encoded())
|
||||||
.body(&body);
|
.body(&body);
|
||||||
|
|
||||||
let mut response = try!(request.send());
|
let mut response = request.send()?;
|
||||||
let json = serde_json::from_reader(&mut response)?;
|
let json = serde_json::from_reader(&mut response)?;
|
||||||
|
|
||||||
let error = OAuth2Error::from_response(&json);
|
let error = OAuth2Error::from_response(&json);
|
||||||
|
@ -156,8 +156,8 @@ impl<P: Provider> Client<P> {
|
||||||
body.append_pair("redirect_uri", redirect_uri);
|
body.append_pair("redirect_uri", redirect_uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
let json = try!(self.post_token(http_client, body));
|
let json = self.post_token(http_client, body)?;
|
||||||
let token = try!(P::Token::from_response(&json));
|
let token = P::Token::from_response(&json)?;
|
||||||
Ok(token)
|
Ok(token)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -180,8 +180,8 @@ impl<P: Provider> Client<P> where P::Token: Token<Refresh> {
|
||||||
body.append_pair("scope", scope);
|
body.append_pair("scope", scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
let json = try!(self.post_token(http_client, body));
|
let json = self.post_token(http_client, body)?;
|
||||||
let token = try!(P::Token::from_response_inherit(&json, &token));
|
let token = P::Token::from_response_inherit(&json, &token)?;
|
||||||
Ok(token)
|
Ok(token)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,12 +71,12 @@ pub struct OAuth2Error {
|
||||||
|
|
||||||
impl fmt::Display for OAuth2Error {
|
impl fmt::Display for OAuth2Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
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 {
|
if let Some(ref description) = self.description {
|
||||||
try!(write!(f, ": {}", description));
|
write!(f, ": {}", description)?;
|
||||||
}
|
}
|
||||||
if let Some(ref uri) = self.uri {
|
if let Some(ref uri) = self.uri {
|
||||||
try!(write!(f, " ({})", uri));
|
write!(f, " ({})", uri)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use hyper::header;
|
use hyper::header;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
use super::{Token, Lifetime};
|
|
||||||
use client::response::{FromResponse, ParseError};
|
use client::response::{FromResponse, ParseError};
|
||||||
|
use token::{Token, Lifetime};
|
||||||
|
|
||||||
/// The bearer token type.
|
/// The bearer token type.
|
||||||
///
|
///
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use chrono::{DateTime, UTC, Duration};
|
use chrono::{DateTime, UTC, Duration};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
use super::Lifetime;
|
|
||||||
use client::response::{FromResponse, ParseError};
|
use client::response::{FromResponse, ParseError};
|
||||||
|
use token::Lifetime;
|
||||||
|
|
||||||
/// An expiring token.
|
/// An expiring token.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
|
|
@ -5,6 +5,16 @@
|
||||||
//!
|
//!
|
||||||
//! Expiring and non-expiring tokens are abstracted through the `Lifetime` trait.
|
//! 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;
|
use client::response::FromResponse;
|
||||||
|
|
||||||
/// OAuth 2.0 tokens.
|
/// OAuth 2.0 tokens.
|
||||||
|
@ -28,13 +38,3 @@ pub trait Lifetime: FromResponse {
|
||||||
/// Returns true if the access token is no longer valid.
|
/// Returns true if the access token is no longer valid.
|
||||||
fn expired(&self) -> bool;
|
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;
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use chrono::{DateTime, UTC, Duration};
|
use chrono::{DateTime, UTC, Duration};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
use super::Lifetime;
|
|
||||||
use client::response::{FromResponse, ParseError};
|
use client::response::{FromResponse, ParseError};
|
||||||
|
use token::Lifetime;
|
||||||
|
|
||||||
/// An expiring token which can be refreshed.
|
/// An expiring token which can be refreshed.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
use super::Lifetime;
|
|
||||||
use client::response::{FromResponse, ParseError};
|
use client::response::{FromResponse, ParseError};
|
||||||
|
use token::Lifetime;
|
||||||
|
|
||||||
/// A static, non-expiring token.
|
/// A static, non-expiring token.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
|
Loading…
Reference in New Issue