Social Authentication from drf_social_oauth2 : error with django.urls.exceptions.NoReverseMatch: 'social' is not a registered namespace

I'm developing an new application with an Angular and Django Rest Framework stack.

In my API, I use drf_social_oauth2 for a Social Authentication. The token exchanges are successful. Tokens and users are created on the database.

However, the authentication for others views are in failure.

I use this type of authentication_classes in my others views :

from rest_framework import authentication
from drf_social_oauth2.authentication import SocialAuthentication

class UsersListApiView(APIView):
    authentication_classes = [authentication.TokenAuthentication, SocialAuthentication]

My URLs are :

path('auth/login/', obtain_auth_token, name='login'),
path('auth/', include('dj_rest_auth.urls')), 
path('auth/registration/', include('dj_rest_auth.registration.urls')),
re_path(r'^auth/', include('drf_social_oauth2.urls', namespace='drf')),

This is a part of my settings.py file :

AUTHENTICATION_BACKENDS = [
    # Google OAuth2
    'social_core.backends.google.GoogleOAuth2',
    
    # Facebook OAuth2
    'social_core.backends.facebook.FacebookAppOAuth2',
    'social_core.backends.facebook.FacebookOAuth2',
    
    # drf_social_oauth2
    'drf_social_oauth2.backends.DjangoOAuth2',
    
    # DJango
    'django.contrib.auth.backends.ModelBackend',
]

# Facebook configuration
SOCIAL_AUTH_FACEBOOK_KEY = ''
SOCIAL_AUTH_FACEBOOK_SECRET = ''

# Define SOCIAL_AUTH_FACEBOOK_SCOPE to get extra permissions from Facebook.
# Email is not sent by default, to get it, you must request the email permission.
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']
SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {
    'fields': 'id, name, email'
}

# Google configuration
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = ""
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = ""

# Define SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE to get extra permissions from Google.
SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = [
    'https://www.googleapis.com/auth/userinfo.email',
    'https://www.googleapis.com/auth/userinfo.profile',
]
REST_FRAMEWORK = {
    'DEFAULT_SCHEMA_CLASS':'rest_framework.schemas.coreapi.AutoSchema',
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.SessionAuthentication',
        'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
        'drf_social_oauth2.authentication.SocialAuthentication',
        'rest_framework.authentication.TokenAuthentication',
    ],
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
}
SITE_ID = 2

When I call a view with the SocialAuthentication class and the Authorization bearer that I received from the convert-token URL (as Authorization: Bearer facebook <token>), I have this type of error :

django.urls.exceptions.NoReverseMatch: 'social' is not a registered namespace

So, I don't understand, why I have this type of error, only on the URL that I call with this type of Bearer.

Thanks

Back to Top