Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Kerberos authentication for Twisted

Project Description


Kerberos authentication for Twisted

import os
import sys

from twisted.cred.portal import IRealm, Portal
from twisted.internet import reactor
from twisted.python import log
from twisted.web import server
from twisted.web.guard import HTTPAuthSessionWrapper, BasicCredentialFactory
from twisted.web.resource import IResource, Resource

from zope.interface import implements

import authkerb

class Simple(Resource):
isLeaf = True

def render_GET(self, request):
return '<html>Hello, world!</html>'

class Realm(object):

def requestAvatar(self, avatarId, mind, *interfaces):
if IResource in interfaces:
return (IResource, Simple(), lambda: None)

raise NotImplementedError()

os.environ['KRB5_KTNAME'] = '/path/to/keytab'

negotiateChecker = authkerb.NegotiateCredentialsChecker()
basicChecker = authkerb.BasicCredentialsChecker('HTTP/', 'EXAMPLE.ORG')

portal = Portal(Realm(), [negotiateChecker, basicChecker])

negotiateFactory = authkerb.NegotiateCredentialFactory('HTTP')
basicFactory = BasicCredentialFactory('realm')

resource = HTTPAuthSessionWrapper(portal, [negotiateFactory, basicFactory])
site = server.Site(resource)

reactor.listenTCP(8080, site)

Release History

This version
History Node


Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(2.9 kB) Copy SHA256 Hash SHA256
Source None Aug 17, 2014

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Kabu Creative Kabu Creative UX & Design Google Google Cloud Servers Fastly Fastly CDN StatusPage StatusPage Statuspage DigiCert DigiCert EV Certificate