1 import binascii
2
3 from paste.httpheaders import WWW_AUTHENTICATE
4 from paste.httpheaders import AUTHORIZATION
5 from paste.httpexceptions import HTTPUnauthorized
6
7 from zope.interface import implements
8
9 from repoze.who.interfaces import IIdentifier
10 from repoze.who.interfaces import IChallenger
11
13
14 implements(IIdentifier, IChallenger)
15
18
19
21 authorization = AUTHORIZATION(environ)
22 try:
23 authmeth, auth = authorization.split(' ', 1)
24 except ValueError:
25 return None
26 if authmeth.lower() == 'basic':
27 try:
28 auth = auth.strip().decode('base64')
29 except binascii.Error:
30 return None
31 try:
32 login, password = auth.split(':', 1)
33 except ValueError:
34 return None
35 auth = {'login':login, 'password':password}
36 return auth
37
38 return None
39
40
45
47 head = WWW_AUTHENTICATE.tuples('Basic realm="%s"' % self.realm)
48 return head
49
50
51 - def forget(self, environ, identity):
53
54
55 - def challenge(self, environ, status, app_headers, forget_headers):
56 head = self._get_wwwauth()
57 if head[0] not in forget_headers:
58 head = head + forget_headers
59 return HTTPUnauthorized(headers=head)
60
62 return '<%s %s>' % (self.__class__.__name__,
63 id(self))
64
68