Dear all,

I am experiencing a problem with a custom credential checker for twisted cred 
based on an external server.

    @defer.inlineCallbacks
    def requestAvatarId(self, credentials):
        user = <query external server with credentials>
        try:
            # Check password with external server, raises InvalidCredentials 
error
        # if successful return user entry
        user_entry = yield checkCredentialsWithExternalServer(user, 
credentials.password)
            defer.returnValue(user_entry)
        except InvalidCredentials:
            self.log.debug("Invalid password for username {user}", 
user=user_entry.dn.getText())
            
defer.returnValue(Failure(error.UnauthorizedLogin("username/password is 
wrong")))

My problem is, that the Failure in the last line does not trigger the Errback 
of the deferred of the calling method to signal that the login failed.

I also tried to raise the error but this does not work for me. I also tried to 
return a defer.fail(error.UnauthorizedLogin()).

This is what the requestAvatarID method documentation 
(https://github.com/twisted/twisted/blob/f9e12bd88618682f7cdba342fbaea1212073533f/src/twisted/cred/checkers.py#L26)
 says about the return value

        @return: a Deferred which will fire a string which identifies an
        avatar, an empty tuple to specify an authenticated anonymous user
        (provided as checkers.ANONYMOUS) or fire a Failure(UnauthorizedLogin).
        Alternatively, return the result itself.

I am now a bit puzzled that it could be problematic, because the 
@inlineCallbacks decorator makes the function itself return a deferred already. 
It would be great to have an inlineCallbacked method as getAvatarID method, 
because I am doing some networking calls in it which are all returning 
deferreds.

Do I have to rewrite the getAvatarID implementation to not use inlineCallbacks?

Any help is appreciated,
Thomas
_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to