parent
0813240aea
commit
0132a85be2
|
@ -76,7 +76,7 @@ impl<P: Provider> Client<P> {
|
||||||
/// None
|
/// None
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
pub fn auth_uri(&self, scope: Option<&str>, state: Option<&str>) -> Result<String, ClientError>
|
pub fn auth_uri(&self, scope: Option<&str>, state: Option<&str>) -> Result<Url, ClientError>
|
||||||
{
|
{
|
||||||
let mut uri = try!(Url::parse(P::auth_uri()));
|
let mut uri = try!(Url::parse(P::auth_uri()));
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ impl<P: Provider> Client<P> {
|
||||||
|
|
||||||
uri.set_query_from_pairs(query_pairs.iter());
|
uri.set_query_from_pairs(query_pairs.iter());
|
||||||
|
|
||||||
Ok(uri.serialize())
|
Ok(uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn post_token<'a>(
|
fn post_token<'a>(
|
||||||
|
@ -209,7 +209,7 @@ mod tests {
|
||||||
let client = Client::<Test>::new(String::from("foo"), String::from("bar"), None);
|
let client = Client::<Test>::new(String::from("foo"), String::from("bar"), None);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"http://example.com/oauth2/auth?response_type=code&client_id=foo",
|
"http://example.com/oauth2/auth?response_type=code&client_id=foo",
|
||||||
client.auth_uri(None, None).unwrap()
|
client.auth_uri(None, None).unwrap().serialize()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,7 +222,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"http://example.com/oauth2/auth?response_type=code&client_id=foo&redirect_uri=http%3A%2F%2Fexample.com%2Foauth2%2Fcallback",
|
"http://example.com/oauth2/auth?response_type=code&client_id=foo&redirect_uri=http%3A%2F%2Fexample.com%2Foauth2%2Fcallback",
|
||||||
client.auth_uri(None, None).unwrap()
|
client.auth_uri(None, None).unwrap().serialize()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ mod tests {
|
||||||
let client = Client::<Test>::new(String::from("foo"), String::from("bar"), None);
|
let client = Client::<Test>::new(String::from("foo"), String::from("bar"), None);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"http://example.com/oauth2/auth?response_type=code&client_id=foo&scope=baz",
|
"http://example.com/oauth2/auth?response_type=code&client_id=foo&scope=baz",
|
||||||
client.auth_uri(Some("baz"), None).unwrap()
|
client.auth_uri(Some("baz"), None).unwrap().serialize()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,7 +240,7 @@ mod tests {
|
||||||
let client = Client::<Test>::new(String::from("foo"), String::from("bar"), None);
|
let client = Client::<Test>::new(String::from("foo"), String::from("bar"), None);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"http://example.com/oauth2/auth?response_type=code&client_id=foo&state=baz",
|
"http://example.com/oauth2/auth?response_type=code&client_id=foo&state=baz",
|
||||||
client.auth_uri(None, Some("baz")).unwrap()
|
client.auth_uri(None, Some("baz")).unwrap().serialize()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
extern crate hyper;
|
extern crate hyper;
|
||||||
extern crate inth_oauth2;
|
extern crate inth_oauth2;
|
||||||
|
extern crate url;
|
||||||
|
|
||||||
use inth_oauth2::Client;
|
use inth_oauth2::Client;
|
||||||
use inth_oauth2::provider::*;
|
use inth_oauth2::provider::*;
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
fn assert_get_uri_ok(uri: &str) {
|
fn assert_get_uri_ok(uri: Url) {
|
||||||
let client = hyper::Client::new();
|
let client = hyper::Client::new();
|
||||||
let response = client.get(uri).send().unwrap();
|
let response = client.get(uri).send().unwrap();
|
||||||
assert_eq!(hyper::Ok, response.status);
|
assert_eq!(hyper::Ok, response.status);
|
||||||
|
@ -21,7 +23,7 @@ fn google_web_auth_uri_ok() {
|
||||||
Some("https://www.googleapis.com/auth/userinfo.email"),
|
Some("https://www.googleapis.com/auth/userinfo.email"),
|
||||||
Some("state"),
|
Some("state"),
|
||||||
).unwrap();
|
).unwrap();
|
||||||
assert_get_uri_ok(&auth_uri);
|
assert_get_uri_ok(auth_uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -35,7 +37,7 @@ fn google_installed_auth_uri_ok() {
|
||||||
Some("https://www.googleapis.com/auth/userinfo.email"),
|
Some("https://www.googleapis.com/auth/userinfo.email"),
|
||||||
Some("state")
|
Some("state")
|
||||||
).unwrap();
|
).unwrap();
|
||||||
assert_get_uri_ok(&auth_uri);
|
assert_get_uri_ok(auth_uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -46,7 +48,7 @@ fn github_auth_uri_ok() {
|
||||||
Some(String::from("https://cmcenroe.me/oauth2-paste/"))
|
Some(String::from("https://cmcenroe.me/oauth2-paste/"))
|
||||||
);
|
);
|
||||||
let auth_uri = client.auth_uri(Some("user"), Some("state")).unwrap();
|
let auth_uri = client.auth_uri(Some("user"), Some("state")).unwrap();
|
||||||
assert_get_uri_ok(&auth_uri);
|
assert_get_uri_ok(auth_uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -57,5 +59,5 @@ fn imgur_auth_uri_ok() {
|
||||||
Some(String::from("https://cmcenroe.me/oauth2-paste/"))
|
Some(String::from("https://cmcenroe.me/oauth2-paste/"))
|
||||||
);
|
);
|
||||||
let auth_uri = client.auth_uri(None, Some("state")).unwrap();
|
let auth_uri = client.auth_uri(None, Some("state")).unwrap();
|
||||||
assert_get_uri_ok(&auth_uri);
|
assert_get_uri_ok(auth_uri);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue