Rename Google provider to google::Installed
This commit is contained in:
parent
26273b90f3
commit
93ac962b32
|
@ -3,10 +3,10 @@ extern crate inth_oauth2;
|
|||
use std::io;
|
||||
|
||||
use inth_oauth2::Client;
|
||||
use inth_oauth2::provider::Google;
|
||||
use inth_oauth2::provider::google::Installed;
|
||||
|
||||
fn main() {
|
||||
let client = Client::<Google>::new(
|
||||
let client = Client::<Installed>::new(
|
||||
String::from("143225766783-ip2d9qv6sdr37276t77luk6f7bhd6bj5.apps.googleusercontent.com"),
|
||||
String::from("3kZ5WomzHFlN2f_XbhkyPd3o"),
|
||||
Some(String::from("urn:ietf:wg:oauth:2.0:oob"))
|
|
@ -38,9 +38,9 @@ impl<P: Provider> Client<P> {
|
|||
///
|
||||
/// ```
|
||||
/// 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_SECRET"),
|
||||
/// 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::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_SECRET"),
|
||||
/// Some(String::from("urn:ietf:wg:oauth:2.0:oob"))
|
||||
|
|
33
src/lib.rs
33
src/lib.rs
|
@ -14,6 +14,7 @@
|
|||
//! Support for the following OAuth 2.0 providers is included:
|
||||
//!
|
||||
//! - Google
|
||||
//! - Installed
|
||||
//! - GitHub
|
||||
//! - Imgur
|
||||
//!
|
||||
|
@ -30,9 +31,9 @@
|
|||
//!
|
||||
//! ```
|
||||
//! 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_secret"),
|
||||
//! Some(String::from("redirect_uri"))
|
||||
|
@ -43,8 +44,8 @@
|
|||
//!
|
||||
//! ```
|
||||
//! # use inth_oauth2::Client;
|
||||
//! # use inth_oauth2::provider::Google;
|
||||
//! # let client = Client::<Google>::new(String::new(), String::new(), None);
|
||||
//! # use inth_oauth2::provider::google::Installed;
|
||||
//! # let client = Client::<Installed>::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);
|
||||
//! ```
|
||||
|
@ -54,8 +55,8 @@
|
|||
//! ```no_run
|
||||
//! use std::io;
|
||||
//! use inth_oauth2::{Client, Token};
|
||||
//! # use inth_oauth2::provider::Google;
|
||||
//! # let client = Client::<Google>::new(String::new(), String::new(), None);
|
||||
//! # use inth_oauth2::provider::google::Installed;
|
||||
//! # let client = Client::<Installed>::new(String::new(), String::new(), None);
|
||||
//!
|
||||
//! let mut code = String::new();
|
||||
//! io::stdin().read_line(&mut code).unwrap();
|
||||
|
@ -69,8 +70,8 @@
|
|||
//!
|
||||
//! ```no_run
|
||||
//! # use inth_oauth2::Client;
|
||||
//! # use inth_oauth2::provider::Google;
|
||||
//! # let client = Client::<Google>::new(String::new(), String::new(), None);
|
||||
//! # use inth_oauth2::provider::google::Installed;
|
||||
//! # let client = Client::<Installed>::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();
|
||||
|
@ -80,8 +81,8 @@
|
|||
//!
|
||||
//! ```no_run
|
||||
//! # use inth_oauth2::Client;
|
||||
//! # use inth_oauth2::provider::Google;
|
||||
//! # let client = Client::<Google>::new(String::new(), String::new(), None);
|
||||
//! # use inth_oauth2::provider::google::Installed;
|
||||
//! # let client = Client::<Installed>::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.
|
||||
|
@ -96,12 +97,12 @@
|
|||
//! # extern crate hyper;
|
||||
//! # extern crate inth_oauth2;
|
||||
//! # use inth_oauth2::Client;
|
||||
//! # use inth_oauth2::provider::Google;
|
||||
//! # use inth_oauth2::provider::google::Installed;
|
||||
//! use hyper::header::Authorization;
|
||||
//!
|
||||
//! # fn main() {
|
||||
//! 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 request = client.get("https://example.com/resource")
|
||||
//! .header(Into::<Authorization<_>>::into(&token));
|
||||
|
@ -117,11 +118,11 @@
|
|||
//! # extern crate inth_oauth2;
|
||||
//! # extern crate rustc_serialize;
|
||||
//! # use inth_oauth2::Client;
|
||||
//! # use inth_oauth2::provider::Google;
|
||||
//! # use inth_oauth2::provider::google::Installed;
|
||||
//! use rustc_serialize::json;
|
||||
//! # fn main() {
|
||||
//! # 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 json = json::encode(&token).unwrap();
|
||||
//! # }
|
||||
|
@ -131,10 +132,10 @@
|
|||
//! # extern crate inth_oauth2;
|
||||
//! extern crate serde_json;
|
||||
//! # use inth_oauth2::Client;
|
||||
//! # use inth_oauth2::provider::Google;
|
||||
//! # use inth_oauth2::provider::google::Installed;
|
||||
//! # fn main() {
|
||||
//! # 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 json = serde_json::to_string(&token).unwrap();
|
||||
//! # }
|
||||
|
|
|
@ -35,18 +35,27 @@ pub trait Provider {
|
|||
fn credentials_in_body() -> bool { false }
|
||||
}
|
||||
|
||||
/// Google OAuth 2.0 provider.
|
||||
/// Google OAuth 2.0 providers.
|
||||
///
|
||||
/// See [Using OAuth 2.0 to Access Google
|
||||
/// APIs](https://developers.google.com/identity/protocols/OAuth2).
|
||||
pub mod google {
|
||||
use token::{Bearer, Expiring};
|
||||
use super::Provider;
|
||||
|
||||
/// Google OAuth 2.0 provider for installed applications.
|
||||
///
|
||||
/// See [Using OAuth 2.0 for Installed
|
||||
/// Applications](https://developers.google.com/identity/protocols/OAuth2InstalledApp).
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Google;
|
||||
impl Provider for Google {
|
||||
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.
|
||||
///
|
||||
|
|
|
@ -11,8 +11,8 @@ fn assert_get_uri_ok(uri: &str) {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn google_auth_uri_ok() {
|
||||
let client = Client::<Google>::new(
|
||||
fn google_installed_auth_uri_ok() {
|
||||
let client = Client::<google::Installed>::new(
|
||||
String::from("143225766783-ip2d9qv6sdr37276t77luk6f7bhd6bj5.apps.googleusercontent.com"),
|
||||
String::new(),
|
||||
Some(String::from("urn:ietf:wg:oauth:2.0:oob"))
|
||||
|
|
Loading…
Reference in New Issue