Skip to content

Commit

Permalink
feat(common): ConsoleApplicationSecret
Browse files Browse the repository at this point in the history
A simplel structure to help reading secret files obtained from
https://code.google.com/apis/console
  • Loading branch information
Byron committed Feb 27, 2015
1 parent aa030e8 commit aedc9b6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
48 changes: 48 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

/// The service account email associated with the client.
pub client_email: Option<String>,
/// 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<String>,
/// The URL of the public x509 certificate, used to verify JWTs signed by the client.
pub client_x509_cert_url: Option<String>
}

/// 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<ApplicationSecret>,
installed: Option<ApplicationSecret>
}


#[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::<ConsoleApplicationSecret>(SECRET) {
Ok(s) => assert!(s.installed.is_some()),
Err(err) => panic!(err),
}
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

0 comments on commit aedc9b6

Please sign in to comment.