david / django-oauth (http://oauth.net/)
Support of OAuth in Django. Note that http://code.welldev.org/django-oauth-plus will use python-oauth2 if you're interested in it.
| commit 37: | cf6929353bd9 |
| parent 36: | e2acef365281 |
| branch: | default |
Do not restrict callback url scheme and add a setting to blacklist some callback url hostnames. Thanks Toby White.
11 months ago
Changed (Δ336 bytes):
raw changeset »
oauth_provider/stores.py (5 lines added, 2 lines removed)
oauth_provider/tests.py (6 lines added, 1 lines removed)
Up to file-list oauth_provider/stores.py:
| … | … | @@ -2,9 +2,12 @@ from urlparse import urlparse |
2 |
2 |
|
3 |
3 |
from oauth.oauth import OAuthDataStore, OAuthError, escape |
4 |
4 |
|
5 |
from django.conf import settings |
|
6 |
||
5 |
7 |
from models import Nonce, Token, Consumer, Resource, generate_random |
6 |
8 |
from consts import VERIFIER_SIZE, MAX_URL_LENGTH, OUT_OF_BAND |
7 |
9 |
|
10 |
OAUTH_BLACKLISTED_HOSTNAMES = getattr(settings, 'OAUTH_BLACKLISTED_HOSTNAMES', []) |
|
8 |
11 |
|
9 |
12 |
class DataStore(OAuthDataStore): |
10 |
13 |
"""Layer between Python OAuth and Django database.""" |
| … | … | @@ -110,6 +113,6 @@ def check_valid_callback(callback): |
110 |
113 |
Checks the size and nature of the callback. |
111 |
114 |
""" |
112 |
115 |
callback_url = urlparse(callback) |
113 |
return (callback_url.scheme in ['http', 'https'] |
|
114 |
and callback_url.hostname |
|
116 |
return (callback_url.scheme |
|
117 |
and callback_url.hostname not in OAUTH_BLACKLISTED_HOSTNAMES |
|
115 |
118 |
and len(callback) < MAX_URL_LENGTH) |
Up to file-list oauth_provider/tests.py:
| … | … | @@ -107,12 +107,17 @@ That is the only thing you need to docum |
107 |
107 |
in consts.py. Default is set to 16 characters for ``KEY_SIZE`` and |
108 |
108 |
``SECRET_SIZE`` and 256 characters for ``CONSUMER_KEY_SIZE``. |
109 |
109 |
|
110 |
The ``OAUTH_BLACKLISTED_HOSTNAMES`` setting allows you to restrict callback |
|
111 |
URL hostnames, it must be a list of blacklisted ones. For example:: |
|
112 |
||
113 |
OAUTH_BLACKLISTED_HOSTNAMES = ['localhost', '127.0.0.1'] |
|
114 |
||
110 |
115 |
A complete example is available in ``oauth_examples/provider/`` folder, you |
111 |
116 |
can run tests from this example with this command:: |
112 |
117 |
|
113 |
118 |
$ python manage.py test oauth_provider |
114 |
119 |
... |
115 |
Ran |
|
120 |
Ran 1 test in 0.264s |
|
116 |
121 |
|
117 |
122 |
OK |
118 |
123 |
... |
