[Twisted-Python] How to do basic authentication on twisted web

Reza Lotun rlotun at gmail.com
Mon Aug 17 06:13:32 EDT 2009


Hi Colin,

> Where is Portal and SimpleRealm in your example? Those are actually quite
> large constructs which are crucial to guard doing anything useful at all.

Sorry, this snippet of code I wrote tracked the webguard.py example
that I linked to.

from twisted.cred.portal import IRealm, Portal

class SimpleRealm(object):
    """
    A realm which gives out L{GuardedResource} instances for authenticated
    users.
    """
    implements(IRealm)

    def requestAvatar(self, avatarId, mind, *interfaces):
        if resource.IResource in interfaces:
            return resource.IResource, GuardedResource(), lambda: None
        raise NotImplementedError()

Does that make sense now?

> Since there are numerous circumstances that people need Htauth, it is
> implemented as follows

Ok, of course you can do that if you want. But you still need to be
able to *verify* credentials.

Anyway, to each their own.

Reza



-- 
Reza Lotun
mobile: +44 (0)7521 310 763
email:  rlotun at gmail.com
work:   reza at tweetdeck.com
twitter: @rlotun



More information about the Twisted-Python mailing list