diff options
author | jboeuf <jboeuf@users.noreply.github.com> | 2015-03-16 10:04:08 -0700 |
---|---|---|
committer | jboeuf <jboeuf@users.noreply.github.com> | 2015-03-16 10:04:08 -0700 |
commit | c91a9f942e948c081f10a512d1c1be0926c845c7 (patch) | |
tree | 905a769ff37f0690fac5b3d3afe1e9c86cfd3649 /src/cpp/client | |
parent | 4c3ee74d4eaa8ad2772f9a069e41813cd8188956 (diff) | |
parent | 2fbbb9bd95cd6803afaf66e0cffb18d9189f731b (diff) |
Merge pull request #1011 from yang-g/jwt
Put back C++ JWTCredentials code and add a test case in interop test.
Diffstat (limited to 'src/cpp/client')
-rw-r--r-- | src/cpp/client/secure_credentials.cc | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc index 6ca702eead..a2f6a69858 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -98,12 +98,30 @@ std::unique_ptr<Credentials> ComputeEngineCredentials() { std::unique_ptr<Credentials> ServiceAccountCredentials( const grpc::string& json_key, const grpc::string& scope, std::chrono::seconds token_lifetime) { - gpr_timespec lifetime = gpr_time_from_seconds( - token_lifetime.count() > 0 ? token_lifetime.count() : 0); + if (token_lifetime.count() <= 0) { + gpr_log(GPR_ERROR, + "Trying to create ServiceAccountCredentials " + "with non-positive lifetime"); + return WrapCredentials(nullptr); + } + gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime.count()); return WrapCredentials(grpc_service_account_credentials_create( json_key.c_str(), scope.c_str(), lifetime)); } +// Builds JWT credentials. +std::unique_ptr<Credentials> JWTCredentials( + const grpc::string &json_key, std::chrono::seconds token_lifetime) { + if (token_lifetime.count() <= 0) { + gpr_log(GPR_ERROR, + "Trying to create JWTCredentials with non-positive lifetime"); + return WrapCredentials(nullptr); + } + gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime.count()); + return WrapCredentials( + grpc_jwt_credentials_create(json_key.c_str(), lifetime)); +} + // Builds IAM credentials. std::unique_ptr<Credentials> IAMCredentials( const grpc::string& authorization_token, |