Reputation: 333
I am new to Django (not DRF) and I have a hard time configuring my authentication requirements. I have an external authentication service that gets a username and password and returns a JWT. After I have the JWT how should I save the token and provide it with every request from the browser. And after that where can I validate it?
Thanks!
Upvotes: 1
Views: 457
Reputation: 3244
For every call that your service get there should be header to that call
{'Authorization':'Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b'}
And you can use that in views.py as :
if request.user.is_authenticated():
It has to be included in the settings file of that django project.
JWT_AUTH = {
# 'JWT_ENCODE_HANDLER':
# 'rest_framework_jwt.utils.jwt_encode_handler',
# 'JWT_DECODE_HANDLER':
# 'rest_framework_jwt.utils.jwt_decode_handler',
# 'JWT_PAYLOAD_HANDLER':
# 'rest_framework_jwt.utils.jwt_payload_handler',
# 'JWT_PAYLOAD_GET_USER_ID_HANDLER':
# 'rest_framework_jwt.utils.jwt_get_user_id_from_payload_handler',
# 'JWT_RESPONSE_PAYLOAD_HANDLER':
# 'rest_framework_jwt.utils.jwt_response_payload_handler',
# 'JWT_SECRET_KEY': settings.SECRET_KEY,
# 'JWT_ALGORITHM': 'HS256',
# 'JWT_VERIFY': True,
# 'JWT_VERIFY_EXPIRATION': False,
# 'JWT_LEEWAY': 0,
'JWT_EXPIRATION_DELTA': datetime.timedelta(days=1),
# 'JWT_AUDIENCE': None,
# 'JWT_ISSUER': None,
# 'JWT_ALLOW_REFRESH': False,
# 'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(days=7),
# 'JWT_AUTH_HEADER_PREFIX': 'JWT',
}
Read more about it here.
Upvotes: 1