feat(common): ConsoleApplicationSecret

A simplel structure to help reading secret files obtained from
https://code.google.com/apis/console
This commit is contained in:
Sebastian Thiel
2015-02-27 15:32:26 +01:00
parent aa030e8987
commit aedc9b6696
2 changed files with 49 additions and 1 deletions

View File

@@ -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),
}
}
}

View File

@@ -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};