From a07a59efeb96ecb643c2c9f82b3ba13377d8137b Mon Sep 17 00:00:00 2001 From: Gerard Paligot Date: Sun, 8 Feb 2015 00:08:53 +0100 Subject: [PATCH] fix #2229 Changes library of oauth2 for django-oauth2-toolkit. We changes the library to be compatible Django 1.7 and Python 3. --- requirements.txt | 2 +- zds/member/api/tests.py | 11 +++++------ zds/settings.py | 5 ++--- zds/urls.py | 2 +- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/requirements.txt b/requirements.txt index 55bd1966b0..1ab77df7df 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,6 +25,6 @@ easy-thumbnails==2.2 # Api dependencies djangorestframework==3.0.2 django-filter==0.8 -django-oauth2-provider==0.2.6.1 +django-oauth-toolkit==0.7.2 drf-extensions==0.2.6 django-rest-swagger==0.2.8 diff --git a/zds/member/api/tests.py b/zds/member/api/tests.py index c75c91a9a4..f746d3c05e 100644 --- a/zds/member/api/tests.py +++ b/zds/member/api/tests.py @@ -5,7 +5,7 @@ from django.core import mail from django.core.urlresolvers import reverse from django.test.utils import override_settings -from provider.oauth2.models import AccessToken, Client +from oauth2_provider.models import Application, AccessToken from rest_framework import status from rest_framework.test import APITestCase from rest_framework.test import APIClient @@ -846,16 +846,15 @@ def test_remove_ban_at_a_member_without_permissions(self): def create_oauth2_client(user): - client = Client.objects.create(user=user, - name='zds', - url='zestedesavoir.com', - client_type=1) + client = Application.objects.create(user=user, + client_type=Application.CLIENT_CONFIDENTIAL, + authorization_grant_type=Application.GRANT_PASSWORD) client.save() return client def authenticate_client(client, clientAuth, username, password): - client.post('/oauth2/access_token', { + client.post('/oauth2/token/', { 'client_id': clientAuth.client_id, 'client_secret': clientAuth.client_secret, 'username': username, diff --git a/zds/settings.py b/zds/settings.py index 9e5ad63d33..3d838829f3 100644 --- a/zds/settings.py +++ b/zds/settings.py @@ -174,8 +174,7 @@ 'social.apps.django_app.default', 'rest_framework', 'rest_framework_swagger', - 'provider', - 'provider.oauth2', + 'oauth2_provider', # Apps DB tables are created in THIS order by default # --> Order is CRITICAL to properly handle foreign keys @@ -218,7 +217,7 @@ 'MAX_PAGINATE_BY': 100, # Maximum limit allowed when using `?page_size=xxx`. # Active OAuth2 authentication. 'DEFAULT_AUTHENTICATION_CLASSES': ( - 'rest_framework.authentication.OAuth2Authentication', + 'oauth2_provider.ext.rest_framework.OAuth2Authentication', ), 'DEFAULT_PARSER_CLASSES': ( 'rest_framework.parsers.JSONParser', diff --git a/zds/urls.py b/zds/urls.py index db33d55a8d..4bb011dec1 100644 --- a/zds/urls.py +++ b/zds/urls.py @@ -94,7 +94,7 @@ def location(self, article): # API urlpatterns += patterns('', url(r'^api/', include('rest_framework_swagger.urls')), - url(r'^oauth2/', include('provider.oauth2.urls', namespace='oauth2')), + url(r'^oauth2/', include('oauth2_provider.urls', namespace='oauth2_provider')), url(r'^api/membres/', include('zds.member.api.urls')), )