[improve][client] Implement tls_client_auth for AuthOauth2 #575
Open
izumo27 wants to merge 3 commits into
Open
[improve][client] Implement tls_client_auth for AuthOauth2 #575izumo27 wants to merge 3 commits into
izumo27 wants to merge 3 commits into
Conversation
izumo27
commented
May 11, 2026
Comment on lines
+544
to
+546
| * For `tokenEndpointAuthMethod = "client_secret_post"` (default), the required parameter | ||
| * keys are “issuer_url”, “private_key”, and “audience”. | ||
| * Optional keys: `scope`, `tls_cert_file`, `tls_key_file`. |
Contributor
Author
There was a problem hiding this comment.
Although the RFC defines audience as an optional parameter, it remains required for client_secret_post to avoid a breaking change.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds OAuth2 tls_client_auth support to the C++ client, including mTLS client cert/key configuration, shared TLS/token retrieval logic, and new E2E-style tests using a local mock TLS server.
Changes:
- Implement
TlsClientAuthFlowand select OAuth2 flow bytokenEndpointAuthMethod. - Refactor token endpoint discovery and token fetching into shared helpers with TLS context handling.
- Add mock TLS OAuth2 server + tests for success/failure paths; update public API docs.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
| tests/AuthPluginTest.cc | Adds a mock TLS OAuth2 server and new tests for tls_client_auth behavior. |
| lib/auth/AuthOauth2.h | Introduces TlsClientAuthFlow and adds mTLS-related fields to flows. |
| lib/auth/AuthOauth2.cc | Implements flow selection, shared well-known/token fetching, and TLS context creation. |
| include/pulsar/Authentication.h | Documents tokenEndpointAuthMethod and the new tls_client_auth parameters. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+574
to
+576
| const std::string response = "HTTP/1.1 200 OK\nContent-Type: " + responseContentType_ + | ||
| "\nContent-Length: " + std::to_string(responseBody_.size()) + | ||
| "\nConnection: close\n\n" + responseBody_; |
Comment on lines
+824
to
+825
| ASSERT_TRUE(wellKnownFuture.get()); | ||
| ASSERT_TRUE(tokenFuture.get()); |
Comment on lines
+829
to
+830
| wellKnownThread.join(); | ||
| tokenThread.join(); |
Comment on lines
+244
to
+263
| static std::unique_ptr<CurlWrapper::TlsContext> createTlsContext(const std::string& tlsTrustCertsFilePath, | ||
| const std::string& tlsCertFilePath, | ||
| const std::string& tlsKeyFilePath, | ||
| OAuth2TokenEndpointAuthMethod authMethod) { | ||
| if (tlsTrustCertsFilePath.empty() && tlsCertFilePath.empty() && tlsKeyFilePath.empty()) { | ||
| return nullptr; | ||
| } | ||
|
|
||
| void ClientCredentialFlow::initialize() { | ||
| if (issuerUrl_.empty()) { | ||
| LOG_ERROR("Failed to initialize ClientCredentialFlow: issuer_url is not set"); | ||
| return; | ||
| auto tlsContext = std::unique_ptr<CurlWrapper::TlsContext>(new CurlWrapper::TlsContext); | ||
| if (!tlsTrustCertsFilePath.empty()) { | ||
| tlsContext->trustCertsFilePath = tlsTrustCertsFilePath; | ||
| } | ||
| if (!keyFile_.isValid()) { | ||
| return; | ||
| if (!tlsCertFilePath.empty() && !tlsKeyFilePath.empty()) { | ||
| tlsContext->certPath = tlsCertFilePath; | ||
| tlsContext->keyPath = tlsKeyFilePath; | ||
| } else if (authMethod == OAuth2TokenEndpointAuthMethod::TlsClientAuth) { | ||
| LOG_WARN("Ignore incomplete mTLS settings: both tls_cert_file and tls_key_file are required"); | ||
| } | ||
| return tlsContext; | ||
| } |
Comment on lines
338
to
341
| if (!result.error.empty()) { | ||
| LOG_ERROR("Failed to get the well-known configuration " << issuerUrl_ << ": " << result.error); | ||
| return; | ||
| LOG_ERROR("Failed to get the well-known configuration " << issuerUrl << ": " << result.error); | ||
| return resultPtr; | ||
| } |
Comment on lines
+358
to
+360
| LOG_ERROR("Failed to parse json of Oauth2 response: " | ||
| << e.what() << "\nInput Json = " << responseData | ||
| << " passedin: " << options.postFields); |
Comment on lines
+377
to
+378
| LOG_ERROR("Response failed for issuerurl " << issuerUrl << ". response Code " << responseCode | ||
| << " passedin: " << options.postFields); |
Comment on lines
+382
to
+383
| LOG_ERROR("Response failed for issuerurl " << issuerUrl << ". ErrorCode " << res << ": " | ||
| << errorBuffer << " passedin: " << options.postFields); |
Comment on lines
520
to
521
| * "client_id": "d9ZyX97q1ef8Cr81WHVC4hFQ64vSlDK3", | ||
| * "client_secret": "on1uJ...k6F6R", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Currently, AuthOauth2 supports only
client_secret_post.This PR adds
tls_client_auth.cf. apache/pulsar#25538
Modifications
tls_cert_fileandtls_key_file, and make these two parameters required when usingtls_client_auth.Verifying this change
(Please pick either of the following options)
This change added tests and can be verified as follows:
Documentation
doc-required(Your PR needs to update docs and you will update later)
doc-not-needed(Please explain why)
doc(Your PR contains doc changes)
doc-complete(Docs have been already added)