diff --git a/src/common.rs b/src/common.rs index 526fb88..54f6248 100644 --- a/src/common.rs +++ b/src/common.rs @@ -30,4 +30,52 @@ impl Str for AuthenticationType { AuthenticationType::Device => "https://accounts.google.com/o/oauth2/device/code", } } +} + +/// Represents either 'installed' or 'web' applications in a json secrets file. +/// See `ConsoleApplicationSecret` for more information +#[derive(RustcDecodable, RustcEncodable)] +pub struct ApplicationSecret { + /// The client ID. + pub client_id: String, + /// The client secret. + pub client_secret: String, + /// The token server endpoint URI. + pub token_uri: String, + /// The authorization server endpoint URI. + pub auth_uri: String, + pub redirect_uris: Vec, + + /// The service account email associated with the client. + pub client_email: Option, + /// The URL of the public x509 certificate, used to verify the signature on JWTs, such + /// as ID tokens, signed by the authentication provider. + pub auth_provider_x509_cert_url: Option, + /// The URL of the public x509 certificate, used to verify JWTs signed by the client. + pub client_x509_cert_url: Option +} + +/// A type to facilitate reading and writing the json secret file +/// as returned by the [google developer console](https://code.google.com/apis/console) +#[derive(RustcDecodable, RustcEncodable)] +pub struct ConsoleApplicationSecret { + web: Option, + installed: Option +} + + +#[cfg(test)] +mod tests { + use super::*; + + const SECRET: &'static str = "{\"installed\":{\"auth_uri\":\"https://accounts.google.com/o/oauth2/auth\",\"client_secret\":\"UqkDJd5RFwnHoiG5x5Rub8SI\",\"token_uri\":\"https://accounts.google.com/o/oauth2/token\",\"client_email\":\"\",\"redirect_uris\":[\"urn:ietf:wg:oauth:2.0:oob\",\"oob\"],\"client_x509_cert_url\":\"\",\"client_id\":\"14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com\",\"auth_provider_x509_cert_url\":\"https://www.googleapis.com/oauth2/v1/certs\"}}"; + + #[test] + fn console_secret() { + use rustc_serialize::json; + match json::decode::(SECRET) { + Ok(s) => assert!(s.installed.is_some()), + Err(err) => panic!(err), + } + } } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 403266f..93cf8a7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -82,5 +82,5 @@ mod common; pub use device::{DeviceFlow, PollInformation, PollResult, DeviceFlowHelper, DeviceFlowHelperDelegate, Retry}; pub use refresh::{RefreshFlow, RefreshResult}; -pub use common::{Token, AuthenticationType}; +pub use common::{Token, AuthenticationType, ApplicationSecret, ConsoleApplicationSecret};