Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support PLAIN auth mechanism. #156

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions src/Bunny/AbstractClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}).");
}

/**
Expand Down
Loading