Search code examples
phpxmppejabberd

unregister ejabbered user with fabiang php


i use fabiang php example (https://github.com/fabiang/xmpp/blob/master/example.php) to successfully register new user. but when I try remove command it fails with

<error code='405' type='cancel'><not-allowed xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/><text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>The query is only allowed from local users</text></error>

I noticed I can register new user even if Im not logged in, so I suspect my authentication is not working as expected for remove. How to use fabiang to authenticate with sha1?

I can unregister from android app with sha1 auth without problem.


Solution

  • I figured it out, in order to unregister user, you have to be logged in as that user (while for register you have to be logged in as admin).

    $this->implementation = new Implementation($withAuthentication);
    $this->options = new \Fabiang\Xmpp\Options('tcp://...');
    $this->options->setImplementation($this->implementation);
    $this->options->setLogger($this->logger)
      ->setUsername($xmppuser)
      ->setPassword($xmpppass)
      ->setTimeout(self::XMPP_TIMEOUT);
    
    $this->client = new \Fabiang\Xmpp\Client($this->options);
    
    $listener = new UnRegistrationListener();
    $unRegistrationObj = new UnRegistration();
    
    $this->client->connect();
    $this->implementation->registerListener($listener);
    $this->client->send($unRegistrationObj);
    $this->client->disconnect();
    

    and unregister message from ProtocolImplementationInterface looks like this:

    public function toString()
    {
    return \Fabiang\Xmpp\Util\XML::quoteMessage(
      "<iq id='%s' type='set'><query xmlns='jabber:iq:register'><remove></remove></query></iq>",
      \Fabiang\Xmpp\Util\XML::generateId()
    );
    }