This module provides Keycloak integration for Sarama.
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.
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,
)