1 # -*- test-case-name: twisted.web.test.test_httpauth -*-
2 # Copyright (c) Twisted Matrix Laboratories.
3 # See LICENSE for details.
6 Implementation of RFC2617: HTTP Digest Authentication
8 @see: U{http://www.faqs.org/rfcs/rfc2617.html}
11 from zope.interface import implements
12 from twisted.cred import credentials
13 from twisted.web.iweb import ICredentialFactory
15 class DigestCredentialFactory(object):
17 Wrapper for L{digest.DigestCredentialFactory} that implements the
18 L{ICredentialFactory} interface.
20 implements(ICredentialFactory)
24 def __init__(self, algorithm, authenticationRealm):
26 Create the digest credential factory that this object wraps.
28 self.digest = credentials.DigestCredentialFactory(algorithm,
32 def getChallenge(self, request):
34 Generate the challenge for use in the WWW-Authenticate header
36 @param request: The L{IRequest} to with access was denied and for the
37 response to which this challenge is being generated.
39 @return: The C{dict} that can be used to generate a WWW-Authenticate
42 return self.digest.getChallenge(request.getClientIP())
45 def decode(self, response, request):
47 Create a L{twisted.cred.digest.DigestedCredentials} object from the
48 given response and request.
50 @see: L{ICredentialFactory.decode}
52 return self.digest.decode(response,
54 request.getClientIP())