Add with_sub method for ServiceAccountKey - required to read email from user accounts

This commit is contained in:
OZ
2017-02-22 03:50:21 +01:00
parent 076b943768
commit 4e45d4358d
2 changed files with 15 additions and 2 deletions

2
Cargo.lock generated
View File

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

View File

@@ -158,6 +158,7 @@ pub struct ServiceAccountAccess<C> {
client: C,
key: ServiceAccountKey,
cache: MemoryStorage,
sub: Option<String>,
}
/// This is the schema of the server's response.
@@ -192,11 +193,23 @@ impl<'a, C> ServiceAccountAccess<C>
client: client,
key: key,
cache: MemoryStorage::default(),
sub: None,
}
}
pub fn with_sub(key: ServiceAccountKey, client: C, sub: Option<String>) -> ServiceAccountAccess<C> {
ServiceAccountAccess {
client: client,
key: key,
cache: MemoryStorage::default(),
sub: sub,
}
}
fn request_token(&mut self, scopes: &Vec<&str>) -> result::Result<Token, Box<error::Error>> {
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(),