Skip to content

Keycloak auth provider for Sarama

Notifications You must be signed in to change notification settings

ozonru/sarama-keycloak

Repository files navigation

sarama-keycloack

This module provides Keycloak integration for Sarama.

How it works

Sarama supports SASL/OAUTHBEARER authentication mechanism, but to use it with Keycloak it's required to implement AccessTokenProvider interface.

Provider is responsible for fetching and refreshing access tokens.

How to use?

providerConfig := saramakeycloak.Config{
    KeycloackHostPort: "https://keycloak.host",
    ClientID:          "<client-id>",
    ClientSecret:      "<client-secret>",
    Realm:             "<realm>",
}

provider, _ := saramakeycloak.New(providerConfig)


config := sarama.NewConfig()
// ...
config.Net.SASL.Enable = true
config.Net.SASL.Mechanism = sarama.SASLTypeOAuth
config.Net.SASL.TokenProvider = provider

producer, err := sarama.NewSyncProducer(
    []string{
        "broker1.host:9092",
        "broker2.host:9092",
        "broker3.host:9092",
    },
    config,
)

Releases

No releases published

Packages

No packages published

Languages