Refactor JWT handling in ServiceAccountAccess.

Avoid reading and parsing the private key file on every invocation of
token() in favor or reading it once when the ServiceAccountAccess is
built. Also avoid unnecessary allocations when signing JWT tokens and
renamed sub to subject to avoid any confusion with the std::ops::Sub
trait.
This commit is contained in:
Glenn Griffin
2019-11-11 14:04:27 -08:00
parent 05f7c10533
commit 060eb92bf7
2 changed files with 94 additions and 105 deletions

View File

@@ -7,7 +7,9 @@ use yup_oauth2::GetToken;
async fn main() {
let creds =
yup_oauth2::service_account_key_from_file(path::Path::new("serviceaccount.json")).unwrap();
let sa = yup_oauth2::ServiceAccountAccess::new(creds).build();
let sa = yup_oauth2::ServiceAccountAccess::new(creds)
.build()
.unwrap();
let scopes = &["https://www.googleapis.com/auth/pubsub"];
let tok = sa.token(scopes).await.unwrap();