Last active
August 29, 2015 14:17
-
-
Save adiroiban/9ee8e29af3193a258f68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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