Update dependencies

This commit is contained in:
Matthew Scheirer 2017-10-23 20:13:08 -04:00
parent 6861617e1a
commit a9200c17ac
4 changed files with 28 additions and 27 deletions

View File

@ -10,11 +10,11 @@ keywords = ["sync", "authentication", "client", "reqwest",
readme = "README.md" readme = "README.md"
[dependencies] [dependencies]
base64 = "0.6" base64 = "0.7"
biscuit = { git = "https://github.com/Korvox/biscuit" } biscuit = { git = "https://github.com/Korvox/biscuit" }
chrono = "0.4" chrono = "0.4"
inth-oauth2 = "0.13" inth-oauth2 = "0.15"
reqwest = "0.7" reqwest = "0.8"
serde = "1" serde = "1"
serde_derive = "1" serde_derive = "1"
serde_json = "1" serde_json = "1"

View File

@ -83,12 +83,12 @@ pub struct Discovered {
impl Provider for Discovered { impl Provider for Discovered {
type Lifetime = Expiring; type Lifetime = Expiring;
type Token = Token; type Token = Token;
fn auth_uri(&self) -> &str { fn auth_uri(&self) -> &Url {
self.config.authorization_endpoint.as_ref() &self.config.authorization_endpoint
} }
fn token_uri(&self) -> &str { fn token_uri(&self) -> &Url {
self.config.token_endpoint.as_ref() &self.config.token_endpoint
} }
} }
@ -97,7 +97,7 @@ impl Provider for Discovered {
pub fn discover(client: &Client, issuer: Url) -> Result<Config, Error> { pub fn discover(client: &Client, issuer: Url) -> Result<Config, Error> {
secure(&issuer)?; secure(&issuer)?;
let url = issuer.join("/.well-known/openid-configuration")?; let url = issuer.join("/.well-known/openid-configuration")?;
let mut resp = client.get(url)?.send()?; let mut resp = client.get(url).send()?;
resp.json().map_err(Error::from) resp.json().map_err(Error::from)
} }
@ -105,7 +105,7 @@ pub fn discover(client: &Client, issuer: Url) -> Result<Config, Error> {
/// the url isn't https. /// the url isn't https.
pub fn jwks(client: &Client, url: Url) -> Result<JWKSet<Empty>, Error> { pub fn jwks(client: &Client, url: Url) -> Result<JWKSet<Empty>, Error> {
secure(&url)?; secure(&url)?;
let mut resp = client.get(url)?.send()?; let mut resp = client.get(url).send()?;
resp.json().map_err(Error::from) resp.json().map_err(Error::from)
} }

View File

@ -16,18 +16,18 @@ pub fn salesforce() -> Url {
#[test] #[test]
fn google_disco() { fn google_disco() {
let client = ::reqwest::Client::new().unwrap(); let client = ::reqwest::Client::new();
::discovery::discover(&client, google()).unwrap(); ::discovery::discover(&client, google()).unwrap();
} }
#[test] #[test]
fn paypal_disco() { fn paypal_disco() {
let client = ::reqwest::Client::new().unwrap(); let client = ::reqwest::Client::new();
::discovery::discover(&client, paypal()).unwrap(); ::discovery::discover(&client, paypal()).unwrap();
} }
#[test] #[test]
fn salesforce_disco() { fn salesforce_disco() {
let client = ::reqwest::Client::new().unwrap(); let client = ::reqwest::Client::new();
::discovery::discover(&client, salesforce()).unwrap(); ::discovery::discover(&client, salesforce()).unwrap();
} }

View File

@ -14,7 +14,7 @@
//! let redirect = reqwest::Url::parse("https://my-redirect.foo")?; //! let redirect = reqwest::Url::parse("https://my-redirect.foo")?;
//! let issuer = oidc::issuer::google(); //! let issuer = oidc::issuer::google();
//! let client = oidc::discover(id, secret, redirect, issuer)?; //! let client = oidc::discover(id, secret, redirect, issuer)?;
//! let auth_url = client.auth_url(Default::default())?; //! let auth_url = client.auth_url(Default::default());
//! //!
//! // ... send your user to auth_url, get an auth_code back at your redirect_url handler //! // ... send your user to auth_url, get an auth_code back at your redirect_url handler
//! //!
@ -35,14 +35,14 @@
//! let secret = "a secret to everybody".to_string(); //! let secret = "a secret to everybody".to_string();
//! let redirect = reqwest::Url::parse("https://my-redirect.foo")?; //! let redirect = reqwest::Url::parse("https://my-redirect.foo")?;
//! let issuer = oidc::issuer::google(); //! let issuer = oidc::issuer::google();
//! let http = reqwest::Client::new()?; //! let http = reqwest::Client::new();
//! //!
//! let config = oidc::discovery::discover(&http, issuer)?; //! let config = oidc::discovery::discover(&http, issuer)?;
//! let jwks = oidc::discovery::jwks(&http, config.jwks_uri.clone())?; //! let jwks = oidc::discovery::jwks(&http, config.jwks_uri.clone())?;
//! let provider = oidc::discovery::Discovered { config }; //! let provider = oidc::discovery::Discovered { config };
//! //!
//! let client = oidc::new(id, secret, redirect, provider, jwks); //! let client = oidc::new(id, secret, redirect, provider, jwks);
//! let auth_url = client.auth_url(Default::default())?; //! let auth_url = client.auth_url(Default::default());
//! //!
//! // ... send your user to auth_url, get an auth_code back at your redirect_url handler //! // ... send your user to auth_url, get an auth_code back at your redirect_url handler
//! //!
@ -121,7 +121,7 @@ impl Client {
/// Constructs a client from an issuer url and client parameters via discovery /// Constructs a client from an issuer url and client parameters via discovery
pub fn discover(id: String, secret: String, redirect: Url, issuer: Url) -> Result<Self, Error> { pub fn discover(id: String, secret: String, redirect: Url, issuer: Url) -> Result<Self, Error> {
discovery::secure(&redirect)?; discovery::secure(&redirect)?;
let client = reqwest::Client::new()?; let client = reqwest::Client::new();
let config = discovery::discover(&client, issuer)?; let config = discovery::discover(&client, issuer)?;
let jwks = discovery::jwks(&client, config.jwks_uri.clone())?; let jwks = discovery::jwks(&client, config.jwks_uri.clone())?;
let provider = Discovered { config }; let provider = Discovered { config };
@ -163,19 +163,20 @@ impl Client {
/// Constructs the auth_url to redirect a client to the provider. Options are... optional. Use /// Constructs the auth_url to redirect a client to the provider. Options are... optional. Use
/// them as needed. Keep the Options struct around for authentication, or at least the nonce /// them as needed. Keep the Options struct around for authentication, or at least the nonce
/// and max_age parameter - we need to verify they stay the same and validate if you used them. /// and max_age parameter - we need to verify they stay the same and validate if you used them.
pub fn auth_url(&self, options: &Options) -> Result<Url, Error>{ pub fn auth_url(&self, options: &Options) -> Url {
let scope = match options.scope { let scope = match options.scope {
Some(ref scope) => { Some(ref scope) => {
if !scope.contains("openid") { if !scope.contains("openid") {
return Err(Error::MissingOpenidScope) String::from("openid ") + scope
} else {
scope.clone()
} }
scope
} }
// Default scope value // Default scope value
None => "openid" None => String::from("openid")
}; };
let mut url = self.oauth.auth_uri(Some(scope), options.state.as_ref().map(String::as_str))?; let mut url = self.oauth.auth_uri(Some(&scope), options.state.as_ref().map(String::as_str));
{ {
let mut query = url.query_pairs_mut(); let mut query = url.query_pairs_mut();
if let Some(ref nonce) = options.nonce { if let Some(ref nonce) = options.nonce {
@ -207,13 +208,13 @@ impl Client {
query.append_pair("acr_values", acr_values.as_str()); query.append_pair("acr_values", acr_values.as_str());
} }
} }
Ok(url) url
} }
/// Given an auth_code and auth options, request the token, decode, and validate it. /// Given an auth_code and auth options, request the token, decode, and validate it.
pub fn authenticate(&self, auth_code: &str, nonce: Option<&str>, max_age: Option<&Duration> pub fn authenticate(&self, auth_code: &str, nonce: Option<&str>, max_age: Option<&Duration>
) -> Result<Token, Error> { ) -> Result<Token, Error> {
let client = reqwest::Client::new()?; let client = reqwest::Client::new();
let mut token = self.request_token(&client, auth_code)?; let mut token = self.request_token(&client, auth_code)?;
self.decode_token(&mut token.id_token)?; self.decode_token(&mut token.id_token)?;
self.validate_token(&token.id_token, nonce, max_age)?; self.validate_token(&token.id_token, nonce, max_age)?;
@ -400,7 +401,7 @@ impl Client {
} }
let claims = token.id_token.payload()?; let claims = token.id_token.payload()?;
let auth_code = token.access_token().to_string(); let auth_code = token.access_token().to_string();
let mut resp = client.get(url.clone())? let mut resp = client.get(url.clone())
.header(header::Authorization(header::Bearer { token: auth_code })) .header(header::Authorization(header::Bearer { token: auth_code }))
.send()?; .send()?;
let info: Userinfo = resp.json()?; let info: Userinfo = resp.json()?;
@ -526,7 +527,7 @@ fn google() {
let secret = "a secret to everybody".to_string(); let secret = "a secret to everybody".to_string();
let redirect = Url::parse("https://example.com/re").unwrap(); let redirect = Url::parse("https://example.com/re").unwrap();
let client = Client::discover(id, secret, redirect, issuer::google()).unwrap(); let client = Client::discover(id, secret, redirect, issuer::google()).unwrap();
client.auth_url(&Default::default()).unwrap(); client.auth_url(&Default::default());
} }
#[test] #[test]
@ -535,7 +536,7 @@ fn paypal() {
let secret = "a secret to everybody".to_string(); let secret = "a secret to everybody".to_string();
let redirect = Url::parse("https://example.com/re").unwrap(); let redirect = Url::parse("https://example.com/re").unwrap();
let client = Client::discover(id, secret, redirect, issuer::paypal()).unwrap(); let client = Client::discover(id, secret, redirect, issuer::paypal()).unwrap();
client.auth_url(&Default::default()).unwrap(); client.auth_url(&Default::default());
} }
#[test] #[test]
@ -544,5 +545,5 @@ fn salesforce() {
let secret = "a secret to everybody".to_string(); let secret = "a secret to everybody".to_string();
let redirect = Url::parse("https://example.com/re").unwrap(); let redirect = Url::parse("https://example.com/re").unwrap();
let client = Client::discover(id, secret, redirect, issuer::salesforce()).unwrap(); let client = Client::discover(id, secret, redirect, issuer::salesforce()).unwrap();
client.auth_url(&Default::default()).unwrap(); client.auth_url(&Default::default());
} }