19

It's the first time I work with django rest and Django Oauth toolkit I'm following this tutorial oauth2-with-django-rest-framework But when I run python manage.py migrate I get the following error:

ImportError: Could not import 'oauth2_provider.ext.rest_framework.OAuth2Authentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'. ImportError: No module named ext.rest_framework.

What is going wrong ? is there another module I should install ? my virtual environment contains :

certifi==2017.4.17

chardet==3.0.4

Django==1.11.2

django-extensions==1.8.1

django-oauth-toolkit==1.0.0

djangorestframework==3.6.3

idna==2.5

oauthlib==2.0.2

pytz==2017.2

requests==2.18.1

six==1.10.0

Unidecode==0.4.21

urllib3==1.21.1

Akamee
  • 593
  • 1
  • 6
  • 21
  • please show your settings file – Exprator Jul 11 '17 at 08:29
  • settings files contains : INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'business', 'rest_framework', 'django_extensions', 'oauth2_provider', ] for the installed aps and REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'oauth2_provider.ext.rest_framework.OAuth2Authentication', ) } for the django rest settings – Akamee Jul 11 '17 at 08:32

2 Answers2

48

It looks like oath2_provider.ext has been moved to oauth_provider.contrib. You could try installing an older version of django-oauth-toolkit, or try changing the value in DEFAULT_AUTHENTICATION_CLASSES from:

'oauth2_provider.ext.rest_framework.OAuth2Authentication',

to:

'oauth2_provider.contrib.rest_framework.OAuth2Authentication',

Note that the tutorial is a couple of years old, you might find other problems like this.

Alasdair
  • 298,606
  • 55
  • 578
  • 516
  • They should update their documentation https://django-oauth-toolkit.readthedocs.io/en/latest/rest-framework/getting_started.html – Rohit Sthapit Jan 31 '18 at 17:21
  • 2
    @RohitSthapit 'they' might never see that comment. Instead of complaining here, why not create a pull request with updated instructions. – Alasdair Jan 31 '18 at 17:26
2

I was facing same issue. In my setting file DEFAULT_AUTHENTICATION_CLASSES was already 'oauth2_provider.contrib.rest_framework.OAuth2Authentication',

I just installed older version as @Alasdair ask. My issue resolved. thanks

sakulachi8
  • 190
  • 2
  • 11