Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ Paul Oswald
Jens Timmerman
Jim Graham
pySilver
Silvano Cerza
5 changes: 3 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ Notice that `oauth2_provider` namespace is mandatory.

.. code-block:: python

urlpatterns = patterns(
urlpatterns = [
...
url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
)
]

Documentation
--------------
Expand All @@ -100,6 +100,7 @@ Changelog
Development
~~~~~~~~~~~

* #425: Added support for Django 1.10
* #396: added an IsAuthenticatedOrTokenHasScope Permission
* #357: Support multiple-user clients by allowing User to be NULL for Applications
* #389: Reuse refresh tokens if enabled.
Expand Down
3 changes: 2 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Changelog
Development
~~~~~~~~~~~

* #396: added an IsAuthenticatedOrTokenHasScope Permission
* #425: Added support for Django 1.10
* #396: Added an IsAuthenticatedOrTokenHasScope Permission
* #357: Support multiple-user clients by allowing User to be NULL for Applications
* #389: Reuse refresh tokens if enabled.

Expand Down
4 changes: 2 additions & 2 deletions docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ If you need an OAuth2 provider you'll want to add the following to your urls.py

.. code-block:: python

urlpatterns = patterns(
urlpatterns = [
...
url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
)
]

Sync your database
------------------
Expand Down
6 changes: 3 additions & 3 deletions docs/rest-framework/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Here's our project's root `urls.py` module:

.. code-block:: python

from django.conf.urls import url, patterns, include
from django.conf.urls import url, include
from django.contrib.auth.models import User, Group
from django.contrib import admin
admin.autodiscover()
Expand Down Expand Up @@ -91,11 +91,11 @@ Here's our project's root `urls.py` module:

# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browseable API.
urlpatterns = patterns('',
urlpatterns = [
url(r'^', include(router.urls)),
url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
url(r'^admin/', include(admin.site.urls)),
)
]

Also add the following to your `settings.py` module:

Expand Down
5 changes: 2 additions & 3 deletions docs/tutorial/tutorial_01.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ Include the Django OAuth Toolkit urls in your `urls.py`, choosing the urlspace y

.. code-block:: python

urlpatterns = patterns(
'',
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
# ...
)
]

Include the CORS middleware in your `settings.py`:

Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/tutorial_02.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ URL this view will respond to:

.. code-block:: python

from django.conf.urls import patterns, url
from django.conf.urls import url
import oauth2_provider.views as oauth2_views
from django.conf import settings
from .views import ApiEndpoint
Expand Down
5 changes: 2 additions & 3 deletions docs/tutorial/tutorial_03.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,10 @@ To check everything works properly, mount the view above to some url:

.. code-block:: python

urlpatterns = patterns(
'',
urlpatterns = [
url(r'^secret$', 'my.views.secret_page', name='secret'),
'...',
)
]

You should have an :term:`Application` registered at this point, if you don't, follow the steps in
the previous tutorials to create one. Obtain an :term:`Access Token`, either following the OAuth2
Expand Down
1 change: 1 addition & 0 deletions oauth2_provider/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class RawIDAdmin(admin.ModelAdmin):
raw_id_fields = ('user',)


Application = get_application_model()

admin.site.register(Application, RawIDAdmin)
Expand Down
2 changes: 1 addition & 1 deletion oauth2_provider/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# bastb Django 1.10 has updated Middleware. This code imports the Mixin required to get old-style
# middleware working again
# More?
# More?
# https://docs.djangoproject.com/en/1.10/topics/http/middleware/#upgrading-pre-django-1-10-style-middleware
try:
from django.utils.deprecation import MiddlewareMixin
Expand Down
28 changes: 19 additions & 9 deletions oauth2_provider/tests/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = ()

MANAGERS = ADMINS
Expand Down Expand Up @@ -40,10 +37,25 @@
# Make this unique, and don't share it with anybody.
SECRET_KEY = "1234567890evonove"

TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'debug': True,
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
},
},
]

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
Expand All @@ -55,8 +67,6 @@

ROOT_URLCONF = 'oauth2_provider.tests.urls'

TEMPLATE_DIRS = ()

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
Expand Down
9 changes: 8 additions & 1 deletion oauth2_provider/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,14 @@ def test_related_objects(self):
# Django internals caches the related objects.
if django.VERSION < (1, 8):
del UserModel._meta._related_objects_cache
related_object_names = [ro.name for ro in UserModel._meta.get_all_related_objects()]
if django.VERSION < (1, 10):
related_object_names = [ro.name for ro in UserModel._meta.get_all_related_objects()]
else:
related_object_names = [
f.name for f in UserModel._meta.get_fields()
if (f.one_to_many or f.one_to_one)
and f.auto_created and not f.concrete
]
self.assertNotIn('oauth2_provider:application', related_object_names)
self.assertIn('tests%stestapplication' % (':' if django.VERSION < (1, 8) else '_'),
related_object_names)
Expand Down
11 changes: 5 additions & 6 deletions oauth2_provider/tests/test_rest_framework.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import unittest
from datetime import timedelta

from django.conf.urls import patterns, url, include
from django.conf.urls import url, include
from django.contrib.auth import get_user_model
from django.http import HttpResponse
from django.test import TestCase
from django.test.utils import override_settings
from django.utils import timezone

from .test_utils import TestCaseUtils
Expand Down Expand Up @@ -50,15 +51,14 @@ class ResourceScopedView(OAuth2View):
permission_classes = [permissions.IsAuthenticated, TokenHasResourceScope]
required_scopes = ['resource1']

urlpatterns = patterns(
'',
urlpatterns = [
url(r'^oauth2/', include('oauth2_provider.urls')),
url(r'^oauth2-test/$', OAuth2View.as_view()),
url(r'^oauth2-scoped-test/$', ScopedView.as_view()),
url(r'^oauth2-read-write-test/$', ReadWriteScopedView.as_view()),
url(r'^oauth2-resource-scoped-test/$', ResourceScopedView.as_view()),
url(r'^oauth2-authenticated-or-scoped-test/$', AuthenticatedOrScopedView.as_view()),
)
]

rest_framework_installed = True
except ImportError:
Expand All @@ -72,9 +72,8 @@ class BaseTest(TestCaseUtils, TestCase):
pass


@override_settings(ROOT_URLCONF=__name__)
class TestOAuth2Authentication(BaseTest):
urls = 'oauth2_provider.tests.test_rest_framework'

def setUp(self):
oauth2_settings._SCOPES = ['read', 'write', 'scope1', 'scope2', 'resource1']

Expand Down
4 changes: 2 additions & 2 deletions oauth2_provider/tests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
admin.autodiscover()


urlpatterns = (
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
)
]
12 changes: 6 additions & 6 deletions oauth2_provider/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@

from . import views

urlpatterns = (
urlpatterns = [
url(r'^authorize/$', views.AuthorizationView.as_view(), name="authorize"),
url(r'^token/$', views.TokenView.as_view(), name="token"),
url(r'^revoke_token/$', views.RevokeTokenView.as_view(), name="revoke-token"),
)
]

# Application management views
urlpatterns += (
urlpatterns += [
url(r'^applications/$', views.ApplicationList.as_view(), name="list"),
url(r'^applications/register/$', views.ApplicationRegistration.as_view(), name="register"),
url(r'^applications/(?P<pk>\d+)/$', views.ApplicationDetail.as_view(), name="detail"),
url(r'^applications/(?P<pk>\d+)/delete/$', views.ApplicationDelete.as_view(), name="delete"),
url(r'^applications/(?P<pk>\d+)/update/$', views.ApplicationUpdate.as_view(), name="update"),
)
]

urlpatterns += (
urlpatterns += [
url(r'^authorized_tokens/$', views.AuthorizedTokensListView.as_view(), name="authorized-token-list"),
url(r'^authorized_tokens/(?P<pk>\d+)/delete/$', views.AuthorizedTokenDeleteView.as_view(),
name="authorized-token-delete"),
)
]
8 changes: 5 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ testpaths=oauth2_provider

[tox]
envlist =
py27-django{18,19},
py27-django{18,19,110},
py32-django18,
py33-django18,
py34-django{18,19},
py35-django{18,19},
py34-django{18,19,110},
py35-django{18,19,110},
docs,
flake8

Expand All @@ -17,6 +17,7 @@ commands=python runtests.py -q --cov=oauth2_provider --cov-report= --cov-append
deps =
django18: Django==1.8.15
django19: Django==1.9.10
django110: Django==1.10.2
coverage==4.1
pytest-cov==2.3.0
-rrequirements/testing.txt
Expand All @@ -31,6 +32,7 @@ deps =
[testenv:docs]
basepython=python
changedir=docs
whitelist_externals=make
deps =
sphinx
south
Expand Down