View Source KafkaEx.Auth.SASL.OAuthBearer (kafka_ex v1.0.0-rc.1)

SASL/OAUTHBEARER mechanism for Kafka (KIP-255, KIP-342).

Configuration

KafkaEx.Auth.Config.new(%{
  mechanism: :oauthbearer,
  mechanism_opts: %{
    token_provider: fn -> {:ok, "jwt-token"} end,
    extensions: %{"traceId" => "abc123"}  # optional, KIP-342
  }
})

Token Provider

The token_provider is a 0-arity function returning:

  • {:ok, token} - JWT token string
  • {:error, reason} - failure

The provider is called on each new connection and is responsible for caching and refreshing tokens.