4

I am trying to set up OAuth2 authentication system for my Django REST API (using DjangoRestFramework and Django-Oauth-Toolkit). I wrote everything according to the official documentation, but the system gives error "could not import ext.rest_framework"

Here is my setting.py file:

OAUTH2_PROVIDER = {
    # this is the list of available scopes
    'SCOPES': {'read': 'Read scope', 'write': 'Write scope', 'groups': 'Access to your groups'}
}


REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': [
        'oauth2_provider.ext.rest_framework.OAuth2Authentication',
    ],
    'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',),
    'PAGE_SIZE': 10
}

Thanks!

funtik
  • 1,688
  • 3
  • 11
  • 27

1 Answers1

7

OK, I checked the source code for oauth2_provider. Apparently they changed the structure, but did not update the tutorial on their website. So, oauth2_provider.ext package does not exist anymore, you should use oauth2_provider.contrib instead. That is, the following code works fine:

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
    ),
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
    'PAGE_SIZE': 10
}
Kurt Peek
  • 52,165
  • 91
  • 301
  • 526
funtik
  • 1,688
  • 3
  • 11
  • 27