JWT authentication does not work in Django Rest Framework after deploying it to IIS on live server

Question:

I built a Rest API using Django’s Rest framework. And I’ve deployed it on Windows OS’s IIS. When I deploy the application to the live IIS server, it throws the following issue even though it functions well on the local IIS server. I have used wfastcgi package for deploying my application to IIS.

DEFAULT_AUTHENTICATION_CLASSES in settings.py:

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    )
}

Here’s an example request in postman:
enter image description here

Asked By: parth panchal

||

Answers:

Maybe the error was in settings.py file because I haven’t updated the CORS_ALLOWED_ORIGINS so I changed it as below:

Here’s the snippet of code on my local machine

CORS_ALLOWED_ORIGINS = [
    "http://localhost:8000",
    "http://127.0.0.1:8000",
]

Here’s the snippet of code on my live server,

CORS_ALLOWED_ORIGINS = [
    "https://www.example.com"
]
Answered By: parth panchal