From 6edce8f750a4514630f30ca349f6721b487a0a80 Mon Sep 17 00:00:00 2001 From: Matthew Scheirer Date: Thu, 6 Dec 2018 15:18:06 -0500 Subject: [PATCH] Update to rust 2018 --- src/discovery.rs | 7 ++++--- src/error.rs | 28 ++++++++++++++-------------- src/issuer.rs | 4 +--- src/lib.rs | 34 ++++++++++------------------------ src/token.rs | 3 ++- 5 files changed, 31 insertions(+), 45 deletions(-) diff --git a/src/discovery.rs b/src/discovery.rs index 44b1f73..a23e331 100644 --- a/src/discovery.rs +++ b/src/discovery.rs @@ -3,10 +3,11 @@ use biscuit::jwk::JWKSet; use inth_oauth2::provider::Provider; use inth_oauth2::token::Expiring; use reqwest::{Client, Url}; +use serde_derive::{Deserialize, Serialize}; use url_serde; -use error::Error; -use token::Token; +use crate::error::Error; +use crate::token::Token; pub(crate) fn secure(url: &Url) -> Result<(), Error> { if url.scheme() != "https" { @@ -17,7 +18,7 @@ pub(crate) fn secure(url: &Url) -> Result<(), Error> { } // TODO I wish we could impl default for this, but you cannot have a config without issuer etc -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct Config { #[serde(with = "url_serde")] pub issuer: Url, #[serde(with = "url_serde")] pub authorization_endpoint: Url, diff --git a/src/error.rs b/src/error.rs index cffea2d..50a2114 100644 --- a/src/error.rs +++ b/src/error.rs @@ -42,7 +42,7 @@ from!(Error, Userinfo); impl Display for Error { fn fmt(&self, f: &mut Formatter) -> Result { - use Error::*; + use self::Error::*; match *self { Jose(ref err) => Display::fmt(err, f), Json(ref err) => Display::fmt(err, f), @@ -60,7 +60,7 @@ impl Display for Error { impl ErrorTrait for Error { fn description(&self) -> &str { - use Error::*; + use self::Error::*; match *self { Jose(ref err) => err.description(), Json(ref err) => err.description(), @@ -76,7 +76,7 @@ impl ErrorTrait for Error { } fn cause(&self) -> Option<&ErrorTrait> { - use Error::*; + use self::Error::*; match *self { Jose(ref err) => Some(err), Json(ref err) => Some(err), @@ -101,7 +101,7 @@ pub enum Decode { impl ErrorTrait for Decode { fn description(&self) -> &str { - use Decode::*; + use self::Decode::*; match *self { MissingKid => "Missing Key Id", MissingKey(_) => "Token key not in key set", @@ -115,7 +115,7 @@ impl ErrorTrait for Decode { impl Display for Decode { fn fmt(&self, f: &mut Formatter) -> Result { - use Decode::*; + use self::Decode::*; match *self { MissingKid => write!(f, "Token Missing a Key Id when the key set has multiple keys"), MissingKey(ref id) => @@ -134,10 +134,10 @@ pub enum Validation { impl ErrorTrait for Validation { fn description(&self) -> &str { - use error::Validation::*; + use self::Validation::*; match *self { Mismatch(ref mm) => { - use error::Mismatch::*; + use self::Mismatch::*; match *mm { AuthorizedParty {..} => "Client id and token authorized party mismatch", Issuer {..} => "Config issuer and token issuer mismatch", @@ -145,7 +145,7 @@ impl ErrorTrait for Validation { } } Missing(ref mi) => { - use Missing::*; + use self::Missing::*; match *mi { Audience => "Token missing Audience", AuthorizedParty => "Token missing AZP", @@ -169,7 +169,7 @@ impl ErrorTrait for Validation { impl Display for Validation { fn fmt(&self, f: &mut Formatter) -> Result { - use error::Validation::*; + use self::Validation::*; match *self { Mismatch(ref err) => err.fmt(f), Missing(ref err) => err.fmt(f), @@ -187,7 +187,7 @@ pub enum Mismatch { impl Display for Mismatch { fn fmt(&self, f: &mut Formatter) -> Result { - use error::Mismatch::*; + use self::Mismatch::*; match *self { AuthorizedParty { ref expected, ref actual } => write!(f, "Client ID and Token authorized party mismatch: '{}', '{}'", expected, actual), @@ -209,7 +209,7 @@ pub enum Missing { impl Display for Missing { fn fmt(&self, f: &mut Formatter) -> Result { - use Missing::*; + use self::Missing::*; match *self { Audience => write!(f, "Token missing Audience"), AuthorizedParty => write!(f, "Token missing AZP"), @@ -227,7 +227,7 @@ pub enum Expiry { impl Display for Expiry { fn fmt(&self, f: &mut Formatter) -> Result { - use Expiry::*; + use self::Expiry::*; match *self { Expires(time) => write!(f, "Token expired at: {}", time), MaxAge(age) => write!(f, "Token is too old: {}", age) @@ -243,7 +243,7 @@ pub enum Userinfo { impl ErrorTrait for Userinfo { fn description(&self) -> &str { - use error::Userinfo::*; + use self::Userinfo::*; match *self { NoUrl => "No url", MismatchSubject { .. } => "Mismatch subject" @@ -257,7 +257,7 @@ impl ErrorTrait for Userinfo { impl Display for Userinfo { fn fmt(&self, f: &mut Formatter) -> Result { - use error::Userinfo::*; + use self::Userinfo::*; match *self { NoUrl => write!(f, "Config has no userinfo url"), MismatchSubject { ref expected, ref actual } => diff --git a/src/issuer.rs b/src/issuer.rs index 3e9d8ec..4d05eaf 100644 --- a/src/issuer.rs +++ b/src/issuer.rs @@ -27,7 +27,7 @@ pub fn yahoo() -> Url { #[cfg(test)] mod tests { use reqwest::Client; - use discovery::discover; + use crate::discovery::discover; #[test] fn google_disco() { @@ -39,8 +39,6 @@ mod tests { fn microsoft_disco() { let client = Client::new(); let res = discover(&client, super::microsoft()); - println!("Result: {:?}", res); - res.unwrap(); } #[test] diff --git a/src/lib.rs b/src/lib.rs index 719fda6..bfd7ab1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -62,28 +62,12 @@ //! - This version demonstrates userinfo. It is not required by spec, so make sure its available! //! (you get an Error::Userinfo::Nourl if it is not) -extern crate base64; -extern crate biscuit; -extern crate chrono; -extern crate inth_oauth2; -extern crate reqwest; -// We never use serde, but serde_derive needs it here -#[allow(unused_extern_crates)] -extern crate serde; -#[macro_use] -extern crate serde_derive; -extern crate serde_json; -extern crate url_serde; -extern crate validator; -#[macro_use] -extern crate validator_derive; - pub mod discovery; pub mod error; pub mod issuer; pub mod token; -pub use error::Error; +pub use crate::error::Error; use biscuit::{Empty, SingleOrMultiple}; use biscuit::jwa::{self, SignatureAlgorithm}; @@ -92,11 +76,13 @@ use biscuit::jws::{Compact, Secret}; use chrono::{Duration, NaiveDate, Utc}; use inth_oauth2::token::Token as _t; use reqwest::Url; +use serde_derive::{Deserialize, Serialize}; use validator::Validate; +use validator_derive::Validate; -use discovery::{Config, Discovered}; -use error::{Decode, Expiry, Mismatch, Missing, Validation}; -use token::{Claims, Token}; +use crate::discovery::{Config, Discovered}; +use crate::error::{Decode, Expiry, Mismatch, Missing, Validation}; +use crate::token::{Claims, Token}; type IdToken = Compact; @@ -435,7 +421,7 @@ pub struct Options { /// The userinfo struct contains all possible userinfo fields regardless of scope. [See spec.](https://openid.net/specs/openid-connect-basic-1_0.html#StandardClaims) // TODO is there a way to use claims_supported in config to simplify this struct? -#[derive(Debug, Serialize, Deserialize, Validate)] +#[derive(Debug, Deserialize, Serialize, Validate)] pub struct Userinfo { pub sub: String, #[serde(default)] pub name: Option, @@ -474,7 +460,7 @@ pub enum Display { impl Display { fn as_str(&self) -> &'static str { - use Display::*; + use self::Display::*; match *self { Page => "page", Popup => "popup", @@ -495,7 +481,7 @@ pub enum Prompt { impl Prompt { fn as_str(&self) -> &'static str { - use Prompt::*; + use self::Prompt::*; match *self { None => "none", Login => "login", @@ -506,7 +492,7 @@ impl Prompt { } /// Address Claim struct. Can be only formatted, only the rest, or both. -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct Address { #[serde(default)] pub formatted: Option, #[serde(default)] pub street_address: Option, diff --git a/src/token.rs b/src/token.rs index b1efde3..12aa583 100644 --- a/src/token.rs +++ b/src/token.rs @@ -3,6 +3,7 @@ use biscuit::{CompactJson, Empty, SingleOrMultiple}; use inth_oauth2::client::response::{FromResponse, ParseError}; use inth_oauth2::token::{self, Bearer, Expiring}; use reqwest::Url; +use serde_derive::{Deserialize, Serialize}; use serde_json::Value; use url_serde; @@ -11,7 +12,7 @@ pub use biscuit::jws::Compact as Jws; type IdToken = Jws; /// ID Token contents. [See spec.](https://openid.net/specs/openid-connect-basic-1_0.html#IDToken) -#[derive(Serialize, Deserialize)] +#[derive(Deserialize, Serialize)] pub struct Claims { #[serde(with = "url_serde")] pub iss: Url, // Max 255 ASCII chars