1

As the question says, how can I do it? following is the code-

import logging
from sleekxmpp import ClientXMPP

logging.basicConfig(level=logging.DEBUG, format='%(levelname)-8s %(message)s')


def on_session(event):
    xmpp.get_roster()

xmpp = ClientXMPP(jid, password)
xmpp.add_event_handler('session_start', on_session)
if xmpp.connect():
    print xmpp.authenticated  # Always prints `False`
    xmpp.process(block=True)

I can see that printing in the logs, but I rather want to check it in the code as well. How can I do it?

Praful Bagai
  • 16,684
  • 50
  • 136
  • 267

1 Answers1

2

In XMPP, the authentication is handled by SASL which usually starts once the client is connected.

In your case, mere connection success doesn't imply that authentication was done. You need to put event handler for SASL authentication success and failure cases. Going through the sleekxmpp events, it makes me believe that it can be done by monitoring auth_success and failed_auth events. Possible code will be :

xmpp.add_event_handler("failed_auth", on_failed_auth)
xmpp.add_event_handler("auth_success", on_auth_success)
manishg
  • 9,520
  • 1
  • 16
  • 19
  • Thanks @Manishg for bringing this up. Didnt know this. I can now combine your answer with http://stackoverflow.com/questions/9815422/sleekxmpp-threaded-authentication?rq=1 to solve my use case. – Praful Bagai Mar 01 '17 at 07:21
  • BTW what all events are there in SleekXMPP? Is there any wiki for the same? Would like to know all the events. Thans – Praful Bagai Mar 01 '17 at 07:22
  • Also, it will be helpful if you can provide your expertise in http://stackoverflow.com/questions/42485797/xmpp-roster-subscription-explaination – Praful Bagai Mar 01 '17 at 07:32
  • I didn't find any wiki describing this info. It was my observation through the SASL code they wrote. I think XMPP basics will help here but I might be wrong. I will check the other question. – manishg Mar 01 '17 at 21:55