Django OAuth Toolkit: Failed to import ext.rest_framework
I'm trying to set up an 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 the error "failed to import ext.rest_framework"
Here is my settings.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
}
Thank!
+3
source to share
1 answer
OK, I checked the source code for oauth2_provider
. Apparently they changed the structure, but did not update the tutorial on their website. So the package oauth2_provider.ext
no longer exists, should be used instead oauth2_provider.contrib
. 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
}
+6
source to share