1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! # Google Sign-In
//!
//! This crate provides an API to verify Google's OAuth client id tokens
//! for use with Google is an authentication provider.
//!
//! Typically these tokens are generated by a web application using the
//! [Google Platform Library](https://developers.google.com/identity/sign-in/web/sign-in).
//!
//! ## Getting Started
//! Create a new client and configure it with your client id(s).
//!
//! ```
//! extern crate google_signin;
//!
//! # fn main() {
//! let mut client = google_signin::Client::new();
//! client.audiences.push("YOUR_CLIENT_ID.apps.googleusercontent.com".to_string()); // required
//! client.hosted_domains.push("YOUR_HOSTED_DOMAIN.tld".to_string()); // optional
//! # }
//! ```
//!
//! When you get an id token (typically in an HTTP request handler), you should verify
//! it using the client's `verify` method:
//!
//! ```
//! struct GoogleLogin {
//!     token: String,
//! }
//!
//! # fn handler(client: &google_signin::Client, request: GoogleLogin) {
//! // Recommended: Let the crate handle everything for you
//! let id_info = client.verify(&request.token).expect("Expected token to be valid");
//! println!("Success! Signed-in as {}", id_info.sub);
//!
//! // Alternative: Inspect the ID before verifying it
//! let id_info = client.get_slow_unverified(&request.token).expect("Expected token to exist");
//! let ok = id_info.verify(&client).is_ok();
//! println!("Ok: {}, Info: {:?}", ok, id_info);
//! # }
//! ```

extern crate hyper;
#[cfg(feature = "with-rustls")]
extern crate hyper_rustls;
#[cfg(feature = "with-openssl")]
extern crate hyper_openssl;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;

mod client;
mod error;
mod token;

pub use client::Client;
pub use error::Error;
pub use token::IdInfo;