Skip to content

Commit b0fe3db

Browse files
committed
Support PLAIN authentication mechanism.
1 parent 4842701 commit b0fe3db

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

Diff for: src/Bunny/AbstractClient.php

+18-10
Original file line numberDiff line numberDiff line change
@@ -350,18 +350,26 @@ protected function write()
350350
*/
351351
protected function authResponse(MethodConnectionStartFrame $start)
352352
{
353-
if (strpos($start->mechanisms, "AMQPLAIN") === false) {
354-
throw new ClientException("Server does not support AMQPLAIN mechanism (supported: {$start->mechanisms}).");
353+
if (strpos($start->mechanisms, "AMQPLAIN") !== false) {
354+
$responseBuffer = new Buffer();
355+
$this->writer->appendTable([
356+
"LOGIN" => $this->options["user"],
357+
"PASSWORD" => $this->options["password"],
358+
], $responseBuffer);
359+
$responseBuffer->discard(4);
360+
361+
return $this->connectionStartOk([], "AMQPLAIN", $responseBuffer->read($responseBuffer->getLength()), "en_US");
362+
} else if (strpos($start->mechanisms, "PLAIN") !== false) {
363+
$responseBuffer = new Buffer();
364+
$responseBuffer->appendUint8(0);
365+
$responseBuffer->append($this->options["user"]);
366+
$responseBuffer->appendUint8(0);
367+
$responseBuffer->append($this->options["password"]);
368+
369+
return $this->connectionStartOk([], "PLAIN", $responseBuffer->read($responseBuffer->getLength()), "en_US");
355370
}
356371

357-
$responseBuffer = new Buffer();
358-
$this->writer->appendTable([
359-
"LOGIN" => $this->options["user"],
360-
"PASSWORD" => $this->options["password"],
361-
], $responseBuffer);
362-
$responseBuffer->discard(4);
363-
364-
return $this->connectionStartOk($this->options['client_properties'], "AMQPLAIN", $responseBuffer->read($responseBuffer->getLength()), "en_US");
372+
throw new ClientException("Server does not support either AMQPLAIN or PLAIN mechanism (supported: {$start->mechanisms}).");
365373
}
366374

367375
/**

0 commit comments

Comments
 (0)