Permalink
Browse files

Revert "upgrade to django-browserid==0.7.1"

This reverts commit a78e698.
  • Loading branch information...
peterbe committed Dec 17, 2012
1 parent 5f367d6 commit 0b784afa0a984cb632b89e5623089980d79e2501
Showing with 609 additions and 15,120 deletions.
  1. +2 −4 lib/python/django_browserid/__init__.py
  2. +20 −24 lib/python/django_browserid/auth.py
  3. +47 −12 lib/python/django_browserid/base.py
  4. +1 −1 lib/python/django_browserid/forms.py
  5. +9 −61 lib/python/django_browserid/static/browserid/browserid.js
  6. +1 −1 lib/python/django_browserid/tests/__init__.py
  7. +0 −23 lib/python/django_browserid/tests/models.py
  8. +0 −3 lib/python/django_browserid/tests/settings.py
  9. +33 −71 lib/python/django_browserid/tests/test_auth.py
  10. +13 −33 lib/python/django_browserid/tests/test_verification.py
  11. +13 −29 lib/python/django_browserid/tests/test_views.py
  12. +3 −11 lib/python/django_browserid/views.py
  13. +4 −31 lib/python/requests/__init__.py
  14. +0 −23 lib/python/requests/_oauth.py
  15. +0 −58 lib/python/requests/adapters.py
  16. +3 −14 lib/python/requests/api.py
  17. +104 −257 lib/python/requests/auth.py
  18. +0 −3,338 lib/python/requests/cacert.pem
  19. +0 −27 lib/python/requests/certs.py
  20. +5 −19 lib/python/requests/compat.py
  21. +15 −29 lib/python/requests/cookies.py
  22. +7 −4 lib/python/requests/defaults.py
  23. +0 −10 lib/python/requests/exceptions.py
  24. +6 −3 lib/python/requests/hooks.py
  25. +77 −152 lib/python/requests/models.py
  26. +0 −26 lib/python/requests/packages/chardet/__init__.py
  27. +0 −923 lib/python/requests/packages/chardet/big5freq.py
  28. +0 −41 lib/python/requests/packages/chardet/big5prober.py
  29. +0 −200 lib/python/requests/packages/chardet/chardistribution.py
  30. +0 −96 lib/python/requests/packages/chardet/charsetgroupprober.py
  31. +0 −60 lib/python/requests/packages/chardet/charsetprober.py
  32. +0 −56 lib/python/requests/packages/chardet/codingstatemachine.py
  33. +0 −47 lib/python/requests/packages/chardet/constants.py
  34. +0 −79 lib/python/requests/packages/chardet/escprober.py
  35. +0 −240 lib/python/requests/packages/chardet/escsm.py
  36. +0 −85 lib/python/requests/packages/chardet/eucjpprober.py
  37. +0 −594 lib/python/requests/packages/chardet/euckrfreq.py
  38. +0 −41 lib/python/requests/packages/chardet/euckrprober.py
  39. +0 −426 lib/python/requests/packages/chardet/euctwfreq.py
  40. +0 −41 lib/python/requests/packages/chardet/euctwprober.py
  41. +0 −471 lib/python/requests/packages/chardet/gb2312freq.py
  42. +0 −41 lib/python/requests/packages/chardet/gb2312prober.py
  43. +0 −269 lib/python/requests/packages/chardet/hebrewprober.py
  44. +0 −567 lib/python/requests/packages/chardet/jisfreq.py
  45. +0 −210 lib/python/requests/packages/chardet/jpcntx.py
  46. +0 −228 lib/python/requests/packages/chardet/langbulgarianmodel.py
  47. +0 −329 lib/python/requests/packages/chardet/langcyrillicmodel.py
  48. +0 −225 lib/python/requests/packages/chardet/langgreekmodel.py
  49. +0 −201 lib/python/requests/packages/chardet/langhebrewmodel.py
  50. +0 −225 lib/python/requests/packages/chardet/langhungarianmodel.py
  51. +0 −200 lib/python/requests/packages/chardet/langthaimodel.py
  52. +0 −136 lib/python/requests/packages/chardet/latin1prober.py
  53. +0 −82 lib/python/requests/packages/chardet/mbcharsetprober.py
  54. +0 −50 lib/python/requests/packages/chardet/mbcsgroupprober.py
  55. +0 −514 lib/python/requests/packages/chardet/mbcssm.py
  56. +0 −106 lib/python/requests/packages/chardet/sbcharsetprober.py
  57. +0 −64 lib/python/requests/packages/chardet/sbcsgroupprober.py
  58. +0 −85 lib/python/requests/packages/chardet/sjisprober.py
  59. +0 −154 lib/python/requests/packages/chardet/universaldetector.py
  60. +0 −76 lib/python/requests/packages/chardet/utf8prober.py
  61. 0 lib/python/requests/packages/oauthlib/__init__.py
  62. +0 −229 lib/python/requests/packages/oauthlib/common.py
  63. +0 −13 lib/python/requests/packages/oauthlib/oauth1/__init__.py
  64. +0 −889 lib/python/requests/packages/oauthlib/oauth1/rfc5849/__init__.py
  65. +0 −134 lib/python/requests/packages/oauthlib/oauth1/rfc5849/parameters.py
  66. +0 −551 lib/python/requests/packages/oauthlib/oauth1/rfc5849/signature.py
  67. +0 −99 lib/python/requests/packages/oauthlib/oauth1/rfc5849/utils.py
  68. +0 −13 lib/python/requests/packages/oauthlib/oauth2/__init__.py
  69. +0 −497 lib/python/requests/packages/oauthlib/oauth2/draft25/__init__.py
  70. +0 −256 lib/python/requests/packages/oauthlib/oauth2/draft25/parameters.py
  71. +0 −132 lib/python/requests/packages/oauthlib/oauth2/draft25/tokens.py
  72. +0 −39 lib/python/requests/packages/oauthlib/oauth2/draft25/utils.py
  73. +2 −18 lib/python/requests/packages/urllib3/__init__.py
  74. +103 −66 lib/python/requests/packages/urllib3/_collections.py
  75. +26 −66 lib/python/requests/packages/urllib3/connectionpool.py
  76. +0 −10 lib/python/requests/packages/urllib3/exceptions.py
  77. +5 −8 lib/python/requests/packages/urllib3/filepost.py
  78. +0 −260 lib/python/requests/packages/urllib3/packages/ordered_dict.py
  79. +22 −42 lib/python/requests/packages/urllib3/poolmanager.py
  80. +4 −4 lib/python/requests/packages/urllib3/response.py
  81. +39 −155 lib/python/requests/packages/urllib3/util.py
  82. +5 −7 lib/python/requests/safe_mode.py
  83. +28 −32 lib/python/requests/sessions.py
  84. +1 −1 lib/python/requests/status_codes.py
  85. +0 −1 lib/python/requests/structures.py
  86. +11 −172 lib/python/requests/utils.py
@@ -5,7 +5,5 @@
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""
-__version__ = '0.7.1'
-
-from django_browserid.auth import BrowserIDBackend # NOQA
-from django_browserid.base import get_audience, verify # NOQA
+from django_browserid.auth import BrowserIDBackend
+from django_browserid.base import get_audience, verify
@@ -6,24 +6,24 @@
import base64
import hashlib
import logging
+from warnings import warn
from django.conf import settings
+from django.contrib.auth.models import User
from django.core.exceptions import ImproperlyConfigured
from django.utils.importlib import import_module
-from django_browserid.base import verify
+from django_browserid.base import get_audience as base_get_audience, verify
from django_browserid.signals import user_created
-try:
- from django.contrib.auth import get_user_model
-except ImportError:
- from django.contrib.auth.models import User
- def get_user_model(*args, **kwargs):
- return User
+log = logging.getLogger(__name__)
-log = logging.getLogger(__name__)
+def get_audience(*args):
+ warn('Deprecated, please use the standalone function '
+ 'django_browserid.get_audience instead.', DeprecationWarning)
+ return base_get_audience(*args)
def default_username_algo(email):
@@ -40,17 +40,14 @@ class BrowserIDBackend(object):
supports_inactive_user = True
supports_object_permissions = False
- def __init__(self):
- """
- Store the current user model on creation to avoid issues if
- settings.AUTH_USER_MODEL changes, which usually only happens during
- tests.
- """
- self.User = get_user_model()
+ def verify(self, *args):
+ warn('Deprecated, please use the standalone function '
+ 'django_browserid.verify instead.', DeprecationWarning)
+ return verify(*args)
def filter_users_by_email(self, email):
"""Return all users matching the specified email."""
- return self.User.objects.filter(email=email)
+ return User.objects.filter(email=email)
def create_user(self, email):
"""Return object for a newly created user account."""
@@ -60,7 +57,7 @@ def create_user(self, email):
else:
username = default_username_algo(email)
- return self.User.objects.create_user(username, email)
+ return User.objects.create_user(username, email)
def authenticate(self, assertion=None, audience=None):
"""``django.contrib.auth`` compatible authentication method.
@@ -84,8 +81,7 @@ def authenticate(self, assertion=None, audience=None):
# log and bail. randomly selecting one seems really wrong.
users = self.filter_users_by_email(email=email)
if len(users) > 1:
- log.warn('{0} users with email address {1}.'.format(len(users),
- email))
+ log.warn('%d users with email address %s.' % (len(users), email))
return None
if len(users) == 1:
return users[0]
@@ -94,7 +90,7 @@ def authenticate(self, assertion=None, audience=None):
if not create_user:
return None
else:
- if create_user is True:
+ if create_user == True:
create_function = self.create_user
else:
# Find the function to call.
@@ -106,8 +102,8 @@ def authenticate(self, assertion=None, audience=None):
def get_user(self, user_id):
try:
- return self.User.objects.get(pk=user_id)
- except self.User.DoesNotExist:
+ return User.objects.get(pk=user_id)
+ except User.DoesNotExist:
return None
def _load_module(self, path):
@@ -129,6 +125,6 @@ def _load_module(self, path):
try:
create_user = getattr(mod, attr)
except AttributeError:
- raise ImproperlyConfigured('Module {0} does not define a {1} '
- 'function.'.format(module, attr))
+ raise ImproperlyConfigured('Module "%s" does not define a "%s" '
+ 'function.' % (module, attr))
return create_user
@@ -9,7 +9,7 @@
try:
import json
except ImportError:
- import simplejson as json # NOQA
+ import simplejson as json
from django.conf import settings
@@ -21,7 +21,7 @@
DEFAULT_HTTP_TIMEOUT = 5
-DEFAULT_VERIFICATION_URL = 'https://verifier.login.persona.org/verify'
+DEFAULT_VERIFICATION_URL = 'https://browserid.org/verify'
OKAY_RESPONSE = 'okay'
@@ -36,6 +36,17 @@ def get_audience(request):
SITE_URL = 'https://example.com'
SITE_URL = 'http://example.com'
+ If you don't have a SITE_URL you can also use these varables:
+ PROTOCOL, DOMAIN, and (optionally) PORT.
+ Example 1:
+ PROTOCOL = 'https://'
+ DOMAIN = 'example.com'
+
+ Example 2:
+ PROTOCOL = 'http://'
+ DOMAIN = '127.0.0.1'
+ PORT = '8001'
+
If none are set, we trust the request to populate the audience.
This is *not secure*!
"""
@@ -48,11 +59,32 @@ def get_audience(request):
req_proto = 'http://'
req_domain = request.get_host()
+ # If we don't define it explicitly
+ if not site_url:
+ warn('Using DOMAIN and PROTOCOL to specify your BrowserID audience is '
+ 'deprecated. Please use the SITE_URL setting instead.',
+ DeprecationWarning)
+
+ # DOMAIN is example.com req_domain is example.com:8001
+ domain = getattr(settings, 'DOMAIN', req_domain.split(':')[0])
+ protocol = getattr(settings, 'PROTOCOL', req_proto)
+
+ standards = {'https://': 443, 'http://': 80}
+ if ':' in req_domain:
+ req_port = req_domain.split(':')[1]
+ else:
+ req_port = None
+ port = getattr(settings, 'PORT', req_port or standards[protocol])
+ if port == standards[protocol]:
+ site_url = ''.join(map(str, (protocol, domain)))
+ else:
+ site_url = ''.join(map(str, (protocol, domain, ':', port)))
+
req_url = "%s%s" % (req_proto, req_domain)
if site_url != "%s%s" % (req_proto, req_domain):
- log.warning('Misconfigured SITE_URL? settings has {0}, but '
- 'actual request was {1} BrowserID may fail on '
- 'audience'.format(site_url, req_url))
+ log.warning('Misconfigured SITE_URL? settings has [%s], but '
+ 'actual request was [%s] BrowserID may fail on '
+ 'audience' % (site_url, req_url))
return site_url
@@ -62,8 +94,10 @@ def _verify_http_request(url, qs):
'proxies': getattr(settings, 'BROWSERID_PROXY_INFO', None),
'verify': not getattr(settings, 'BROWSERID_DISABLE_CERT_CHECK', False),
'headers': {'Content-type': 'application/x-www-form-urlencoded'},
- 'timeout': getattr(settings, 'BROWSERID_HTTP_TIMEOUT',
- DEFAULT_HTTP_TIMEOUT),
+ 'params': {
+ 'timeout': getattr(settings, 'BROWSERID_HTTP_TIMEOUT',
+ DEFAULT_HTTP_TIMEOUT)
+ }
}
if parameters['verify']:
@@ -74,7 +108,8 @@ def _verify_http_request(url, qs):
try:
rv = json.loads(r.content)
except ValueError:
- log.debug('Failed to decode JSON. Resp: {0}, Content: {1}'.format(r.status_code, r.content))
+ log.debug('Failed to decode JSON. Resp: %s, Content: %s' %
+ (r.status_code, r.content))
return dict(status='failure')
return rv
@@ -85,7 +120,7 @@ def verify(assertion, audience):
verify_url = getattr(settings, 'BROWSERID_VERIFICATION_URL',
DEFAULT_VERIFICATION_URL)
- log.info("Verification URL: {0}".format(verify_url))
+ log.info("Verification URL: %s" % verify_url)
result = _verify_http_request(verify_url, urllib.urlencode({
'assertion': assertion,
@@ -95,7 +130,7 @@ def verify(assertion, audience):
if result['status'] == OKAY_RESPONSE:
return result
- log.error('BrowserID verification failure. Response: {0} '
- 'Audience: {1}'.format(result, audience))
- log.error("BID assert: {0}".format(assertion))
+ log.error('BrowserID verification failure. Response: %r '
+ 'Audience: %r' % (result, audience))
+ log.error("BID assert: %r" % assertion)
return False
@@ -10,4 +10,4 @@ class BrowserIDForm(forms.Form):
assertion = forms.CharField(widget=forms.HiddenInput())
class Media:
- js = ('browserid/browserid.js', 'https://login.persona.org/include.js')
+ js = ('browserid/browserid.js', 'https://browserid.org/include.js')
@@ -1,67 +1,15 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-(function($) {
- 'use strict';
-
- $(function() {
- // State? Ewwwwww.
- var logoutButton = null;
- var requestOptions = [
- 'siteName',
- 'siteLogo',
- 'oncancel',
- 'privacyPolicy',
- 'returnTo',
- 'termsOfService'
- ];
-
- $(document).delegate('.browserid-login, #browserid', 'click', function(e) {
- e.preventDefault();
-
- // Arguments to navigator.id.request can be specified by data-attributes
- // on the BrowserID link: <a href="#" data-site-name="Site Name">
- var options = {};
- var $link = $(e.target);
- for (var k = 0; k < requestOptions.length; k++) {
- var name = requestOptions[k];
- var value = $link.data(name);
- if (value !== undefined) {
- options[name] = value;
- }
- }
-
- navigator.id.request(options); // Triggers BrowserID login dialog.
- });
-
- $('.browserid-logout').bind('click', function(e) {
- e.preventDefault();
- logoutButton = e.target;
- navigator.id.logout(); // Clears User Agent BrowserID state.
- });
-
- navigator.id.watch({
- onlogin: function(assertion) {
- // Don't bother if login just failed.
- if (location.search.indexOf('bid_login_failed=1') !== -1) {
- navigator.id.logout();
- } else if (assertion) {
- var $e = $('#id_assertion');
- $e.val(assertion.toString());
- $e.parent().submit();
- }
- },
-
- onlogout: function() {
- var currentButton = logoutButton;
- if (currentButton !== null) {
- logoutButton = null;
- if (currentButton.href) {
- window.location = currentButton.href;
- }
- }
+ $(document).ready(function() {
+ $('#browserid').bind('click', function(e) {
+ e.preventDefault();
+ navigator.id.getVerifiedEmail(function(assertion) {
+ if (assertion) {
+ var $e = $('#id_assertion');
+ $e.val(assertion.toString());
+ $e.parent().submit();
}
});
});
-})(jQuery);
+});
@@ -31,7 +31,7 @@ def __init__(self, email=None, audience=None):
self.return_value = {
u'audience': audience,
u'email': email,
- u'issuer': u'login.persona.org:443',
+ u'issuer': u'browserid.org:443',
u'status': u'okay' if email is not None else u'failure',
u'valid-until': 1311377222765
}
@@ -1,23 +0,0 @@
-"""
-This Source Code Form is subject to the terms of the Mozilla Public
-License, v. 2.0. If a copy of the MPL was not distributed with this
-file, You can obtain one at http://mozilla.org/MPL/2.0/.
-"""
-from django.db import models
-
-try:
- from django.contrib.auth.models import AbstractBaseUser
-except ImportError:
- AbstractBaseUser = object
-
-
-class CustomUser(AbstractBaseUser):
- USERNAME_FIELD = 'email'
-
- email = models.EmailField(unique=True, db_index=True)
-
- def get_full_name(self):
- return self.email
-
- def get_short_name(self):
- return self.email
@@ -5,8 +5,6 @@
"""
TEST_RUNNER = 'django_nose.runner.NoseTestSuiteRunner'
-SECRET_KEY = 'asdf'
-
DATABASES = {
'default': {
'NAME': 'test.db',
@@ -17,7 +15,6 @@
INSTALLED_APPS = (
'django_nose',
'django_browserid',
- 'django_browserid.tests',
'django.contrib.auth',
'django.contrib.contenttypes',
Oops, something went wrong.

0 comments on commit 0b784af

Please sign in to comment.