funtik
funtik

Reputation: 1826

Django OAuth Toolkit: could not import ext.rest_framework

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!

Upvotes: 4

Views: 409

Answers (1)

funtik
funtik

Reputation: 1826

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
}

Upvotes: 7

Related Questions