BewareMyPower opened a new issue #12324:
URL: https://github.com/apache/pulsar/issues/12324


   **Describe the bug**
   When configuring C++ client with wrong client secret to make OAuth 2.0 
authentication fail, instead of returning any error code, segmentation fault 
will happen.
   
   **To Reproduce**
   
   ```c++
   #include <iostream>
   
   #include <pulsar/Client.h>
   
   #include <lib/LogUtils.h>
   
   DECLARE_LOG_OBJECT()
   
   using namespace pulsar;
   
   int main() {
       ParamMap params;
       params["issuer_url"] = "https://dev-kt-aa9ne.us.auth0.com";;
       params["client_id"] = "my-client";
       params["client_secret"] = "my-secret";
       params["audience"] = "https://dev-kt-aa9ne.us.auth0.com/api/v2/";;
   
       ClientConfiguration conf;
       conf.setLogger(new ConsoleLoggerFactory(Logger::LEVEL_DEBUG));
       conf.setAuth(AuthOauth2::create(params));
   
       Client client("pulsar://localhost:6650", conf);
   
       Producer producer;
       Result result = 
client.createProducer("persistent://public/default/my-topic", producer);
       if (result != ResultOk) {
           LOG_ERROR("Error creating producer: " << result);
           return -1;
       }
   
       client.close();
   }
   ```
   
   The output:
   
   ```
   2021-10-11 17:47:48.862 ERROR [0x700009313000] AuthOauth2:313 | Response 
failed for issuerurl https://dev-kt-aa9ne.us.auth0.com. response Code 401 
passedin: {
       "grant_type": "client_credentials",
       "client_id": "my-client",
       "client_secret": "my-secret",
       "audience": "https:\/\/dev-kt-aa9ne.us.auth0.com\/api\/v2\/"
   }
   
   libc++abi.dylib: terminating with uncaught exception of type 
std::runtime_error: ExpiresIn in Oauth2TokenResult invalid value: -1
   zsh: abort      ./examples/SampleProducer
   ```
   
   When I modified `issuer_url` to an unknown OAuth2 server URL like 
`https://google.com`, the output became:
   
   ```
   2021-10-11 18:01:28.517 ERROR [0x112d5be00] AuthOauth2:217 | Response failed 
for getting the well-known configuration https://google.com. response Code 404
   ...
   libc++abi.dylib: terminating with uncaught exception of type 
std::runtime_error: ExpiresIn in Oauth2TokenResult invalid value: -1
   ```
   
   or an invalid URL like `my-issuer-url`, the output became:
   
   ```
   2021-10-11 18:02:59.456 ERROR [0x102eb2e00] AuthOauth2:222 | Response failed 
for getting the well-known configuration my-issuer-url. Error Code 6
   ...
   libc++abi.dylib: terminating with uncaught exception of type 
std::runtime_error: ExpiresIn in Oauth2TokenResult invalid value: -1
   zsh: abort      ./examples/SampleProducer
   ```
   
   **Expected behavior**
   If the authentication failed, the method of `Client`, like `createProducer`, 
should return a `ResultConnectError` instead of segmentation fault.
   
   **Desktop (please complete the following information):**
    - OS: macOS Big Sur 11.2
    - Apple clang version 12.0.0 (clang-1200.0.32.21)
    - Target: x86_64-apple-darwin20.3.0
   
   **Additional context**
   Add any other context about the problem here.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to