From 4e45d4358d4dd9c6dec8f5026ce3c28b6ab34ebb Mon Sep 17 00:00:00 2001 From: OZ Date: Wed, 22 Feb 2017 03:50:21 +0100 Subject: [PATCH] Add with_sub method for ServiceAccountKey - required to read email from user accounts --- Cargo.lock | 2 +- src/service_account.rs | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c2686aa..1c8df35 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ [root] name = "yup-oauth2" -version = "1.0.4" +version = "1.0.5" dependencies = [ "base64 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/service_account.rs b/src/service_account.rs index 686a799..c93ee7d 100644 --- a/src/service_account.rs +++ b/src/service_account.rs @@ -158,6 +158,7 @@ pub struct ServiceAccountAccess { client: C, key: ServiceAccountKey, cache: MemoryStorage, + sub: Option, } /// This is the schema of the server's response. @@ -192,11 +193,23 @@ impl<'a, C> ServiceAccountAccess client: client, key: key, cache: MemoryStorage::default(), + sub: None, + } + } + + pub fn with_sub(key: ServiceAccountKey, client: C, sub: Option) -> ServiceAccountAccess { + ServiceAccountAccess { + client: client, + key: key, + cache: MemoryStorage::default(), + sub: sub, } } fn request_token(&mut self, scopes: &Vec<&str>) -> result::Result> { - let signed = try!(JWT::new(init_claims_from_key(&self.key, scopes)) + let mut claims = init_claims_from_key(&self.key, scopes); + claims.sub = self.sub.clone(); + let signed = try!(JWT::new(claims) .sign(self.key.private_key.as_ref().unwrap())); let body = form_urlencoded::serialize(vec![("grant_type".to_string(),