Skip to content

feat: add support for OAUTHBEARER token refresh callback#5

Merged
antaljanosbenjamin merged 2 commits intoClickHouse:ClickHouse/release-0.4.1from
kalavt:ClickHouse/release-0.4.1
Mar 2, 2026
Merged

feat: add support for OAUTHBEARER token refresh callback#5
antaljanosbenjamin merged 2 commits intoClickHouse:ClickHouse/release-0.4.1from
kalavt:ClickHouse/release-0.4.1

Conversation

@kalavt
Copy link

@kalavt kalavt commented Feb 5, 2026

This PR extends cppkafka::Configuration to support the sasl.oauthbearer.token.refresh.cb callback provided by librdkafka.

Motivation Mechanisms like AWS_MSK_IAM or generic OAUTHBEARER require the client to dynamically generate and refresh tokens when they expire. librdkafka handles this via a callback that requests a new token. Previously, cppkafka did not expose this callback, making it impossible to implement custom OAuth logic (like AWS SigV4 signing) purely in C++ without bypassing the wrapper.

Changes

  • API: Added Configuration::set_oauthbearer_token_refresh_callback which accepts a std::function.
  • Implementation: Implemented a proxy function oauthbearer_token_refresh_callback_proxy that correctly bridges the C-style librdkafka callback to the C++ function, properly casting the opaque handle.
  • Documentation: Added docs/oauth_bearer_callback.md explaining how to use the new feature.
  • Example: Added examples/oauth_example.cpp demonstrating a basic implementation.

Usage Example

config.set_oauthbearer_token_refresh_callback([](KafkaHandleBase& handle, const std::string& config) {
    // Generate token...
    rd_kafka_oauthbearer_set_token(handle.get_handle(), token_str.c_str(), expiry, ...);
});

This change is required for integrating AWS MSK IAM Authentication into ClickHouse.

@kalavt
Copy link
Author

kalavt commented Feb 5, 2026

@antaljanosbenjamin for your review to address the comments
ClickHouse/ClickHouse#91118 (comment)

Copy link
Member

@antaljanosbenjamin antaljanosbenjamin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from this small change, the PR looks good. One question remains: do you mind also submitting the same PR to the upstream project or should I do that once this is merged?

The reason is we like to contribute back and it also help us keep our fork closer to the upstream one.

Change the oauthbearer_config parameter from 'const std::string&' to
'const std::string*' to maintain semantic consistency with librdkafka.

This allows the callback to distinguish between:
- Config not set (nullptr)
- Config set to empty string ('')

Updated files:
- include/cppkafka/configuration.h: Changed callback signature
- src/configuration.cpp: Modified proxy to pass nullptr instead of empty string
- examples/oauth_example.cpp: Updated example to check for nullptr
- docs/oauth_bearer_callback.md: Updated all documentation and examples

Addresses PR review comment from antaljanosbenjamin.
@kalavt
Copy link
Author

kalavt commented Mar 1, 2026

@antaljanosbenjamin are we all good for this MR?

@antaljanosbenjamin antaljanosbenjamin merged commit ee62c51 into ClickHouse:ClickHouse/release-0.4.1 Mar 2, 2026
@antaljanosbenjamin
Copy link
Member

We are good to go. Could you please also open an upstream PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants