Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from zope.interface import implements
from twisted.cred.portal import IRealm, Portal
from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse
from twisted.web.static import File
from twisted.web.resource import IResource
from twisted.web.guard import HTTPAuthSessionWrapper, DigestCredentialFactory
from twisted.web.server import Site
from twisted.internet import reactor
class PublicHTMLRealm(object):
implements(IRealm)
def requestAvatar(self, avatarId, mind, *interfaces):
if IResource in interfaces:
return (IResource, File("/tmp"), lambda: None)
raise NotImplementedError()
portal = Portal(
PublicHTMLRealm(),
[InMemoryUsernamePasswordDatabaseDontUse(user='pass')],
)
credentialFactory = DigestCredentialFactory("md5-sess", "localhost:8080")
resource = HTTPAuthSessionWrapper(portal, [credentialFactory])
factory = Site(resource)
print "Listening on 8080"
reactor.listenTCP(8080, factory)
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.