View Source KafkaEx.Auth.SASL (kafka_ex v0.15.0)
SASL authentication orchestrator for KafkaEx.
Coordinates the SASL authentication flow:
- Fetches API versions (if supported by Kafka version)
- Performs SASL handshake to negotiate mechanism
- Executes mechanism-specific authentication
- Manages packet mode switching between raw and length-prefixed
Entry Point
The authenticate/2 function is called by NetworkClient immediately
after socket creation when auth configuration is present.
Version Compatibility
- Kafka 0.9.x - Skips API versions call (not supported)
- Kafka 0.10.0+ - Queries API versions for optimal protocol selection
- Kafka 0.10.2+ - Full SCRAM support available
Internal Flow
- Check if API versions should be fetched (based on Kafka version)
- Send handshake request with desired mechanism
- Delegate to mechanism module for authentication exchange
- Return
:okor{:error, reason}to NetworkClient
Compatibility
Brokers does not tell you the header mode (legacy vs flexible). Some stacks (older IBP, ZK builds, or auth/proxy layers) still map (apiKey=36, ver=2) to header v1 internally, so we cap at v1 for authentication request.
Another option would be to try v2 and fallback to v1 if we meet such broker.
Summary
Functions
@spec authenticate(KafkaEx.Socket.t(), KafkaEx.Auth.Config.t()) :: :ok | {:error, term()}