View Source KafkaEx.Auth.Mechanism behaviour (kafka_ex v0.15.0)

Behaviour for SASL authentication mechanisms.

Each mechanism must implement:

  • mechanism_name/1 - Returns the mechanism name for SASL handshake
  • authenticate/2 - Performs the authentication exchange

Built-in Implementations

Extending Authentication

To implement a custom mechanism:

defmodule MyAuth do @behaviour KafkaEx.Auth.Mechanism

@impl true def mechanism_name(_config), do: "OAUTHBEARER"

@impl true def authenticate(config, send_fun) do

# Exchange authentication messages with broker
# using send_fun to send and receive data
:ok

end end

Summary

Callbacks

Performs the authentication exchange after handshake.

Returns mechanism name for handshake.

Types

@type auth_opts() :: KafkaEx.Auth.Config.t()
@type send_fun() :: (binary() -> {:ok, binary() | nil} | {:error, term()})

Callbacks

Link to this callback

authenticate(auth_opts, send_fun)

View Source
@callback authenticate(auth_opts(), send_fun()) :: :ok | {:error, term()}

Performs the authentication exchange after handshake.

Link to this callback

mechanism_name(auth_opts)

View Source
@callback mechanism_name(auth_opts()) :: String.t()

Returns mechanism name for handshake.