Reputation: 45
I am running django application with django knox token authentication. I was able to do login with the package.
But after the token expired, url response are throwing " Invalid Token".
I don't understand how to refresh the token after expiry? whether i need to login again? if it is, the user will get irritated.
How to do it in proper way?
Which is the best token authentication for django rest framework?
Upvotes: 1
Views: 1665
Reputation: 2124
What worked for me is:
#setting.py
REST_KNOX = {
'TOKEN_TTL': timedelta(hours=10), #time to live (without refresh)
'TOKEN_LIMIT_PER_USER': None,
'AUTO_REFRESH': True,
'MIN_REFRESH_INTERVAL': 60 #number of seconds
}
You can of course change the settings. If you don't specify the 'MIN_REFRESH_INTERVAL'
it doesn't work.
The advantage of knox IMOP is that the token refresh is done automatically, and you don't have to do it yourself (unlike JWT, where you need to specifically ask for a new token with the refresh token).
It's less secure than JWT. But the plus is that you have less work to do on the client side.
Upvotes: 2