django-rest-framework-jwt
django-rest-framework-jwt copied to clipboard
Unable to override the default settings
None of the changes I do to override the default settings seem to work. In particular, I want to increase the expiration delta by a lot more and use my own decoder. Anything I'm doing wrong? Let me know if I need to add more information.
Django==1.8.4 PyJWT==1.4.0 djangorestframework==3.2.4 djangorestframework-jwt==1.7.2
JWT_AUTH = { 'JWT_VERIFY': False, 'JWT_VERIFY_EXPIRATION': False, 'JWT_LEEWAY': 0, 'JWT_EXPIRATION_DELTA' : datetime.timedelta(seconds=30000000), 'JWT_AUDIENCE': None, 'JWT_ISSUER': None, 'JWT_ALLOW_REFRESH': True, 'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(days=365), 'JWT_AUTH_HEADER_PREFIX': 'JWT', 'JWT_DECODE_HANDLER': 'mywrapper.views.my_decode_handler',
}
INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'attendance', 'notice', 'marks', 'accounts', 'mywrapper', 'rest_framework', 'rest_framework_swagger', "push_notifications", 'rest_framework_jwt', )
Having the same trouble. Signature keeps getting expired.
Not sure though, can you set the JWT_AUTH 'after' the INSTALLED_APPS in the settings.py. Maybe the default settings are overriding your ones.
I did the same @saurabhmaurya06 and it worked well.
@blaklites order doesn't matter at all. Because DRF-JWT just looks for JWT_AUTH in the settings file it doesn't matter its in the beginning or in the end.
@vaibhav-jain I am not talking about the order actually, I am talking about your value being over written by the original one, will have to check actually though.
@saurabhmaurya06 You should to add rest_framework.authtoken in your INSTALLED_APPS settings. source - Docs
I still have the same problem and tried the things mentioned here. Any other things I could try? The app itself is very simple so far.
Have you figured it out?
@datrinh You've not described your issue, have you?
I'm also running into the same issue. Appreciate any assistance anyone can provide.
I am assuming I'm missing something that is probably obvious to the pros. I was going to post this at https://github.com/GetBlimp/django-rest-framework-jwt/issues/190; however, I found this thread to be more applicable to my issue.
First I'm receiving the following response to my refresh attempts:
{
"non_field_errors": [
"orig_iat field is required."
]
}
Even though my settings.py appears to be correct based on code and documentation my token doesn't seem to adhere to the 7 days I have set it to either. What's odd is that when my token is expired I do receive the below:
{
"non_field_errors": [
"Signature has expired."
]
}
So I'm assuming the 'JWT_ALLOW_REFRESH': True, is working?
I saw a similar same issue at https://github.com/GetBlimp/django-rest-framework-jwt/issues/134 but, again, I feel I am overwriting the settings correctly.
INSTALLED_APPS = [
'testapp',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'corsheaders',
]
import datetime
JWT_AUTH = {
'JWT_EXPIRATION_DELTA': datetime.timedelta(hours=1),
'JWT_ALLOW_REFRESH': True,
}
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
),
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 10
}
Looking a bit further, I'm also not seeing orig_iat being passed in the token. Below is my token and I'm not seeing it in the decoded version... Should it be there?
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6InRnb3J1cCIsImV4cCI6MTUzMDYyNjUzOCwiZW1haWwiOiJ0b21AdGVzdGFwcC5pbyJ9.3VMrJuj5PiWuNI6mlvQswn2HXmNJij3gsYD6fRQtSzA
Decoded Web Token: here

Versions
djangorestframework==3.8.2
djangorestframework-jwt==1.11.0
Appreciate any assistance. Thanks!
So any update on this?
add this to settings JWT_AUTH = { 'JWT_EXPIRATION_DELTA': datetime.timedelta(hours=1), 'JWT_ALLOW_REFRESH': True, }
In my case the problem was in the route configurations
from django.conf.urls import url, include
from rest_framework import routers
from rest_framework_jwt.views import obtain_jwt_token
router = routers.DefaultRouter()
...
urlpatterns = [
url(r'^', include(router.urls)),
# I WAS USING THIS
url(r'^auth/', include('rest_auth.urls'))
#INSTEAD OF THIS
url(r'^auth/', obtain_jwt_token),
]
Plus the 'JWT_ALLOW_REFRESH': True should be set to True. Like below:
JWT_AUTH = {
#THIS IS MANDATORY
'JWT_ALLOW_REFRESH': True,
'JWT_AUTH_HEADER_PREFIX': 'Bearer',
'JWT_RESPONSE_PAYLOAD_HANDLER': 'xxxx.jwt_response_payload_handler',
}
any updates on this issue?