Skip to content

Commit 5b52e70

Browse files
committed
OAuth Azure IMDS Kafka example
1 parent 3ae9609 commit 5b52e70

File tree

7 files changed

+54
-6
lines changed

7 files changed

+54
-6
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# confluent-kafka-javascript 1.6.0
2+
3+
v1.6.0 is a feature release. It is supported for all usage.
4+
5+
### Enhancements
6+
7+
1. References librdkafka v2.12.0. Refer to the [librdkafka v2.12.0 release notes](https://github.com/confluentinc/librdkafka/releases/tag/v2.12.0) for more information.
8+
2. OAuth OIDC method example for Kafka metadata based authentication with
9+
an Azure IMDS endpoint using an attached managed identity as principal (#377).
10+
11+
112
# confluent-kafka-javascript 1.5.0
213

314
v1.5.0 is a feature release. It is supported for all usage.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const { Kafka } = require('@confluentinc/kafka-javascript').KafkaJS;
2+
3+
async function run() {
4+
const bootstrapServers = "";
5+
const azureIMDSQueryParams = "api-version=&resource=&client_id=";
6+
const kafka = new Kafka({
7+
'bootstrap.servers': bootstrapServers,
8+
'security.protocol': 'SASL_SSL',
9+
'sasl.mechanisms': 'OAUTHBEARER',
10+
'sasl.oauthbearer.method': 'oidc',
11+
'sasl.oauthbearer.metadata.authentication.type': 'azure_imds',
12+
'sasl.oauthbearer.config': `query=${azureIMDSQueryParams}`
13+
});
14+
const producer = kafka.producer();
15+
16+
await producer.connect();
17+
console.log("Producer connected");
18+
19+
const deliveryReport = await producer.send({
20+
topic: 'topic',
21+
messages: [
22+
{ value: 'Hello world!' },
23+
],
24+
});
25+
console.log("Producer sent message", deliveryReport);
26+
27+
await producer.disconnect();
28+
}
29+
30+
run().catch(console.error);

lib/error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ LibrdKafkaError.wrap = errorWrap;
2828
* @constant
2929
* @memberof RdKafka
3030
*/
31-
// ====== Generated from librdkafka 2.11.1 file src-cpp/rdkafkacpp.h ======
31+
// ====== Generated from librdkafka v2.12.0-RC2 file src-cpp/rdkafkacpp.h ======
3232
LibrdKafkaError.codes = {
3333

3434
/* Internal errors to rdkafka: */

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "@confluentinc/kafka-javascript",
33
"version": "1.5.0",
44
"description": "Node.js bindings for librdkafka",
5-
"librdkafka": "2.11.1",
6-
"librdkafka_win": "2.11.1",
5+
"librdkafka": "v2.12.0-RC2",
6+
"librdkafka_win": "v2.12.0-RC2",
77
"main": "lib/index.js",
88
"types": "types/index.d.ts",
99
"scripts": {

types/config.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ====== Generated from librdkafka 2.11.1 file CONFIGURATION.md ======
1+
// ====== Generated from librdkafka v2.12.0-RC2 file CONFIGURATION.md ======
22
// Code that generated this is a derivative work of the code from Nam Nguyen
33
// https://gist.github.com/ntgn81/066c2c8ec5b4238f85d1e9168a04e3fb
44

@@ -713,6 +713,13 @@ export interface GlobalConfig {
713713
*/
714714
"sasl.oauthbearer.assertion.jwt.template.file"?: string;
715715

716+
/**
717+
* Type of metadata-based authentication to use for OAUTHBEARER/OIDC `azure_imds` authenticates using the Azure IMDS endpoint. Sets a default value for `sasl.oauthbearer.token.endpoint.url` if missing. Configuration values specific of chosen authentication type can be passed through `sasl.oauthbearer.config`.
718+
*
719+
* @default none
720+
*/
721+
"sasl.oauthbearer.metadata.authentication.type"?: 'none' | 'azure_imds';
722+
716723
/**
717724
* List of plugin libraries to load (; separated). The library search path is platform dependent (see dlopen(3) for Unix and LoadLibrary() for Windows). If no filename extension is specified the platform-specific extension (such as .dll or .so) will be appended automatically.
718725
*/

types/errors.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ====== Generated from librdkafka 2.11.1 file src-cpp/rdkafkacpp.h ======
1+
// ====== Generated from librdkafka v2.12.0-RC2 file src-cpp/rdkafkacpp.h ======
22
export const CODES: { ERRORS: {
33
/* Internal errors to rdkafka: */
44
/** Begin internal error codes (**-200**) */

0 commit comments

Comments
 (0)