ruby-amqp/amq-client — pull request #21 by zobar (2012-12-06 04:19:01+00:00)
Title: Support additional SASL auth mechanisms

My broker requires me to connect over SSL using the EXTERNAL authentication mechanism, which uses credentials from the SSL client certificate. As it stands, amq-client is hard-wired to use PLAIN authentication, which sends the password in cleartext.

I propose adding an `:auth_mechanism` option to `AMQP::Client::Async::EventMachineClient#connect` which would allow users of this gem to override the SASL authentication mechanism if needed. Both "PLAIN" and "EXTERNAL" will be recognized, defaulting to "PLAIN" to maintain backwards compatibility.

I also propose a simple way for users of this gem to implement additional auth mechanisms should the need arise, without resorting to monkey-patching. Subclasses of `AMQ::Client::Async::AuthMechanismHelper` can register to handle credentials for arbitrary mechanisms like so:

```ruby
class MyAuthMechanism < AMQ::Client::Async::AuthMechanismHelper
auth_mechanism "X-MYAUTH"

def encode_credentials(username, password)
# ...
end
end
```