Skip to content

Commit

Permalink
Return decoded payload in authenticate (jpadilla#370)
Browse files Browse the repository at this point in the history
This allows for accessing it on `request.auth` easily then.
  • Loading branch information
blueyed authored Oct 5, 2017
1 parent 38897e7 commit 0a0bd40
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rest_framework_jwt/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def authenticate(self, request):

user = self.authenticate_credentials(payload)

return (user, jwt_value)
return (user, payload)

def authenticate_credentials(self, payload):
"""
Expand Down
7 changes: 7 additions & 0 deletions tests/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ def test_post_form_passing_jwt_auth(self):
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.content, b'mockview-post')

# Ensure `authenticate` returned the decoded payload.
self.assertEqual(response.wsgi_request.user, self.user)
payload = response.wsgi_request.auth
self.assertIsInstance(payload, dict)
self.assertEqual(set(payload.keys()), {
'user_id', 'username', 'exp', 'email'})

def test_post_json_passing_jwt_auth(self):
"""
Ensure POSTing JSON over JWT auth with correct credentials
Expand Down

0 comments on commit 0a0bd40

Please sign in to comment.