Skip to content

Latest commit

 

History

History
40 lines (29 loc) · 1.67 KB

README.md

File metadata and controls

40 lines (29 loc) · 1.67 KB

SASL/OAUTHBEARER Access Token Provider

Overview

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.

Installation

go get github.com/damiannolan/sasl/oauthbearer

Usage

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)
    ...
}

References