This package is intended to be used as a complement to Shopify/sarama. It provides an implementation of the sarama.AccessTokenProvider
interface to be employed by clients using the SASL/OAUTHBEARER mechanism for Apache Kafka.
The very popular golang/oauth2
and golang/oauth2/clientcredentials
are leveraged to perform the 2 legged client credentials flow to obtain an Access Token outside the context of a user.
go get github.com/damiannolan/sasl/oauthbearer
Configure sarama.Config
as desired for producer/consumer clients and enable SASL/OAUTHBEARER with the appropriate settings. For production setups it is recommended to use this authentication mechanism over a secure connection. This can be achieved by setting Net.TLS.Enable
to true
and providing a *tls.Config
through Net.TLS.Config
.
import (
"github.com/Shopify/sarama"
"github.com/damiannolan/sasl/oauthbearer"
)
func main() {
cfg := sarama.NewConfig()
cfg.Net.SASL.Enable = true
cfg.Net.SASL.Mechanism = sarama.SASLTypeOAuth
cfg.Net.SASL.TokenProvider = oauthbearer.NewTokenProvider(clientID, clientSecret, tokenURL)
...
}