I am trying to authenticate using an XMPP server using SASL.
function authenticate($username, $password) {
$this->username = $username;
$this->password = $password;
var_dump($username, $password, $this->domain);
$auth = base64_encode($username.'@'.$this->domain."\u0000".$username."\u0000".$password);
$xml = '<auth mechanism="PLAIN" xmlns="urn:ietf:params:xml:ns:xmpp-sasl">'.$auth.'</auth>';
if ($this->write($xml)) {
if ($xml = $this->listen(1, true)) {
if (preg_match("/<success/i", $xml)) {
$this->authenticated = $this->_sendStream();
}
}
}
$this->events->trigger('authenticate', $this->authenticated);
return $this->authenticated;
}
However, the XMPP server responds:
<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><bad-protocol/></failure>
This is against the Ejabberd server. When I open the XMPP stream, it advertises:
<stream:features><starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism></mechanisms><register xmlns='http://jabber.org/features/iq-register'/></stream:features>
So, it seems to me that SASL-PLAIN should work. I have a version of JavaScript that works fine on an OpenFire server. (I can't check this on Ejabberd at the moment)
sendAuthentication: function() {
clearTimeout(XMPP.sendAuthentication_timer);
var auth = Base64.encode(XMPP.username+'@'+XMPP.domain+'\u0000'+XMPP.username+'\u0000'+XMPP.password);
mySocket.events.receive.observe(XMPP.receivedAuthSuccess, function() {
mySocket.send('<auth mechanism="PLAIN" xmlns="urn:ietf:params:xml:ns:xmpp-sasl">' + auth + '</auth>');
});
}
Therefore, I cannot understand why the version of PHP is not working.
source
share