Take String in Client::new
This commit is contained in:
parent
ad23733ce4
commit
c6aec754c3
|
@ -7,9 +7,9 @@ use inth_oauth2::provider::GitHub;
|
|||
|
||||
fn main() {
|
||||
let client = Client::<GitHub>::new(
|
||||
"01774654cd9a6051e478",
|
||||
"9f14d16d95d605e715ec1a9aecec220d2565fd5c",
|
||||
Some("https://cmcenroe.me/oauth2-paste/")
|
||||
String::from("01774654cd9a6051e478"),
|
||||
String::from("9f14d16d95d605e715ec1a9aecec220d2565fd5c"),
|
||||
Some(String::from("https://cmcenroe.me/oauth2-paste/"))
|
||||
);
|
||||
|
||||
let auth_uri = client.auth_uri(Some("user"), None).unwrap();
|
||||
|
|
|
@ -7,9 +7,9 @@ use inth_oauth2::provider::Google;
|
|||
|
||||
fn main() {
|
||||
let client = Client::<Google>::new(
|
||||
"143225766783-ip2d9qv6sdr37276t77luk6f7bhd6bj5.apps.googleusercontent.com",
|
||||
"3kZ5WomzHFlN2f_XbhkyPd3o",
|
||||
Some("urn:ietf:wg:oauth:2.0:oob")
|
||||
String::from("143225766783-ip2d9qv6sdr37276t77luk6f7bhd6bj5.apps.googleusercontent.com"),
|
||||
String::from("3kZ5WomzHFlN2f_XbhkyPd3o"),
|
||||
Some(String::from("urn:ietf:wg:oauth:2.0:oob"))
|
||||
);
|
||||
|
||||
let auth_uri = client.auth_uri(Some("https://www.googleapis.com/auth/userinfo.email"), None)
|
||||
|
|
|
@ -7,9 +7,9 @@ use inth_oauth2::provider::Imgur;
|
|||
|
||||
fn main() {
|
||||
let client = Client::<Imgur>::new(
|
||||
"505c8ca804230e0",
|
||||
"c898d8cf28404102752b2119a3a1c6aab49899c8",
|
||||
Some("https://cmcenroe.me/oauth2-paste/")
|
||||
String::from("505c8ca804230e0"),
|
||||
String::from("c898d8cf28404102752b2119a3a1c6aab49899c8"),
|
||||
Some(String::from("https://cmcenroe.me/oauth2-paste/"))
|
||||
);
|
||||
|
||||
let auth_uri = client.auth_uri(None, None).unwrap();
|
||||
|
|
|
@ -41,20 +41,16 @@ impl<P: Provider> Client<P> {
|
|||
/// use inth_oauth2::provider::Google;
|
||||
///
|
||||
/// let client = Client::<Google>::new(
|
||||
/// "CLIENT_ID",
|
||||
/// "CLIENT_SECRET",
|
||||
/// Some("urn:ietf:wg:oauth:2.0:oob")
|
||||
/// String::from("CLIENT_ID"),
|
||||
/// String::from("CLIENT_SECRET"),
|
||||
/// Some(String::from("urn:ietf:wg:oauth:2.0:oob"))
|
||||
/// );
|
||||
/// ```
|
||||
pub fn new<S>(
|
||||
client_id: S,
|
||||
client_secret: S,
|
||||
redirect_uri: Option<S>
|
||||
) -> Self where S: Into<String> {
|
||||
pub fn new(client_id: String, client_secret: String, redirect_uri: Option<String>) -> Self {
|
||||
Client {
|
||||
client_id: client_id.into(),
|
||||
client_secret: client_secret.into(),
|
||||
redirect_uri: redirect_uri.map(Into::into),
|
||||
client_id: client_id,
|
||||
client_secret: client_secret,
|
||||
redirect_uri: redirect_uri,
|
||||
provider: PhantomData,
|
||||
}
|
||||
}
|
||||
|
@ -70,9 +66,9 @@ impl<P: Provider> Client<P> {
|
|||
/// use inth_oauth2::provider::Google;
|
||||
///
|
||||
/// let client = Client::<Google>::new(
|
||||
/// "CLIENT_ID",
|
||||
/// "CLIENT_SECRET",
|
||||
/// Some("urn:ietf:wg:oauth:2.0:oob")
|
||||
/// String::from("CLIENT_ID"),
|
||||
/// String::from("CLIENT_SECRET"),
|
||||
/// Some(String::from("urn:ietf:wg:oauth:2.0:oob"))
|
||||
/// );
|
||||
///
|
||||
/// let auth_uri = client.auth_uri(
|
||||
|
@ -210,7 +206,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn auth_uri() {
|
||||
let client = Client::<Test>::new("foo", "bar", None);
|
||||
let client = Client::<Test>::new(String::from("foo"), String::from("bar"), None);
|
||||
assert_eq!(
|
||||
"http://example.com/oauth2/auth?response_type=code&client_id=foo",
|
||||
client.auth_uri(None, None).unwrap()
|
||||
|
@ -220,9 +216,9 @@ mod tests {
|
|||
#[test]
|
||||
fn auth_uri_with_redirect_uri() {
|
||||
let client = Client::<Test>::new(
|
||||
"foo",
|
||||
"bar",
|
||||
Some("http://example.com/oauth2/callback")
|
||||
String::from("foo"),
|
||||
String::from("bar"),
|
||||
Some(String::from("http://example.com/oauth2/callback"))
|
||||
);
|
||||
assert_eq!(
|
||||
"http://example.com/oauth2/auth?response_type=code&client_id=foo&redirect_uri=http%3A%2F%2Fexample.com%2Foauth2%2Fcallback",
|
||||
|
@ -232,7 +228,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn auth_uri_with_scope() {
|
||||
let client = Client::<Test>::new("foo", "bar", None);
|
||||
let client = Client::<Test>::new(String::from("foo"), String::from("bar"), None);
|
||||
assert_eq!(
|
||||
"http://example.com/oauth2/auth?response_type=code&client_id=foo&scope=baz",
|
||||
client.auth_uri(Some("baz"), None).unwrap()
|
||||
|
@ -241,7 +237,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn auth_uri_with_state() {
|
||||
let client = Client::<Test>::new("foo", "bar", None);
|
||||
let client = Client::<Test>::new(String::from("foo"), String::from("bar"), None);
|
||||
assert_eq!(
|
||||
"http://example.com/oauth2/auth?response_type=code&client_id=foo&state=baz",
|
||||
client.auth_uri(None, Some("baz")).unwrap()
|
||||
|
|
20
src/lib.rs
20
src/lib.rs
|
@ -33,9 +33,9 @@
|
|||
//! use inth_oauth2::provider::Google;
|
||||
//!
|
||||
//! let client = Client::<Google>::new(
|
||||
//! "client_id",
|
||||
//! "client_secret",
|
||||
//! Some("redirect_uri")
|
||||
//! String::from("client_id"),
|
||||
//! String::from("client_secret"),
|
||||
//! Some(String::from("redirect_uri"))
|
||||
//! );
|
||||
//! ```
|
||||
//!
|
||||
|
@ -44,7 +44,7 @@
|
|||
//! ```
|
||||
//! # use inth_oauth2::Client;
|
||||
//! # use inth_oauth2::provider::Google;
|
||||
//! # let client = Client::<Google>::new("", "", None);
|
||||
//! # let client = Client::<Google>::new(String::new(), String::new(), None);
|
||||
//! let auth_uri = client.auth_uri(Some("scope"), Some("state")).unwrap();
|
||||
//! println!("Authorize the application by clicking on the link: {}", auth_uri);
|
||||
//! ```
|
||||
|
@ -55,7 +55,7 @@
|
|||
//! use std::io;
|
||||
//! use inth_oauth2::{Client, Token};
|
||||
//! # use inth_oauth2::provider::Google;
|
||||
//! # let client = Client::<Google>::new("", "", None);
|
||||
//! # let client = Client::<Google>::new(String::new(), String::new(), None);
|
||||
//!
|
||||
//! let mut code = String::new();
|
||||
//! io::stdin().read_line(&mut code).unwrap();
|
||||
|
@ -70,7 +70,7 @@
|
|||
//! ```no_run
|
||||
//! # use inth_oauth2::Client;
|
||||
//! # use inth_oauth2::provider::Google;
|
||||
//! # let client = Client::<Google>::new("", "", None);
|
||||
//! # let client = Client::<Google>::new(String::new(), String::new(), None);
|
||||
//! # let http_client = Default::default();
|
||||
//! # let token = client.request_token(&http_client, "").unwrap();
|
||||
//! let token = client.refresh_token(&http_client, token, None).unwrap();
|
||||
|
@ -81,7 +81,7 @@
|
|||
//! ```no_run
|
||||
//! # use inth_oauth2::Client;
|
||||
//! # use inth_oauth2::provider::Google;
|
||||
//! # let client = Client::<Google>::new("", "", None);
|
||||
//! # let client = Client::<Google>::new(String::new(), String::new(), None);
|
||||
//! # let http_client = Default::default();
|
||||
//! # let mut token = client.request_token(&http_client, "").unwrap();
|
||||
//! // Refresh token only if it has expired.
|
||||
|
@ -101,7 +101,7 @@
|
|||
//!
|
||||
//! # fn main() {
|
||||
//! let client = hyper::Client::new();
|
||||
//! # let oauth_client = Client::<Google>::new("", "", None);
|
||||
//! # let oauth_client = Client::<Google>::new(String::new(), String::new(), None);
|
||||
//! # let token = oauth_client.request_token(&client, "").unwrap();
|
||||
//! let request = client.get("https://example.com/resource")
|
||||
//! .header(Into::<Authorization<_>>::into(&token));
|
||||
|
@ -121,7 +121,7 @@
|
|||
//! use rustc_serialize::json;
|
||||
//! # fn main() {
|
||||
//! # let http_client = Default::default();
|
||||
//! # let client = Client::<Google>::new("", "", None);
|
||||
//! # let client = Client::<Google>::new(String::new(), String::new(), None);
|
||||
//! # let token = client.request_token(&http_client, "").unwrap();
|
||||
//! let json = json::encode(&token).unwrap();
|
||||
//! # }
|
||||
|
@ -134,7 +134,7 @@
|
|||
//! # use inth_oauth2::provider::Google;
|
||||
//! # fn main() {
|
||||
//! # let http_client = Default::default();
|
||||
//! # let client = Client::<Google>::new("", "", None);
|
||||
//! # let client = Client::<Google>::new(String::new(), String::new(), None);
|
||||
//! # let token = client.request_token(&http_client, "").unwrap();
|
||||
//! let json = serde_json::to_string(&token).unwrap();
|
||||
//! # }
|
||||
|
|
|
@ -13,9 +13,9 @@ fn assert_get_uri_ok(uri: &str) {
|
|||
#[test]
|
||||
fn google_auth_uri_ok() {
|
||||
let client = Client::<Google>::new(
|
||||
"143225766783-ip2d9qv6sdr37276t77luk6f7bhd6bj5.apps.googleusercontent.com",
|
||||
"",
|
||||
Some("urn:ietf:wg:oauth:2.0:oob")
|
||||
String::from("143225766783-ip2d9qv6sdr37276t77luk6f7bhd6bj5.apps.googleusercontent.com"),
|
||||
String::new(),
|
||||
Some(String::from("urn:ietf:wg:oauth:2.0:oob"))
|
||||
);
|
||||
let auth_uri = client.auth_uri(
|
||||
Some("https://www.googleapis.com/auth/userinfo.email"),
|
||||
|
@ -27,9 +27,9 @@ fn google_auth_uri_ok() {
|
|||
#[test]
|
||||
fn github_auth_uri_ok() {
|
||||
let client = Client::<GitHub>::new(
|
||||
"01774654cd9a6051e478",
|
||||
"",
|
||||
Some("https://cmcenroe.me/oauth2-paste/")
|
||||
String::from("01774654cd9a6051e478"),
|
||||
String::new(),
|
||||
Some(String::from("https://cmcenroe.me/oauth2-paste/"))
|
||||
);
|
||||
let auth_uri = client.auth_uri(Some("user"), Some("state")).unwrap();
|
||||
assert_get_uri_ok(&auth_uri);
|
||||
|
@ -38,9 +38,9 @@ fn github_auth_uri_ok() {
|
|||
#[test]
|
||||
fn imgur_auth_uri_ok() {
|
||||
let client = Client::<Imgur>::new(
|
||||
"505c8ca804230e0",
|
||||
"",
|
||||
Some("https://cmcenroe.me/oauth2-paste/")
|
||||
String::from("505c8ca804230e0"),
|
||||
String::new(),
|
||||
Some(String::from("https://cmcenroe.me/oauth2-paste/"))
|
||||
);
|
||||
let auth_uri = client.auth_uri(None, Some("state")).unwrap();
|
||||
assert_get_uri_ok(&auth_uri);
|
||||
|
|
|
@ -59,8 +59,8 @@ mod connector {
|
|||
macro_rules! mock_client {
|
||||
($p:ty, $c:ty) => {
|
||||
(Client::<$p>::new(
|
||||
"client_id",
|
||||
"client_secret",
|
||||
String::from("client_id"),
|
||||
String::from("client_secret"),
|
||||
None
|
||||
),
|
||||
hyper::Client::with_connector(<$c>::default()))
|
||||
|
|
Loading…
Reference in New Issue