jazzband / django-rest-knox

Authentication Module for django rest auth
MIT License
1.1k stars 206 forks source link

BasicAuthentication not working in Django Rest #336

Closed Nishhtha closed 2 months ago

Nishhtha commented 2 months ago

This is my settings.py file -

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.BasicAuthentication',
        # 'rest_framework.authentication.SessionAuthentication',
    ]
}

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'watchList_app',
    'rest_framework',
    # 'rest_framework.authtoken',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

I want to add BasicAuthentication to my project but its directly able to hit the api without needing the credentials

johnraz commented 2 months ago

This is not a topic for this repository, knox is not responsible of authentication in Django Rest Framework.

Nevertheless you are probably missing permissions, please check this tutorial on the official Django Rest Framework documentation https://www.django-rest-framework.org/tutorial/4-authentication-and-permissions/#tutorial-4-authentication-permissions