fritzy / SleekXMPP

Python 2.6+/3.1+ XMPP Library
http://groups.google.com/group/sleekxmpp-discussion
Other
1.1k stars 299 forks source link

Custom auth mechanism #222

Closed alexander-akhmetov closed 11 years ago

alexander-akhmetov commented 11 years ago

Hi, I am using SleexXMPP version 1.1.11. I'm trying to login to the server push.xmpp.yandex.ru ( http://api.yandex.com/disk/doc/dg/concepts/xmpp_xmpp-connection.xml ):


DEBUG    SEND (IMMED): <stream:stream to='ya.ru' xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' xml:lang='en' version='1.0'>
DEBUG    RECV: <stream:stream version="1.0" from="ya.ru" id="3603340553" xml:lang="en">
DEBUG    RECV: <stream:features xmlns="http://etherx.jabber.org/streams"><compression xmlns="http://jabber.org/features/compress"><method>zlib</method></compression><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>X-YANDEX-OAUTH</mechanism></mechanisms></stream:features>
ERROR    No appropriate login method.
DEBUG    SEND (IMMED): </stream:stream>
INFO     Waiting for </stream:stream> from server
DEBUG    End of stream recieved
DEBUG    Waiting for 3 threads to exit.
DEBUG    Threading deadlock prevention!
DEBUG    Marked event_thread_0 thread as ended due to disconnect() call. 2 threads remain.
DEBUG    Quitting Scheduler thread
DEBUG    Stopped scheduler thread. 1 threads remain.
DEBUG    Stopped send thread. 0 threads remain.
DEBUG     ==== TRANSITION connected -> disconnected
DEBUG    Finished processing stream features.
DEBUG    Finished exiting event runner thread after early termination from disconnect() call. 0 threads remain.
DEBUG    State was not ready

The server supports only one type of authentication - X-YANDEX-OAUTH. I tried to do this by passing a parameter sasl_mech='X-YANDEX-OAUTH' in the constructor ClientXMPP, but it's not work. Can somebody tell how to use a custom authentication type?

I'm new to Python and XMPP, and sorry for my bad English :)

legastero commented 11 years ago

Here's how to create a new SASL mechanism, based on the docs you linked:

from sleekxmpp.util.sasl import sasl_mech, Mech

@sasl_mech(3)
class X_YANDEX_OAUTH(Mech):
    name = 'X-YANDEX-OAUTH'
    required_credentials = set(['username', 'access_token'])

    def process(self, challenge=b''):
        user = self.credentials['username']
        token = self.credentials['access_token']
        return user + b'\x00' + token

Just be sure to import that before starting your ClientXMPP instance.

You'll also need to save your OAuth token in: your_client.credentials['access_token']

alexander-akhmetov commented 11 years ago

Thanks a lot, it works!