Update to rust 2018

This commit is contained in:
Matthew Scheirer 2018-12-06 15:18:06 -05:00
parent 7f52719948
commit 6edce8f750
5 changed files with 31 additions and 45 deletions

View File

@ -3,10 +3,11 @@ use biscuit::jwk::JWKSet;
use inth_oauth2::provider::Provider; use inth_oauth2::provider::Provider;
use inth_oauth2::token::Expiring; use inth_oauth2::token::Expiring;
use reqwest::{Client, Url}; use reqwest::{Client, Url};
use serde_derive::{Deserialize, Serialize};
use url_serde; use url_serde;
use error::Error; use crate::error::Error;
use token::Token; use crate::token::Token;
pub(crate) fn secure(url: &Url) -> Result<(), Error> { pub(crate) fn secure(url: &Url) -> Result<(), Error> {
if url.scheme() != "https" { 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 // 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 { pub struct Config {
#[serde(with = "url_serde")] pub issuer: Url, #[serde(with = "url_serde")] pub issuer: Url,
#[serde(with = "url_serde")] pub authorization_endpoint: Url, #[serde(with = "url_serde")] pub authorization_endpoint: Url,

View File

@ -42,7 +42,7 @@ from!(Error, Userinfo);
impl Display for Error { impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> Result { fn fmt(&self, f: &mut Formatter) -> Result {
use Error::*; use self::Error::*;
match *self { match *self {
Jose(ref err) => Display::fmt(err, f), Jose(ref err) => Display::fmt(err, f),
Json(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 { impl ErrorTrait for Error {
fn description(&self) -> &str { fn description(&self) -> &str {
use Error::*; use self::Error::*;
match *self { match *self {
Jose(ref err) => err.description(), Jose(ref err) => err.description(),
Json(ref err) => err.description(), Json(ref err) => err.description(),
@ -76,7 +76,7 @@ impl ErrorTrait for Error {
} }
fn cause(&self) -> Option<&ErrorTrait> { fn cause(&self) -> Option<&ErrorTrait> {
use Error::*; use self::Error::*;
match *self { match *self {
Jose(ref err) => Some(err), Jose(ref err) => Some(err),
Json(ref err) => Some(err), Json(ref err) => Some(err),
@ -101,7 +101,7 @@ pub enum Decode {
impl ErrorTrait for Decode { impl ErrorTrait for Decode {
fn description(&self) -> &str { fn description(&self) -> &str {
use Decode::*; use self::Decode::*;
match *self { match *self {
MissingKid => "Missing Key Id", MissingKid => "Missing Key Id",
MissingKey(_) => "Token key not in key set", MissingKey(_) => "Token key not in key set",
@ -115,7 +115,7 @@ impl ErrorTrait for Decode {
impl Display for Decode { impl Display for Decode {
fn fmt(&self, f: &mut Formatter) -> Result { fn fmt(&self, f: &mut Formatter) -> Result {
use Decode::*; use self::Decode::*;
match *self { match *self {
MissingKid => write!(f, "Token Missing a Key Id when the key set has multiple keys"), MissingKid => write!(f, "Token Missing a Key Id when the key set has multiple keys"),
MissingKey(ref id) => MissingKey(ref id) =>
@ -134,10 +134,10 @@ pub enum Validation {
impl ErrorTrait for Validation { impl ErrorTrait for Validation {
fn description(&self) -> &str { fn description(&self) -> &str {
use error::Validation::*; use self::Validation::*;
match *self { match *self {
Mismatch(ref mm) => { Mismatch(ref mm) => {
use error::Mismatch::*; use self::Mismatch::*;
match *mm { match *mm {
AuthorizedParty {..} => "Client id and token authorized party mismatch", AuthorizedParty {..} => "Client id and token authorized party mismatch",
Issuer {..} => "Config issuer and token issuer mismatch", Issuer {..} => "Config issuer and token issuer mismatch",
@ -145,7 +145,7 @@ impl ErrorTrait for Validation {
} }
} }
Missing(ref mi) => { Missing(ref mi) => {
use Missing::*; use self::Missing::*;
match *mi { match *mi {
Audience => "Token missing Audience", Audience => "Token missing Audience",
AuthorizedParty => "Token missing AZP", AuthorizedParty => "Token missing AZP",
@ -169,7 +169,7 @@ impl ErrorTrait for Validation {
impl Display for Validation { impl Display for Validation {
fn fmt(&self, f: &mut Formatter) -> Result { fn fmt(&self, f: &mut Formatter) -> Result {
use error::Validation::*; use self::Validation::*;
match *self { match *self {
Mismatch(ref err) => err.fmt(f), Mismatch(ref err) => err.fmt(f),
Missing(ref err) => err.fmt(f), Missing(ref err) => err.fmt(f),
@ -187,7 +187,7 @@ pub enum Mismatch {
impl Display for Mismatch { impl Display for Mismatch {
fn fmt(&self, f: &mut Formatter) -> Result { fn fmt(&self, f: &mut Formatter) -> Result {
use error::Mismatch::*; use self::Mismatch::*;
match *self { match *self {
AuthorizedParty { ref expected, ref actual } => AuthorizedParty { ref expected, ref actual } =>
write!(f, "Client ID and Token authorized party mismatch: '{}', '{}'", expected, actual), write!(f, "Client ID and Token authorized party mismatch: '{}', '{}'", expected, actual),
@ -209,7 +209,7 @@ pub enum Missing {
impl Display for Missing { impl Display for Missing {
fn fmt(&self, f: &mut Formatter) -> Result { fn fmt(&self, f: &mut Formatter) -> Result {
use Missing::*; use self::Missing::*;
match *self { match *self {
Audience => write!(f, "Token missing Audience"), Audience => write!(f, "Token missing Audience"),
AuthorizedParty => write!(f, "Token missing AZP"), AuthorizedParty => write!(f, "Token missing AZP"),
@ -227,7 +227,7 @@ pub enum Expiry {
impl Display for Expiry { impl Display for Expiry {
fn fmt(&self, f: &mut Formatter) -> Result { fn fmt(&self, f: &mut Formatter) -> Result {
use Expiry::*; use self::Expiry::*;
match *self { match *self {
Expires(time) => write!(f, "Token expired at: {}", time), Expires(time) => write!(f, "Token expired at: {}", time),
MaxAge(age) => write!(f, "Token is too old: {}", age) MaxAge(age) => write!(f, "Token is too old: {}", age)
@ -243,7 +243,7 @@ pub enum Userinfo {
impl ErrorTrait for Userinfo { impl ErrorTrait for Userinfo {
fn description(&self) -> &str { fn description(&self) -> &str {
use error::Userinfo::*; use self::Userinfo::*;
match *self { match *self {
NoUrl => "No url", NoUrl => "No url",
MismatchSubject { .. } => "Mismatch subject" MismatchSubject { .. } => "Mismatch subject"
@ -257,7 +257,7 @@ impl ErrorTrait for Userinfo {
impl Display for Userinfo { impl Display for Userinfo {
fn fmt(&self, f: &mut Formatter) -> Result { fn fmt(&self, f: &mut Formatter) -> Result {
use error::Userinfo::*; use self::Userinfo::*;
match *self { match *self {
NoUrl => write!(f, "Config has no userinfo url"), NoUrl => write!(f, "Config has no userinfo url"),
MismatchSubject { ref expected, ref actual } => MismatchSubject { ref expected, ref actual } =>

View File

@ -27,7 +27,7 @@ pub fn yahoo() -> Url {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use reqwest::Client; use reqwest::Client;
use discovery::discover; use crate::discovery::discover;
#[test] #[test]
fn google_disco() { fn google_disco() {
@ -39,8 +39,6 @@ mod tests {
fn microsoft_disco() { fn microsoft_disco() {
let client = Client::new(); let client = Client::new();
let res = discover(&client, super::microsoft()); let res = discover(&client, super::microsoft());
println!("Result: {:?}", res);
res.unwrap();
} }
#[test] #[test]

View File

@ -62,28 +62,12 @@
//! - This version demonstrates userinfo. It is not required by spec, so make sure its available! //! - 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) //! (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 discovery;
pub mod error; pub mod error;
pub mod issuer; pub mod issuer;
pub mod token; pub mod token;
pub use error::Error; pub use crate::error::Error;
use biscuit::{Empty, SingleOrMultiple}; use biscuit::{Empty, SingleOrMultiple};
use biscuit::jwa::{self, SignatureAlgorithm}; use biscuit::jwa::{self, SignatureAlgorithm};
@ -92,11 +76,13 @@ use biscuit::jws::{Compact, Secret};
use chrono::{Duration, NaiveDate, Utc}; use chrono::{Duration, NaiveDate, Utc};
use inth_oauth2::token::Token as _t; use inth_oauth2::token::Token as _t;
use reqwest::Url; use reqwest::Url;
use serde_derive::{Deserialize, Serialize};
use validator::Validate; use validator::Validate;
use validator_derive::Validate;
use discovery::{Config, Discovered}; use crate::discovery::{Config, Discovered};
use error::{Decode, Expiry, Mismatch, Missing, Validation}; use crate::error::{Decode, Expiry, Mismatch, Missing, Validation};
use token::{Claims, Token}; use crate::token::{Claims, Token};
type IdToken = Compact<Claims, Empty>; type IdToken = Compact<Claims, Empty>;
@ -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) /// 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? // 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 struct Userinfo {
pub sub: String, pub sub: String,
#[serde(default)] pub name: Option<String>, #[serde(default)] pub name: Option<String>,
@ -474,7 +460,7 @@ pub enum Display {
impl Display { impl Display {
fn as_str(&self) -> &'static str { fn as_str(&self) -> &'static str {
use Display::*; use self::Display::*;
match *self { match *self {
Page => "page", Page => "page",
Popup => "popup", Popup => "popup",
@ -495,7 +481,7 @@ pub enum Prompt {
impl Prompt { impl Prompt {
fn as_str(&self) -> &'static str { fn as_str(&self) -> &'static str {
use Prompt::*; use self::Prompt::*;
match *self { match *self {
None => "none", None => "none",
Login => "login", Login => "login",
@ -506,7 +492,7 @@ impl Prompt {
} }
/// Address Claim struct. Can be only formatted, only the rest, or both. /// Address Claim struct. Can be only formatted, only the rest, or both.
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Deserialize, Serialize)]
pub struct Address { pub struct Address {
#[serde(default)] pub formatted: Option<String>, #[serde(default)] pub formatted: Option<String>,
#[serde(default)] pub street_address: Option<String>, #[serde(default)] pub street_address: Option<String>,

View File

@ -3,6 +3,7 @@ use biscuit::{CompactJson, Empty, SingleOrMultiple};
use inth_oauth2::client::response::{FromResponse, ParseError}; use inth_oauth2::client::response::{FromResponse, ParseError};
use inth_oauth2::token::{self, Bearer, Expiring}; use inth_oauth2::token::{self, Bearer, Expiring};
use reqwest::Url; use reqwest::Url;
use serde_derive::{Deserialize, Serialize};
use serde_json::Value; use serde_json::Value;
use url_serde; use url_serde;
@ -11,7 +12,7 @@ pub use biscuit::jws::Compact as Jws;
type IdToken = Jws<Claims, Empty>; type IdToken = Jws<Claims, Empty>;
/// ID Token contents. [See spec.](https://openid.net/specs/openid-connect-basic-1_0.html#IDToken) /// 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 { pub struct Claims {
#[serde(with = "url_serde")] pub iss: Url, #[serde(with = "url_serde")] pub iss: Url,
// Max 255 ASCII chars // Max 255 ASCII chars