Rename Google provider to google::Installed

This commit is contained in:
Curtis McEnroe 2016-02-21 17:16:54 -05:00
parent 26273b90f3
commit 93ac962b32
5 changed files with 42 additions and 32 deletions

View File

@ -3,10 +3,10 @@ extern crate inth_oauth2;
use std::io; use std::io;
use inth_oauth2::Client; use inth_oauth2::Client;
use inth_oauth2::provider::Google; use inth_oauth2::provider::google::Installed;
fn main() { fn main() {
let client = Client::<Google>::new( let client = Client::<Installed>::new(
String::from("143225766783-ip2d9qv6sdr37276t77luk6f7bhd6bj5.apps.googleusercontent.com"), String::from("143225766783-ip2d9qv6sdr37276t77luk6f7bhd6bj5.apps.googleusercontent.com"),
String::from("3kZ5WomzHFlN2f_XbhkyPd3o"), String::from("3kZ5WomzHFlN2f_XbhkyPd3o"),
Some(String::from("urn:ietf:wg:oauth:2.0:oob")) Some(String::from("urn:ietf:wg:oauth:2.0:oob"))

View File

@ -38,9 +38,9 @@ impl<P: Provider> Client<P> {
/// ///
/// ``` /// ```
/// use inth_oauth2::Client; /// use inth_oauth2::Client;
/// use inth_oauth2::provider::Google; /// use inth_oauth2::provider::google::Installed;
/// ///
/// let client = Client::<Google>::new( /// let client = Client::<Installed>::new(
/// String::from("CLIENT_ID"), /// String::from("CLIENT_ID"),
/// String::from("CLIENT_SECRET"), /// String::from("CLIENT_SECRET"),
/// Some(String::from("urn:ietf:wg:oauth:2.0:oob")) /// Some(String::from("urn:ietf:wg:oauth:2.0:oob"))
@ -63,9 +63,9 @@ impl<P: Provider> Client<P> {
/// ///
/// ``` /// ```
/// use inth_oauth2::Client; /// use inth_oauth2::Client;
/// use inth_oauth2::provider::Google; /// use inth_oauth2::provider::google::Installed;
/// ///
/// let client = Client::<Google>::new( /// let client = Client::<Installed>::new(
/// String::from("CLIENT_ID"), /// String::from("CLIENT_ID"),
/// String::from("CLIENT_SECRET"), /// String::from("CLIENT_SECRET"),
/// Some(String::from("urn:ietf:wg:oauth:2.0:oob")) /// Some(String::from("urn:ietf:wg:oauth:2.0:oob"))

View File

@ -14,6 +14,7 @@
//! Support for the following OAuth 2.0 providers is included: //! Support for the following OAuth 2.0 providers is included:
//! //!
//! - Google //! - Google
//! - Installed
//! - GitHub //! - GitHub
//! - Imgur //! - Imgur
//! //!
@ -30,9 +31,9 @@
//! //!
//! ``` //! ```
//! use inth_oauth2::Client; //! use inth_oauth2::Client;
//! use inth_oauth2::provider::Google; //! use inth_oauth2::provider::google::Installed;
//! //!
//! let client = Client::<Google>::new( //! let client = Client::<Installed>::new(
//! String::from("client_id"), //! String::from("client_id"),
//! String::from("client_secret"), //! String::from("client_secret"),
//! Some(String::from("redirect_uri")) //! Some(String::from("redirect_uri"))
@ -43,8 +44,8 @@
//! //!
//! ``` //! ```
//! # use inth_oauth2::Client; //! # use inth_oauth2::Client;
//! # use inth_oauth2::provider::Google; //! # use inth_oauth2::provider::google::Installed;
//! # let client = Client::<Google>::new(String::new(), String::new(), None); //! # let client = Client::<Installed>::new(String::new(), String::new(), None);
//! let auth_uri = client.auth_uri(Some("scope"), Some("state")).unwrap(); //! let auth_uri = client.auth_uri(Some("scope"), Some("state")).unwrap();
//! println!("Authorize the application by clicking on the link: {}", auth_uri); //! println!("Authorize the application by clicking on the link: {}", auth_uri);
//! ``` //! ```
@ -54,8 +55,8 @@
//! ```no_run //! ```no_run
//! use std::io; //! use std::io;
//! use inth_oauth2::{Client, Token}; //! use inth_oauth2::{Client, Token};
//! # use inth_oauth2::provider::Google; //! # use inth_oauth2::provider::google::Installed;
//! # let client = Client::<Google>::new(String::new(), String::new(), None); //! # let client = Client::<Installed>::new(String::new(), String::new(), None);
//! //!
//! let mut code = String::new(); //! let mut code = String::new();
//! io::stdin().read_line(&mut code).unwrap(); //! io::stdin().read_line(&mut code).unwrap();
@ -69,8 +70,8 @@
//! //!
//! ```no_run //! ```no_run
//! # use inth_oauth2::Client; //! # use inth_oauth2::Client;
//! # use inth_oauth2::provider::Google; //! # use inth_oauth2::provider::google::Installed;
//! # let client = Client::<Google>::new(String::new(), String::new(), None); //! # let client = Client::<Installed>::new(String::new(), String::new(), None);
//! # let http_client = Default::default(); //! # let http_client = Default::default();
//! # let token = client.request_token(&http_client, "").unwrap(); //! # let token = client.request_token(&http_client, "").unwrap();
//! let token = client.refresh_token(&http_client, token, None).unwrap(); //! let token = client.refresh_token(&http_client, token, None).unwrap();
@ -80,8 +81,8 @@
//! //!
//! ```no_run //! ```no_run
//! # use inth_oauth2::Client; //! # use inth_oauth2::Client;
//! # use inth_oauth2::provider::Google; //! # use inth_oauth2::provider::google::Installed;
//! # let client = Client::<Google>::new(String::new(), String::new(), None); //! # let client = Client::<Installed>::new(String::new(), String::new(), None);
//! # let http_client = Default::default(); //! # let http_client = Default::default();
//! # let mut token = client.request_token(&http_client, "").unwrap(); //! # let mut token = client.request_token(&http_client, "").unwrap();
//! // Refresh token only if it has expired. //! // Refresh token only if it has expired.
@ -96,12 +97,12 @@
//! # extern crate hyper; //! # extern crate hyper;
//! # extern crate inth_oauth2; //! # extern crate inth_oauth2;
//! # use inth_oauth2::Client; //! # use inth_oauth2::Client;
//! # use inth_oauth2::provider::Google; //! # use inth_oauth2::provider::google::Installed;
//! use hyper::header::Authorization; //! use hyper::header::Authorization;
//! //!
//! # fn main() { //! # fn main() {
//! let client = hyper::Client::new(); //! let client = hyper::Client::new();
//! # let oauth_client = Client::<Google>::new(String::new(), String::new(), None); //! # let oauth_client = Client::<Installed>::new(String::new(), String::new(), None);
//! # let token = oauth_client.request_token(&client, "").unwrap(); //! # let token = oauth_client.request_token(&client, "").unwrap();
//! let request = client.get("https://example.com/resource") //! let request = client.get("https://example.com/resource")
//! .header(Into::<Authorization<_>>::into(&token)); //! .header(Into::<Authorization<_>>::into(&token));
@ -117,11 +118,11 @@
//! # extern crate inth_oauth2; //! # extern crate inth_oauth2;
//! # extern crate rustc_serialize; //! # extern crate rustc_serialize;
//! # use inth_oauth2::Client; //! # use inth_oauth2::Client;
//! # use inth_oauth2::provider::Google; //! # use inth_oauth2::provider::google::Installed;
//! use rustc_serialize::json; //! use rustc_serialize::json;
//! # fn main() { //! # fn main() {
//! # let http_client = Default::default(); //! # let http_client = Default::default();
//! # let client = Client::<Google>::new(String::new(), String::new(), None); //! # let client = Client::<Installed>::new(String::new(), String::new(), None);
//! # let token = client.request_token(&http_client, "").unwrap(); //! # let token = client.request_token(&http_client, "").unwrap();
//! let json = json::encode(&token).unwrap(); //! let json = json::encode(&token).unwrap();
//! # } //! # }
@ -131,10 +132,10 @@
//! # extern crate inth_oauth2; //! # extern crate inth_oauth2;
//! extern crate serde_json; //! extern crate serde_json;
//! # use inth_oauth2::Client; //! # use inth_oauth2::Client;
//! # use inth_oauth2::provider::Google; //! # use inth_oauth2::provider::google::Installed;
//! # fn main() { //! # fn main() {
//! # let http_client = Default::default(); //! # let http_client = Default::default();
//! # let client = Client::<Google>::new(String::new(), String::new(), None); //! # let client = Client::<Installed>::new(String::new(), String::new(), None);
//! # let token = client.request_token(&http_client, "").unwrap(); //! # let token = client.request_token(&http_client, "").unwrap();
//! let json = serde_json::to_string(&token).unwrap(); //! let json = serde_json::to_string(&token).unwrap();
//! # } //! # }

View File

@ -35,17 +35,26 @@ pub trait Provider {
fn credentials_in_body() -> bool { false } fn credentials_in_body() -> bool { false }
} }
/// Google OAuth 2.0 provider. /// Google OAuth 2.0 providers.
/// ///
/// See [Using OAuth 2.0 to Access Google /// See [Using OAuth 2.0 to Access Google
/// APIs](https://developers.google.com/identity/protocols/OAuth2). /// APIs](https://developers.google.com/identity/protocols/OAuth2).
#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub mod google {
pub struct Google; use token::{Bearer, Expiring};
impl Provider for Google { use super::Provider;
type Lifetime = Expiring;
type Token = Bearer<Expiring>; /// Google OAuth 2.0 provider for installed applications.
fn auth_uri() -> &'static str { "https://accounts.google.com/o/oauth2/v2/auth" } ///
fn token_uri() -> &'static str { "https://www.googleapis.com/oauth2/v4/token" } /// See [Using OAuth 2.0 for Installed
/// Applications](https://developers.google.com/identity/protocols/OAuth2InstalledApp).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Installed;
impl Provider for Installed {
type Lifetime = Expiring;
type Token = Bearer<Expiring>;
fn auth_uri() -> &'static str { "https://accounts.google.com/o/oauth2/v2/auth" }
fn token_uri() -> &'static str { "https://www.googleapis.com/oauth2/v4/token" }
}
} }
/// GitHub OAuth 2.0 provider. /// GitHub OAuth 2.0 provider.

View File

@ -11,8 +11,8 @@ fn assert_get_uri_ok(uri: &str) {
} }
#[test] #[test]
fn google_auth_uri_ok() { fn google_installed_auth_uri_ok() {
let client = Client::<Google>::new( let client = Client::<google::Installed>::new(
String::from("143225766783-ip2d9qv6sdr37276t77luk6f7bhd6bj5.apps.googleusercontent.com"), String::from("143225766783-ip2d9qv6sdr37276t77luk6f7bhd6bj5.apps.googleusercontent.com"),
String::new(), String::new(),
Some(String::from("urn:ietf:wg:oauth:2.0:oob")) Some(String::from("urn:ietf:wg:oauth:2.0:oob"))