Updating to Rust 2018 - about to fix
This commit is contained in:
parent
bebb3820ea
commit
7f52719948
10
Cargo.toml
10
Cargo.toml
|
@ -1,19 +1,21 @@
|
||||||
[package]
|
[package]
|
||||||
name = "oidc"
|
name = "oidc"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
license = "Apache-2.0"
|
|
||||||
description = "OpenID Connect client library using Reqwest, Biscuit, and inth-oauth2"
|
|
||||||
readme = "README.md"
|
|
||||||
authors = ["Zanny <lordzanny@gmail.com>"]
|
authors = ["Zanny <lordzanny@gmail.com>"]
|
||||||
categories = ["web-programming", "authentication"]
|
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"]
|
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"
|
repository = "https://gitlab.com/zanny/oidc-reqwest"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
base64 = "0.10"
|
base64 = "0.10"
|
||||||
biscuit = "0.1"
|
biscuit = "0.1"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
|
failure = "0.1"
|
||||||
inth-oauth2 = "0.16"
|
inth-oauth2 = "0.16"
|
||||||
reqwest = { version = "0.9", features = ["hyper-011"] }
|
reqwest = { version = "0.9", features = ["hyper-011"] }
|
||||||
serde = "1"
|
serde = "1"
|
||||||
|
|
|
@ -76,19 +76,17 @@ fn tru() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Discovered {
|
pub struct Discovered(pub Config);
|
||||||
pub config: Config,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Provider for Discovered {
|
impl Provider for Discovered {
|
||||||
type Lifetime = Expiring;
|
type Lifetime = Expiring;
|
||||||
type Token = Token;
|
type Token = Token;
|
||||||
fn auth_uri(&self) -> &Url {
|
fn auth_uri(&self) -> &Url {
|
||||||
&self.config.authorization_endpoint
|
&self.0.authorization_endpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
fn token_uri(&self) -> &Url {
|
fn token_uri(&self) -> &Url {
|
||||||
&self.config.token_endpoint
|
&self.0.token_endpoint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,33 +1,63 @@
|
||||||
use reqwest::Url;
|
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 {
|
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 {
|
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 {
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn yahoo() -> Url {
|
||||||
|
Url::parse("https://login.yahoo.com").expect(STATIC_URL_ERR_MSG)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use reqwest::Client;
|
||||||
|
use discovery::discover;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn google_disco() {
|
fn google_disco() {
|
||||||
let client = ::reqwest::Client::new();
|
let client = Client::new();
|
||||||
::discovery::discover(&client, google()).unwrap();
|
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]
|
#[test]
|
||||||
fn paypal_disco() {
|
fn paypal_disco() {
|
||||||
let client = ::reqwest::Client::new();
|
let client = Client::new();
|
||||||
::discovery::discover(&client, paypal()).unwrap();
|
discover(&client, super::paypal()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn salesforce_disco() {
|
fn salesforce_disco() {
|
||||||
let client = ::reqwest::Client::new();
|
let client = Client::new();
|
||||||
::discovery::discover(&client, salesforce()).unwrap();
|
discover(&client, super::salesforce()).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn yahoo_disco() {
|
||||||
|
let client = Client::new();
|
||||||
|
discover(&client, super::yahoo()).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -39,7 +39,7 @@
|
||||||
//!
|
//!
|
||||||
//! 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());
|
||||||
|
@ -124,7 +124,7 @@ impl Client {
|
||||||
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);
|
||||||
Ok(Self::new(id, secret, redirect, provider, jwks))
|
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
|
/// A reference to the config document of the provider obtained via discovery
|
||||||
pub fn config(&self) -> &Config {
|
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
|
/// Constructs the auth_url to redirect a client to the provider. Options are... optional. Use
|
||||||
|
|
Loading…
Reference in New Issue