From 0535da306887779adb79f2adcf35910664532a99 Mon Sep 17 00:00:00 2001 From: Yang Gao Date: Wed, 11 Mar 2015 14:51:03 -0700 Subject: [PATCH] The Jwt code was dropped somewhere in a merge. Put it back --- include/grpc++/credentials.h | 8 ++++++++ src/cpp/client/secure_credentials.cc | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/include/grpc++/credentials.h b/include/grpc++/credentials.h index c677cc3e0a3..d480e0819ae 100644 --- a/include/grpc++/credentials.h +++ b/include/grpc++/credentials.h @@ -105,6 +105,14 @@ std::unique_ptr ServiceAccountCredentials( const grpc::string& json_key, const grpc::string& scope, std::chrono::seconds token_lifetime); + // Builds JWT credentials. + // json_key is the JSON key string containing the client's private key. + // token_lifetime is the lifetime of each Json Web Token (JWT) created with + // this credentials. It should not exceed grpc_max_auth_token_lifetime or + // will be cropped to this value. +std::unique_ptr JWTCredentials( + const grpc::string& json_key, std::chrono::seconds token_lifetime); + // Builds IAM credentials. std::unique_ptr IAMCredentials( const grpc::string& authorization_token, diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc index 47f645c1b63..795d7731c93 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -104,6 +104,15 @@ std::unique_ptr ServiceAccountCredentials( json_key.c_str(), scope.c_str(), lifetime)); } +// Builds JWT credentials. +std::unique_ptr JWTCredentials( + const grpc::string &json_key, std::chrono::seconds token_lifetime) { + gpr_timespec lifetime = gpr_time_from_seconds( + token_lifetime.count() > 0 ? token_lifetime.count() : 0); + return WrapCredentials( + grpc_jwt_credentials_create(json_key.c_str(), lifetime)); +} + // Builds IAM credentials. std::unique_ptr IAMCredentials( const grpc::string& authorization_token,