From 5ebd6c76a27f1445d1ed5f52e27008ff83070565 Mon Sep 17 00:00:00 2001 From: Yang Gao Date: Tue, 17 Mar 2015 16:22:32 -0700 Subject: [PATCH] wrap refresh token credentials in c++ --- include/grpc++/credentials.h | 10 ++++++++-- src/cpp/client/secure_credentials.cc | 12 ++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/grpc++/credentials.h b/include/grpc++/credentials.h index 59ad638f47d..2ac3eec95cd 100644 --- a/include/grpc++/credentials.h +++ b/include/grpc++/credentials.h @@ -50,8 +50,8 @@ class Credentials { protected: friend std::unique_ptr CompositeCredentials( - const std::unique_ptr& creds1, - const std::unique_ptr& creds2); + const std::unique_ptr& creds1, + const std::unique_ptr& creds2); virtual SecureCredentials* AsSecureCredentials() = 0; @@ -113,6 +113,12 @@ std::unique_ptr ServiceAccountCredentials( std::unique_ptr JWTCredentials( const grpc::string& json_key, std::chrono::seconds token_lifetime); +// Builds refresh token credentials. +// json_refresh_token is the JSON string containing the refresh token along +// with a client_id and client_secret. +std::unique_ptr RefreshTokenCredentials( + const grpc::string& json_refresh_token); + // 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 a2f6a698583..e3c66376236 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -55,7 +55,8 @@ class SecureCredentials GRPC_FINAL : public Credentials { args.SetChannelArgs(&channel_args); return std::shared_ptr(new Channel( args.GetSslTargetNameOverride().empty() - ? target : args.GetSslTargetNameOverride(), + ? target + : args.GetSslTargetNameOverride(), grpc_secure_channel_create(c_creds_, target.c_str(), &channel_args))); } @@ -111,7 +112,7 @@ std::unique_ptr ServiceAccountCredentials( // Builds JWT credentials. std::unique_ptr JWTCredentials( - const grpc::string &json_key, std::chrono::seconds token_lifetime) { + 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"); @@ -122,6 +123,13 @@ std::unique_ptr JWTCredentials( grpc_jwt_credentials_create(json_key.c_str(), lifetime)); } +// Builds refresh token credentials. +std::unique_ptr RefreshTokenCredentials( + const grpc::string& json_refresh_token) { + return WrapCredentials( + grpc_refresh_token_credentials_create(json_refresh_token.c_str())); +} + // Builds IAM credentials. std::unique_ptr IAMCredentials( const grpc::string& authorization_token,