diff --git a/Cargo.toml b/Cargo.toml index 41c7b0c..f229ac8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,11 +10,11 @@ keywords = ["sync", "authentication", "client", "reqwest", readme = "README.md" [dependencies] -base64 = "0.6" +base64 = "0.7" biscuit = { git = "https://github.com/Korvox/biscuit" } chrono = "0.4" -inth-oauth2 = "0.13" -reqwest = "0.7" +inth-oauth2 = "0.15" +reqwest = "0.8" serde = "1" serde_derive = "1" serde_json = "1" diff --git a/src/discovery.rs b/src/discovery.rs index 2332687..f6fedff 100644 --- a/src/discovery.rs +++ b/src/discovery.rs @@ -83,12 +83,12 @@ pub struct Discovered { impl Provider for Discovered { type Lifetime = Expiring; type Token = Token; - fn auth_uri(&self) -> &str { - self.config.authorization_endpoint.as_ref() + fn auth_uri(&self) -> &Url { + &self.config.authorization_endpoint } - fn token_uri(&self) -> &str { - self.config.token_endpoint.as_ref() + fn token_uri(&self) -> &Url { + &self.config.token_endpoint } } @@ -97,7 +97,7 @@ impl Provider for Discovered { pub fn discover(client: &Client, issuer: Url) -> Result { secure(&issuer)?; 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) } @@ -105,7 +105,7 @@ pub fn discover(client: &Client, issuer: Url) -> Result { /// the url isn't https. pub fn jwks(client: &Client, url: Url) -> Result, Error> { secure(&url)?; - let mut resp = client.get(url)?.send()?; + let mut resp = client.get(url).send()?; resp.json().map_err(Error::from) } diff --git a/src/issuer.rs b/src/issuer.rs index 23d2c99..3cc5680 100644 --- a/src/issuer.rs +++ b/src/issuer.rs @@ -16,18 +16,18 @@ pub fn salesforce() -> Url { #[test] fn google_disco() { - let client = ::reqwest::Client::new().unwrap(); + let client = ::reqwest::Client::new(); ::discovery::discover(&client, google()).unwrap(); } #[test] fn paypal_disco() { - let client = ::reqwest::Client::new().unwrap(); + let client = ::reqwest::Client::new(); ::discovery::discover(&client, paypal()).unwrap(); } #[test] fn salesforce_disco() { - let client = ::reqwest::Client::new().unwrap(); + let client = ::reqwest::Client::new(); ::discovery::discover(&client, salesforce()).unwrap(); } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index d28b5f0..1ac0a6d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,7 @@ //! let redirect = reqwest::Url::parse("https://my-redirect.foo")?; //! let issuer = oidc::issuer::google(); //! 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 //! @@ -35,14 +35,14 @@ //! let secret = "a secret to everybody".to_string(); //! let redirect = reqwest::Url::parse("https://my-redirect.foo")?; //! let issuer = oidc::issuer::google(); -//! let http = reqwest::Client::new()?; +//! let http = reqwest::Client::new(); //! //! let config = oidc::discovery::discover(&http, issuer)?; //! let jwks = oidc::discovery::jwks(&http, config.jwks_uri.clone())?; //! let provider = oidc::discovery::Discovered { config }; //! //! 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 //! @@ -121,7 +121,7 @@ impl Client { /// Constructs a client from an issuer url and client parameters via discovery pub fn discover(id: String, secret: String, redirect: Url, issuer: Url) -> Result { discovery::secure(&redirect)?; - let client = reqwest::Client::new()?; + let client = reqwest::Client::new(); let config = discovery::discover(&client, issuer)?; let jwks = discovery::jwks(&client, config.jwks_uri.clone())?; 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 /// 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. - pub fn auth_url(&self, options: &Options) -> Result{ + pub fn auth_url(&self, options: &Options) -> Url { let scope = match options.scope { Some(ref scope) => { if !scope.contains("openid") { - return Err(Error::MissingOpenidScope) + String::from("openid ") + scope + } else { + scope.clone() } - scope } // 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(); if let Some(ref nonce) = options.nonce { @@ -207,13 +208,13 @@ impl Client { 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. pub fn authenticate(&self, auth_code: &str, nonce: Option<&str>, max_age: Option<&Duration> ) -> Result { - let client = reqwest::Client::new()?; + let client = reqwest::Client::new(); let mut token = self.request_token(&client, auth_code)?; self.decode_token(&mut token.id_token)?; self.validate_token(&token.id_token, nonce, max_age)?; @@ -400,7 +401,7 @@ impl Client { } let claims = token.id_token.payload()?; 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 })) .send()?; let info: Userinfo = resp.json()?; @@ -526,7 +527,7 @@ fn google() { let secret = "a secret to everybody".to_string(); let redirect = Url::parse("https://example.com/re").unwrap(); let client = Client::discover(id, secret, redirect, issuer::google()).unwrap(); - client.auth_url(&Default::default()).unwrap(); + client.auth_url(&Default::default()); } #[test] @@ -535,7 +536,7 @@ fn paypal() { let secret = "a secret to everybody".to_string(); let redirect = Url::parse("https://example.com/re").unwrap(); let client = Client::discover(id, secret, redirect, issuer::paypal()).unwrap(); - client.auth_url(&Default::default()).unwrap(); + client.auth_url(&Default::default()); } #[test] @@ -544,5 +545,5 @@ fn salesforce() { let secret = "a secret to everybody".to_string(); let redirect = Url::parse("https://example.com/re").unwrap(); let client = Client::discover(id, secret, redirect, issuer::salesforce()).unwrap(); - client.auth_url(&Default::default()).unwrap(); + client.auth_url(&Default::default()); } \ No newline at end of file