This is an automated email from the ASF dual-hosted git repository.

penghui pushed a commit to branch branch-2.8
in repository https://gitbox.apache.org/repos/asf/pulsar.git

commit 8b55470dd25d787433a693fcdb37782b1b09ee5a
Author: Yunze Xu <[email protected]>
AuthorDate: Sat Oct 9 08:14:40 2021 +0800

    [C++] Support configuring optional scope field for OAuth2 authentication 
(#12305)
    
    It's a C++ client catchup for https://github.com/apache/pulsar/pull/11931.
    
    - Add a `scope_` field to `ClientCredentialFlow` and load it from 
`ParamMap` object whose key is `scope`.
    - Refactor `ClientCredentialFlow` to simplify code and make it testable:
      - Use only one constructor instead of two overloaded constructors that 
might look confused
      - Add a `generateJsonBody` public method for generating JSON body for 
post fields in `authenticate` so that it can be tested.
      - Add a `KeyFile` class like what Java client does to load client id and 
client secret from `ParamMap` or file.
    
    - [x] Make sure that the change passes the CI checks.
    
    This change added test `AuthPluginTest.testOauth2RequestBody` for the cases 
that scope exists or doesn't exist.
    
    (cherry picked from commit 44dcc04d037511984ec383fb3f2c75170e4cfefc)
---
 pulsar-client-cpp/lib/auth/AuthOauth2.cc | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/pulsar-client-cpp/lib/auth/AuthOauth2.cc 
b/pulsar-client-cpp/lib/auth/AuthOauth2.cc
index c7cc2bf..c7c8e95 100644
--- a/pulsar-client-cpp/lib/auth/AuthOauth2.cc
+++ b/pulsar-client-cpp/lib/auth/AuthOauth2.cc
@@ -119,6 +119,14 @@ bool Oauth2CachedToken::isExpired() { return expiresAt_ < 
currentTimeMillis(); }
 Oauth2Flow::Oauth2Flow() {}
 Oauth2Flow::~Oauth2Flow() {}
 
+// ClientCredentialFlow
+static std::string readFromFile(const std::string& credentialsFilePath) {
+    std::ifstream input(credentialsFilePath);
+    std::stringstream buffer;
+    buffer << input.rdbuf();
+    return buffer.str();
+}
+
 KeyFile KeyFile::fromParamMap(ParamMap& params) {
     const auto it = params.find("private_key");
     if (it != params.cend()) {

Reply via email to