Django OAuth Toolkit: could not import ext.rest_framework

funtik

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

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
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Django OAuth Toolkit - Register a user

Using django message framework with rest_framework

How to test an API endpoint with Django-rest-framework using Django-oauth-toolkit for authentication

Django oauth toolkit using implicit grant type

Extra protection layer for Django Rest Framework and OAuth2 Toolkit

Django OAuth Toolkit with Multiple Grants

Could not import 'oauth2_provider.ext.rest_framework.OAuth2Authentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'

Integrate Django Oauth Toolkit urls correctly

Client Authentication in Django rest framework powered App using django-oauth-toolkit

Django Rest_Framework strange error can't import name SkippError

django rest_framework permission error

django-oauth-toolkit; Django Rest Framework - Authentication credentials were not provided

django-oauth-toolkit : Customize authenticate response

django rest_framework custom exception error

Token authentication in django (rest_framework) not working

Pagination not working for viewsets in django rest_framework

Django serializers vs rest_framework serializers

Migration error on Django + django-oauth-toolkit

Rest_framework import issue

Django rest_framework relations

Django: Could not import settings

Django oauth toolkit not work with apache

Django rest_framework IsAdminUser not behaving

raise exception in django oauth toolkit

Unable to import 'rest_framework'pylint(import-error)

Import "rest_framework" could not be resolved. But I have installed djangorestframework, I don't know what is going wrong

Django Oauth Toolkit: User data over introspection

Django rest_framework oAuth2 APIView error

Django cannot import name 'Response' from 'rest_framework'

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive