diff --git a/provider/oauth2/__init__.py b/provider/oauth2/__init__.py index 34796220..e15be5c6 100644 --- a/provider/oauth2/__init__.py +++ b/provider/oauth2/__init__.py @@ -3,4 +3,6 @@ import managers import models import urls -import views \ No newline at end of file +import views + +default_app_config = 'provider.oauth2.apps.Oauth2' diff --git a/provider/oauth2/apps.py b/provider/oauth2/apps.py new file mode 100644 index 00000000..c9c50344 --- /dev/null +++ b/provider/oauth2/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + +class Oauth2(AppConfig): + name = 'provider.oauth2' + label = 'oauth2' + verbose_name = "Provider Oauth2" diff --git a/provider/oauth2/models.py b/provider/oauth2/models.py index 9a6bdf91..cb843e8b 100644 --- a/provider/oauth2/models.py +++ b/provider/oauth2/models.py @@ -81,6 +81,10 @@ def deserialize(cls, data): return cls(**kwargs) + class Meta: + app_label = 'oauth2' + db_table = 'oauth2_client' + class Grant(models.Model): """ @@ -108,6 +112,10 @@ class Grant(models.Model): def __unicode__(self): return self.code + class Meta: + app_label = 'oauth2' + db_table = 'oauth2_grant' + class AccessToken(models.Model): """ @@ -165,6 +173,10 @@ def get_expire_delta(self, reference=None): timedelta = expiration - reference return timedelta.days*86400 + timedelta.seconds + class Meta: + app_label = 'oauth2' + db_table = 'oauth2_accesstoken' + class RefreshToken(models.Model): """ @@ -188,3 +200,7 @@ class RefreshToken(models.Model): def __unicode__(self): return self.token + + class Meta: + app_label = 'oauth2' + db_table = 'oauth2_refreshtoken' diff --git a/provider/views.py b/provider/views.py index dd1200df..41e0df95 100644 --- a/provider/views.py +++ b/provider/views.py @@ -298,7 +298,7 @@ def error_response(self, error, mimetype='application/json', status=400, Return an error response to the client with default status code of *400* stating the error as outlined in :rfc:`5.2`. """ - return HttpResponse(json.dumps(error), mimetype=mimetype, + return HttpResponse(json.dumps(error), content_type=mimetype, status=status, **kwargs) def get(self, request): @@ -463,7 +463,7 @@ def error_response(self, error, mimetype='application/json', status=400, Return an error response to the client with default status code of *400* stating the error as outlined in :rfc:`5.2`. """ - return HttpResponse(json.dumps(error), mimetype=mimetype, + return HttpResponse(json.dumps(error), content_type=mimetype, status=status, **kwargs) def access_token_response(self, access_token): @@ -488,7 +488,7 @@ def access_token_response(self, access_token): pass return HttpResponse( - json.dumps(response_data), mimetype='application/json' + json.dumps(response_data), content_type='application/json' ) def authorization_code(self, request, data, client): diff --git a/requirements.txt b/requirements.txt index a79a5d9f..df0d9db9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ Django>=1.4 -shortuuid>=0.3 +shortuuid>=0.4 diff --git a/setup.py b/setup.py index f9f55b85..6a257d10 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ 'Framework :: Django', ], install_requires=[ - "shortuuid>=0.3" + "shortuuid>=0.4" ], include_package_data=True, zip_safe=False, diff --git a/test.sh b/test.sh index 094e309b..1bf50b06 100755 --- a/test.sh +++ b/test.sh @@ -5,7 +5,7 @@ DJ_VERSION=$(django-admin.py --version) # exit if fail [[ "$?" -ne "0" ]] && exit; -IS_16=$(echo $DJ_VERSION | grep "1.6") +IS_16=$(echo $DJ_VERSION | grep -E "1\.6|1\.7|1\.8|dev") # if django version is not 1.6 (non-0 exit) we have to pass different # app names to test runner diff --git a/tests/settings.py b/tests/settings.py index 8e0cbcde..b689fcc1 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -1,5 +1,6 @@ # Django settings for example project. import os +from django import VERSION as DJANGO_VERSION DEBUG = True TEMPLATE_DEBUG = DEBUG @@ -60,3 +61,16 @@ 'provider.oauth2', ) +MIDDLEWARE_CLASSES = ( + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +) + +# Use DiscoverRunner on Django 1.7 and above +if DJANGO_VERSION[0] == 1 and DJANGO_VERSION[1] >= 7: + TEST_RUNNER = 'django.test.runner.DiscoverRunner' + diff --git a/tox.ini b/tox.ini index 41860909..e200bc24 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] downloadcache = {toxworkdir}/cache/ -envlist = py2.7-django.dev,py2.7-django1.6,py2.7-django1.5,py2.7-django1.4,py2.6-django.dev,py2.6-django1.6,py2.6-django1.5,py2.6-django1.4 +envlist = py2.7-django.dev,py2.7-django1.6,py2.7-django1.5,py2.7-django1.4,py2.6-django1.6,py2.6-django1.5,py2.6-django1.4 [testenv] setenv = @@ -29,11 +29,6 @@ basepython = python2.7 deps = django>=1.4,<1.5 {[testenv]deps} -[testenv:py2.6-django.dev] -basepython = python2.6 -deps = https://github.com/django/django/zipball/master - {[testenv]deps} - [testenv:py2.6-django1.6] basepython = python2.6 deps = django>=1.6,<1.7