diff --git a/Cargo.toml b/Cargo.toml index 7cfb56c..1c1669f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,19 +1,21 @@ [package] name = "oidc" version = "0.1.0" -license = "Apache-2.0" -description = "OpenID Connect client library using Reqwest, Biscuit, and inth-oauth2" -readme = "README.md" authors = ["Zanny "] categories = ["web-programming", "authentication"] +description = "OpenID Connect client library using Reqwest, Biscuit, and inth-oauth2" +documentation = "https://docs.rs/crate/oidc" +edition = "2018" keywords = ["authentication", "client", "openid", "openid_connect", "web"] -documentation = "https://docs.rs/crate/oidc/0.1.0" +license = "Apache-2.0" +readme = "README.md" repository = "https://gitlab.com/zanny/oidc-reqwest" [dependencies] base64 = "0.10" biscuit = "0.1" chrono = "0.4" +failure = "0.1" inth-oauth2 = "0.16" reqwest = { version = "0.9", features = ["hyper-011"] } serde = "1" diff --git a/src/discovery.rs b/src/discovery.rs index a515f0e..44b1f73 100644 --- a/src/discovery.rs +++ b/src/discovery.rs @@ -76,19 +76,17 @@ fn tru() -> bool { true } -pub struct Discovered { - pub config: Config, -} +pub struct Discovered(pub Config); impl Provider for Discovered { type Lifetime = Expiring; type Token = Token; fn auth_uri(&self) -> &Url { - &self.config.authorization_endpoint + &self.0.authorization_endpoint } fn token_uri(&self) -> &Url { - &self.config.token_endpoint + &self.0.token_endpoint } } diff --git a/src/issuer.rs b/src/issuer.rs index 3cc5680..3e9d8ec 100644 --- a/src/issuer.rs +++ b/src/issuer.rs @@ -1,33 +1,63 @@ use reqwest::Url; -// TODO these should all be const, or even better, static Urls... +const STATIC_URL_ERR_MSG: &str = "Static urls should always work!"; + +// TODO these should all be const, or even better, sttic Urls...a pub fn google() -> Url { - Url::parse("https://accounts.google.com").expect("Static urls should always work!") + Url::parse("https://accounts.google.com").expect(STATIC_URL_ERR_MSG) +} + +pub fn microsoft() -> Url { + Url::parse("https://login.microsoftonline.com/common/v2.0").expect(STATIC_URL_ERR_MSG) } pub fn paypal() -> Url { - Url::parse("https://www.paypalobjects.com/").expect("Static urls should always work!") + Url::parse("https://www.paypalobjects.com/").expect(STATIC_URL_ERR_MSG) } pub fn salesforce() -> Url { - Url::parse("https://login.salesforce.com").expect("Static urls should always work!") + Url::parse("https://login.salesforce.com").expect(STATIC_URL_ERR_MSG) } -#[test] -fn google_disco() { - let client = ::reqwest::Client::new(); - ::discovery::discover(&client, google()).unwrap(); +pub fn yahoo() -> Url { + Url::parse("https://login.yahoo.com").expect(STATIC_URL_ERR_MSG) } -#[test] -fn paypal_disco() { - let client = ::reqwest::Client::new(); - ::discovery::discover(&client, paypal()).unwrap(); -} +#[cfg(test)] +mod tests { + use reqwest::Client; + use discovery::discover; -#[test] -fn salesforce_disco() { - let client = ::reqwest::Client::new(); - ::discovery::discover(&client, salesforce()).unwrap(); -} \ No newline at end of file + #[test] + fn google_disco() { + let client = Client::new(); + discover(&client, super::google()).unwrap(); + } + + #[test] + fn microsoft_disco() { + let client = Client::new(); + let res = discover(&client, super::microsoft()); + println!("Result: {:?}", res); + res.unwrap(); + } + + #[test] + fn paypal_disco() { + let client = Client::new(); + discover(&client, super::paypal()).unwrap(); + } + + #[test] + fn salesforce_disco() { + let client = Client::new(); + discover(&client, super::salesforce()).unwrap(); + } + + #[test] + fn yahoo_disco() { + let client = Client::new(); + discover(&client, super::yahoo()).unwrap(); + } +} diff --git a/src/lib.rs b/src/lib.rs index 78be052..719fda6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,7 +39,7 @@ //! //! let config = oidc::discovery::discover(&http, issuer)?; //! 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 auth_url = client.auth_url(Default::default()); @@ -124,7 +124,7 @@ impl Client { let client = reqwest::Client::new(); let config = discovery::discover(&client, issuer)?; let jwks = discovery::jwks(&client, config.jwks_uri.clone())?; - let provider = Discovered { config }; + let provider = Discovered(config); Ok(Self::new(id, secret, redirect, provider, jwks)) } @@ -157,7 +157,7 @@ impl Client { /// A reference to the config document of the provider obtained via discovery pub fn config(&self) -> &Config { - &self.oauth.provider.config + &self.oauth.provider.0 } /// Constructs the auth_url to redirect a client to the provider. Options are... optional. Use