protocol
(type:
str
)
'http auth'
realm
(type:
str
)
'Zope'
challenge(request)
Issues an HTTP basic auth challenge for credentials.
The challenge is issued by setting the appropriate response headers. To illustrate, we'll create a plugin:
>>> plugin = HTTPBasicAuthCredentialsPlugin()
The plugin adds its challenge to the HTTP response.
>>> from zope.publisher.browser import TestRequest >>> request = TestRequest() >>> response = request.response >>> plugin.challenge(request) True >>> response._status 401 >>> response.getHeader('WWW-Authenticate', literal=True) 'basic realm="Zope"'
Notice that the realm is quoted, as per RFC 2617.
The plugin only works with HTTP requests.
>>> from zope.publisher.base import TestRequest >>> request = TestRequest('/') >>> response = request.response >>> print plugin.challenge(request) False
extractCredentials(request)
Extracts HTTP basic auth credentials from a request.
First we need to create a request that contains some credentials.
>>> from zope.publisher.browser import TestRequest >>> request = TestRequest( ... environ={'HTTP_AUTHORIZATION': u'Basic bWdyOm1ncnB3'})
Now create the plugin and get the credentials.
>>> plugin = HTTPBasicAuthCredentialsPlugin() >>> plugin.extractCredentials(request) {'login': u'mgr', 'password': u'mgrpw'}
Make sure we return None, if no authentication header has been specified.
>>> print plugin.extractCredentials(TestRequest()) None
Also, this plugin can only handle basic authentication.
>>> request = TestRequest(environ={'HTTP_AUTHORIZATION': 'foo bar'}) >>> print plugin.extractCredentials(TestRequest()) None
This plugin only works with HTTP requests.
>>> from zope.publisher.base import TestRequest >>> print plugin.extractCredentials(TestRequest('/')) None
logout(request)
Always returns False as logout is not supported by basic auth.
>>> plugin = HTTPBasicAuthCredentialsPlugin() >>> from zope.publisher.browser import TestRequest >>> plugin.logout(TestRequest()) False
There are no known subclasses.