Skip to content
This repository was archived by the owner on May 26, 2020. It is now read-only.

Commit 0a0bd40

Browse files
authored
Return decoded payload in authenticate (#370)
This allows for accessing it on `request.auth` easily then.
1 parent 38897e7 commit 0a0bd40

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

rest_framework_jwt/authentication.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def authenticate(self, request):
4242

4343
user = self.authenticate_credentials(payload)
4444

45-
return (user, jwt_value)
45+
return (user, payload)
4646

4747
def authenticate_credentials(self, payload):
4848
"""

tests/test_authentication.py

+7
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ def test_post_form_passing_jwt_auth(self):
6464
self.assertEqual(response.status_code, status.HTTP_200_OK)
6565
self.assertEqual(response.content, b'mockview-post')
6666

67+
# Ensure `authenticate` returned the decoded payload.
68+
self.assertEqual(response.wsgi_request.user, self.user)
69+
payload = response.wsgi_request.auth
70+
self.assertIsInstance(payload, dict)
71+
self.assertEqual(set(payload.keys()), {
72+
'user_id', 'username', 'exp', 'email'})
73+
6774
def test_post_json_passing_jwt_auth(self):
6875
"""
6976
Ensure POSTing JSON over JWT auth with correct credentials

0 commit comments

Comments
 (0)