I have this APIView to activate a user:
class UserActivationView(APIView):
authentication_classes = ([])
permission_classes = [AllowAny]
"""
Intermediate view to activate a user's email.
"""
def get (self, request, uid, token):
protocol = 'https://' if request.is_secure() else 'http://'
web_url = protocol + request.get_host()
post_url = web_url + "/auth/users/activate/"
post_data = {'uid': uid, 'token': token}
result = requests.post(post_url, data = post_data)
content = result.text
return Response(content)
I need to access it from a link in an email sent using Djoser
But I get this error when accessing the APIView:
HTTP 200 OK
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept
"{\"detail\":\"Authentication credentials were not provided.\"}"
View path in users:
path('activate-user/<str:uid>/<str:token>/', views.UserActivationView.as_view()),
The urlConf:
# Register API
apipatterns = [
path('', include('activities.urls')),
path('', include('social_auth.urls')),
path('', include('users.urls')),
]
urlpatterns = [
path('admin/', admin.site.urls),
path('api/v1/', include(apipatterns)),
path('auth/', include('djoser.urls')),
path('auth-token/', include('djoser.urls.authtoken')),
re_path(r'^$', views.index, name='index'),
]
DRF options:
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
'rest_framework.authentication.BasicAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.IsAuthenticated',
'rest_framework.permissions.AllowAny',
],
'DEFAULT_FILTER_BACKENDS': (
'django_filters.rest_framework.DjangoFilterBackend',
),
}
I can access the endpoint with no credentials using this code:
The other error blocking the request is using a wrong
Djoseractivation urlit's:
/auth/users/activation/not:
/auth/users/activate/I used before