An HTTP referer credentials plugin.
Project description
A package that uses the HTTP referer header to provide credentials.
Detailed Documentation
HTTP-Referer Credentials
It is sometimes necessary to restrict access to a site by looking at the the site the user is coming from. For example, a user can only enter the site when he comes from within the corporate network. If the two sites cannot share any specific information, such as an authentication token, the only useful piece of information is the HTTP-Referer request header.
__Note__: Yes I know this is not fully secure and someone could spoof the header. But this is acceptable in this particular application. I guess it keeps away the honest. And yes, this is a real world scenario – would I implement this package otherwise? :-)
So let’s have a look at the credentials plugin:
>>> from z3c.referercredentials import credentials >>> creds = credentials.HTTPRefererCredentials()
Let’s look at the positive case first. The referer credentials plugin has an attribute that specifies all allowed hosts:
>>> creds.allowedHosts ('localhost',)
In this example, we only want to allow peopl eto the site coming from www.zope.org.
>>> creds.allowedHosts = ('www.zope.org',)
Now, a user coming from that site will have a request containing this referer:
>>> from zope.publisher.browser import TestRequest >>> request = TestRequest(HTTP_REFERER='http://www.zope.org/index.html')
The credentials can now be extracted as follows:
>>> creds.extractCredentials(request)
Nothing is returned. This is because we have not defined any credentials that represent the “referer user”. With setting the credentials, it should work:
>>> creds.credentials = {'login': 'mgr', 'password': 'mgrpw'} >>> creds.extractCredentials(request) {'login': 'mgr', 'password': 'mgrpw'}
Once an acceptable referer has been passed in, the credentials are always returned:
>>> del request._environ['HTTP_REFERER'] >>> creds.extractCredentials(request) {'login': 'mgr', 'password': 'mgrpw'}
We have to log out in order to loose the credentials:
>>> creds.logout(request) True
Now, no credentials are returned when not sending in a correct referer:
>>> creds.extractCredentials(request)
When the user could not be authenticated, the plugin is asked to pose a challenge:
>>> creds.challenge(request) True >>> request.response.getHeader('Redirect')
By default we are getting the “unauthorized.html” view on the site. But you can change the view name:
>>> creds.challengeView = 'challenge.html' >>> creds.challenge(request) True >>> request.response.getHeader('Redirect')
Final Note: Of course, this credentials plugin only works with HTTP-based requests:
>>> request = object()>>> creds.extractCredentials(request)>>> creds.challenge(request) False>>> creds.logout(request) False
CHANGES
Version 0.1.0 (6/??/2007)
Initial Release
Implementation of HTTP-Referer credentials plugin
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file z3c.referercredentials-0.1.0.tar.gz
.
File metadata
- Download URL: z3c.referercredentials-0.1.0.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f92a9708c1947abcf2f67538a7ab23a64483530b2df8317315b3b61e2f2a4267 |
|
MD5 | 509db8c0d335f52f7fdcbbc7d89ea124 |
|
BLAKE2b-256 | 3637fc3e10731b274a54c7836e887c48d0b6b66aa89e797272e21b036140aa66 |
File details
Details for the file z3c.referercredentials-0.1.0-py2.4.egg
.
File metadata
- Download URL: z3c.referercredentials-0.1.0-py2.4.egg
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64ff1c24e1ff3bb5232a42b6a3da2c38055020c59e005627d879a391cb39c87c |
|
MD5 | bc7f7ecf99b27725ae5dd048f6165e48 |
|
BLAKE2b-256 | 3ce6de22fe1971625d8ccdc79902432c9b40dead98d2bd3c8a754523ea193aa0 |