I'm subclassing WampCraServerProtocol
(from Autobahn Python) and overriding getAuthSecret
. I understand that now I can return a deferred from that method, however, when doing a simple test:
def getAuthSecret(self, authKey):
deferred = Deferred()
deferred.callback("secret")
return deferred
... I get the following error on my WampCraClientProtocol
:
Authentication Error! http://api.wamp.ws/error#generic Deferred instance has no attribute '__len__' None
Ok, that alone is confusing already. Are there special requirements over the deferred that getAuthSecret
returns?
Ok, moving on, based on that error, I added a (trivial) len method to the deferred I'm returning:
def getAuthSecret(self, authKey):
#secret_deferred = self.factory.get_secret(authKey)
deferred = Deferred()
deferred.__len__ = lambda: 1
deferred.callback("secret")
return deferred
... in that case, I get:
Authentication Error! http://api.wamp.ws/error#generic unsupported operand type(s) for +: 'instance' and 'str' None
That confuses me even more. I just want to know the correct way to return a deferred from that method. (I should note that everything works perfectly if a return a plain simple string). Thanks.
This works for me:
https://github.com/tavendo/AutobahnPython/blob/master/examples/wamp/authentication/server.py#L72
What AutobahnPython version are you using?
Update:
v0.5.9 has a bug regarding deferred based authentication (see comments below). It was fixed on v0.5.14. Wamp Cra deferred based authentication works fine on that version.