Permalink
Browse files

upgrade to django-browserid==0.7.1

  • Loading branch information...
1 parent 8508fd6 commit a78e698c640b8c5874edeeb6072ce97e77aa3545 @peterbe peterbe committed Dec 13, 2012
Showing with 15,120 additions and 609 deletions.
  1. +4 −2 lib/python/django_browserid/__init__.py
  2. +24 −20 lib/python/django_browserid/auth.py
  3. +12 −47 lib/python/django_browserid/base.py
  4. +1 −1 lib/python/django_browserid/forms.py
  5. +61 −9 lib/python/django_browserid/static/browserid/browserid.js
  6. +1 −1 lib/python/django_browserid/tests/__init__.py
  7. +23 −0 lib/python/django_browserid/tests/models.py
  8. +3 −0 lib/python/django_browserid/tests/settings.py
  9. +71 −33 lib/python/django_browserid/tests/test_auth.py
  10. +33 −13 lib/python/django_browserid/tests/test_verification.py
  11. +29 −13 lib/python/django_browserid/tests/test_views.py
  12. +11 −3 lib/python/django_browserid/views.py
  13. +31 −4 lib/python/requests/__init__.py
  14. +23 −0 lib/python/requests/_oauth.py
  15. +58 −0 lib/python/requests/adapters.py
  16. +14 −3 lib/python/requests/api.py
  17. +257 −104 lib/python/requests/auth.py
  18. +3,338 −0 lib/python/requests/cacert.pem
  19. +27 −0 lib/python/requests/certs.py
  20. +19 −5 lib/python/requests/compat.py
  21. +29 −15 lib/python/requests/cookies.py
  22. +4 −7 lib/python/requests/defaults.py
  23. +10 −0 lib/python/requests/exceptions.py
  24. +3 −6 lib/python/requests/hooks.py
  25. +152 −77 lib/python/requests/models.py
  26. +26 −0 lib/python/requests/packages/chardet/__init__.py
  27. +923 −0 lib/python/requests/packages/chardet/big5freq.py
  28. +41 −0 lib/python/requests/packages/chardet/big5prober.py
  29. +200 −0 lib/python/requests/packages/chardet/chardistribution.py
  30. +96 −0 lib/python/requests/packages/chardet/charsetgroupprober.py
  31. +60 −0 lib/python/requests/packages/chardet/charsetprober.py
  32. +56 −0 lib/python/requests/packages/chardet/codingstatemachine.py
  33. +47 −0 lib/python/requests/packages/chardet/constants.py
  34. +79 −0 lib/python/requests/packages/chardet/escprober.py
  35. +240 −0 lib/python/requests/packages/chardet/escsm.py
  36. +85 −0 lib/python/requests/packages/chardet/eucjpprober.py
  37. +594 −0 lib/python/requests/packages/chardet/euckrfreq.py
  38. +41 −0 lib/python/requests/packages/chardet/euckrprober.py
  39. +426 −0 lib/python/requests/packages/chardet/euctwfreq.py
  40. +41 −0 lib/python/requests/packages/chardet/euctwprober.py
  41. +471 −0 lib/python/requests/packages/chardet/gb2312freq.py
  42. +41 −0 lib/python/requests/packages/chardet/gb2312prober.py
  43. +269 −0 lib/python/requests/packages/chardet/hebrewprober.py
  44. +567 −0 lib/python/requests/packages/chardet/jisfreq.py
  45. +210 −0 lib/python/requests/packages/chardet/jpcntx.py
  46. +228 −0 lib/python/requests/packages/chardet/langbulgarianmodel.py
  47. +329 −0 lib/python/requests/packages/chardet/langcyrillicmodel.py
  48. +225 −0 lib/python/requests/packages/chardet/langgreekmodel.py
  49. +201 −0 lib/python/requests/packages/chardet/langhebrewmodel.py
  50. +225 −0 lib/python/requests/packages/chardet/langhungarianmodel.py
  51. +200 −0 lib/python/requests/packages/chardet/langthaimodel.py
  52. +136 −0 lib/python/requests/packages/chardet/latin1prober.py
  53. +82 −0 lib/python/requests/packages/chardet/mbcharsetprober.py
  54. +50 −0 lib/python/requests/packages/chardet/mbcsgroupprober.py
  55. +514 −0 lib/python/requests/packages/chardet/mbcssm.py
  56. +106 −0 lib/python/requests/packages/chardet/sbcharsetprober.py
  57. +64 −0 lib/python/requests/packages/chardet/sbcsgroupprober.py
  58. +85 −0 lib/python/requests/packages/chardet/sjisprober.py
  59. +154 −0 lib/python/requests/packages/chardet/universaldetector.py
  60. +76 −0 lib/python/requests/packages/chardet/utf8prober.py
  61. 0 lib/python/requests/packages/oauthlib/__init__.py
  62. +229 −0 lib/python/requests/packages/oauthlib/common.py
  63. +13 −0 lib/python/requests/packages/oauthlib/oauth1/__init__.py
  64. +889 −0 lib/python/requests/packages/oauthlib/oauth1/rfc5849/__init__.py
  65. +134 −0 lib/python/requests/packages/oauthlib/oauth1/rfc5849/parameters.py
  66. +551 −0 lib/python/requests/packages/oauthlib/oauth1/rfc5849/signature.py
  67. +99 −0 lib/python/requests/packages/oauthlib/oauth1/rfc5849/utils.py
  68. +13 −0 lib/python/requests/packages/oauthlib/oauth2/__init__.py
  69. +497 −0 lib/python/requests/packages/oauthlib/oauth2/draft25/__init__.py
  70. +256 −0 lib/python/requests/packages/oauthlib/oauth2/draft25/parameters.py
  71. +132 −0 lib/python/requests/packages/oauthlib/oauth2/draft25/tokens.py
  72. +39 −0 lib/python/requests/packages/oauthlib/oauth2/draft25/utils.py
  73. +18 −2 lib/python/requests/packages/urllib3/__init__.py
  74. +66 −103 lib/python/requests/packages/urllib3/_collections.py
  75. +66 −26 lib/python/requests/packages/urllib3/connectionpool.py
  76. +10 −0 lib/python/requests/packages/urllib3/exceptions.py
  77. +8 −5 lib/python/requests/packages/urllib3/filepost.py
  78. +260 −0 lib/python/requests/packages/urllib3/packages/ordered_dict.py
  79. +42 −22 lib/python/requests/packages/urllib3/poolmanager.py
  80. +4 −4 lib/python/requests/packages/urllib3/response.py
  81. +155 −39 lib/python/requests/packages/urllib3/util.py
  82. +7 −5 lib/python/requests/safe_mode.py
  83. +32 −28 lib/python/requests/sessions.py
  84. +1 −1 lib/python/requests/status_codes.py
  85. +1 −0 lib/python/requests/structures.py
  86. +172 −11 lib/python/requests/utils.py
@@ -5,5 +5,7 @@
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_browserid.auth import BrowserIDBackend
-from django_browserid.base import get_audience, verify
+__version__ = '0.7.1'
+
+from django_browserid.auth import BrowserIDBackend # NOQA
+from django_browserid.base import get_audience, verify # NOQA
@@ -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 get_audience as base_get_audience, verify
+from django_browserid.base import 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
-log = logging.getLogger(__name__)
+ def get_user_model(*args, **kwargs):
+ return User
-def get_audience(*args):
- warn('Deprecated, please use the standalone function '
- 'django_browserid.get_audience instead.', DeprecationWarning)
- return base_get_audience(*args)
+log = logging.getLogger(__name__)
def default_username_algo(email):
@@ -40,14 +40,17 @@ class BrowserIDBackend(object):
supports_inactive_user = True
supports_object_permissions = False
- def verify(self, *args):
- warn('Deprecated, please use the standalone function '
- 'django_browserid.verify instead.', DeprecationWarning)
- return verify(*args)
+ 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 filter_users_by_email(self, email):
"""Return all users matching the specified email."""
- return User.objects.filter(email=email)
+ return self.User.objects.filter(email=email)
def create_user(self, email):
"""Return object for a newly created user account."""
@@ -57,7 +60,7 @@ def create_user(self, email):
else:
username = default_username_algo(email)
- return User.objects.create_user(username, email)
+ return self.User.objects.create_user(username, email)
def authenticate(self, assertion=None, audience=None):
"""``django.contrib.auth`` compatible authentication method.
@@ -81,7 +84,8 @@ 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('%d users with email address %s.' % (len(users), email))
+ log.warn('{0} users with email address {1}.'.format(len(users),
+ email))
return None
if len(users) == 1:
return users[0]
@@ -90,7 +94,7 @@ def authenticate(self, assertion=None, audience=None):
if not create_user:
return None
else:
- if create_user == True:
+ if create_user is True:
create_function = self.create_user
else:
# Find the function to call.
@@ -102,8 +106,8 @@ def authenticate(self, assertion=None, audience=None):
def get_user(self, user_id):
try:
- return User.objects.get(pk=user_id)
- except User.DoesNotExist:
+ return self.User.objects.get(pk=user_id)
+ except self.User.DoesNotExist:
return None
def _load_module(self, path):
@@ -125,6 +129,6 @@ def _load_module(self, path):
try:
create_user = getattr(mod, attr)
except AttributeError:
- raise ImproperlyConfigured('Module "%s" does not define a "%s" '
- 'function.' % (module, attr))
+ raise ImproperlyConfigured('Module {0} does not define a {1} '
+ 'function.'.format(module, attr))
return create_user
@@ -9,7 +9,7 @@
try:
import json
except ImportError:
- import simplejson as json
+ import simplejson as json # NOQA
from django.conf import settings
@@ -21,7 +21,7 @@
DEFAULT_HTTP_TIMEOUT = 5
-DEFAULT_VERIFICATION_URL = 'https://browserid.org/verify'
+DEFAULT_VERIFICATION_URL = 'https://verifier.login.persona.org/verify'
OKAY_RESPONSE = 'okay'
@@ -36,17 +36,6 @@ 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*!
"""
@@ -59,32 +48,11 @@ 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 [%s], but '
- 'actual request was [%s] BrowserID may fail on '
- 'audience' % (site_url, req_url))
+ log.warning('Misconfigured SITE_URL? settings has {0}, but '
+ 'actual request was {1} BrowserID may fail on '
+ 'audience'.format(site_url, req_url))
return site_url
@@ -94,10 +62,8 @@ 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'},
- 'params': {
- 'timeout': getattr(settings, 'BROWSERID_HTTP_TIMEOUT',
- DEFAULT_HTTP_TIMEOUT)
- }
+ 'timeout': getattr(settings, 'BROWSERID_HTTP_TIMEOUT',
+ DEFAULT_HTTP_TIMEOUT),
}
if parameters['verify']:
@@ -108,8 +74,7 @@ def _verify_http_request(url, qs):
try:
rv = json.loads(r.content)
except ValueError:
- log.debug('Failed to decode JSON. Resp: %s, Content: %s' %
- (r.status_code, r.content))
+ log.debug('Failed to decode JSON. Resp: {0}, Content: {1}'.format(r.status_code, r.content))
return dict(status='failure')
return rv
@@ -120,7 +85,7 @@ def verify(assertion, audience):
verify_url = getattr(settings, 'BROWSERID_VERIFICATION_URL',
DEFAULT_VERIFICATION_URL)
- log.info("Verification URL: %s" % verify_url)
+ log.info("Verification URL: {0}".format(verify_url))
result = _verify_http_request(verify_url, urllib.urlencode({
'assertion': assertion,
@@ -130,7 +95,7 @@ def verify(assertion, audience):
if result['status'] == OKAY_RESPONSE:
return result
- log.error('BrowserID verification failure. Response: %r '
- 'Audience: %r' % (result, audience))
- log.error("BID assert: %r" % assertion)
+ log.error('BrowserID verification failure. Response: {0} '
+ 'Audience: {1}'.format(result, audience))
+ log.error("BID assert: {0}".format(assertion))
return False
@@ -10,4 +10,4 @@ class BrowserIDForm(forms.Form):
assertion = forms.CharField(widget=forms.HiddenInput())
class Media:
- js = ('browserid/browserid.js', 'https://browserid.org/include.js')
+ js = ('browserid/browserid.js', 'https://login.persona.org/include.js')
@@ -1,15 +1,67 @@
/* 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/. */
- $(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();
+
+(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;
+ }
+ }
}
});
});
-});
+})(jQuery);
@@ -31,7 +31,7 @@ def __init__(self, email=None, audience=None):
self.return_value = {
u'audience': audience,
u'email': email,
- u'issuer': u'browserid.org:443',
+ u'issuer': u'login.persona.org:443',
u'status': u'okay' if email is not None else u'failure',
u'valid-until': 1311377222765
}
@@ -0,0 +1,23 @@
+"""
+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,6 +5,8 @@
"""
TEST_RUNNER = 'django_nose.runner.NoseTestSuiteRunner'
+SECRET_KEY = 'asdf'
+
DATABASES = {
'default': {
'NAME': 'test.db',
@@ -15,6 +17,7 @@
INSTALLED_APPS = (
'django_nose',
'django_browserid',
+ 'django_browserid.tests',
'django.contrib.auth',
'django.contrib.contenttypes',
Oops, something went wrong.

0 comments on commit a78e698

Please sign in to comment.