diff --git a/src/Bunny/AbstractClient.php b/src/Bunny/AbstractClient.php index f3b3524..918a3e4 100644 --- a/src/Bunny/AbstractClient.php +++ b/src/Bunny/AbstractClient.php @@ -350,18 +350,26 @@ protected function write() */ protected function authResponse(MethodConnectionStartFrame $start) { - if (strpos($start->mechanisms, "AMQPLAIN") === false) { - throw new ClientException("Server does not support AMQPLAIN mechanism (supported: {$start->mechanisms})."); + if (strpos($start->mechanisms, "AMQPLAIN") !== false) { + $responseBuffer = new Buffer(); + $this->writer->appendTable([ + "LOGIN" => $this->options["user"], + "PASSWORD" => $this->options["password"], + ], $responseBuffer); + $responseBuffer->discard(4); + + return $this->connectionStartOk([], "AMQPLAIN", $responseBuffer->read($responseBuffer->getLength()), "en_US"); + } else if (strpos($start->mechanisms, "PLAIN") !== false) { + $responseBuffer = new Buffer(); + $responseBuffer->appendUint8(0); + $responseBuffer->append($this->options["user"]); + $responseBuffer->appendUint8(0); + $responseBuffer->append($this->options["password"]); + + return $this->connectionStartOk([], "PLAIN", $responseBuffer->read($responseBuffer->getLength()), "en_US"); } - $responseBuffer = new Buffer(); - $this->writer->appendTable([ - "LOGIN" => $this->options["user"], - "PASSWORD" => $this->options["password"], - ], $responseBuffer); - $responseBuffer->discard(4); - - return $this->connectionStartOk($this->options['client_properties'], "AMQPLAIN", $responseBuffer->read($responseBuffer->getLength()), "en_US"); + throw new ClientException("Server does not support either AMQPLAIN or PLAIN mechanism (supported: {$start->mechanisms})."); } /**