Skip to content

Commit

Permalink
BOM-1845 (#136)
Browse files Browse the repository at this point in the history
Latest drf-jwt is causing failures for any other auth header value other than jwt.
Fixed that issue in JwtAuthentication class.
Bump the version.
  • Loading branch information
iamsobanjaved authored Jul 19, 2020
1 parent 5b26b53 commit 1f98132
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
10 changes: 10 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ Unreleased

*

[6.1.1] - 2020-07-19
--------------------

Fixed
~~~~~~~

* Latest `drf-jwt` is throwing error in case of any other Authorization Header. Fixing that issue in `JwtAuthentication` class.



[6.1.0] - 2020-06-26
--------------------

Expand Down
2 changes: 1 addition & 1 deletion edx_rest_framework_extensions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
""" edx Django REST Framework extensions. """

__version__ = '6.1.0' # pragma: no cover
__version__ = '6.1.1' # pragma: no cover
6 changes: 6 additions & 0 deletions edx_rest_framework_extensions/auth/jwt/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ def get_jwt_claim_mergeable_attributes(self):
return get_setting('JWT_PAYLOAD_MERGEABLE_USER_ATTRIBUTES')

def authenticate(self, request):
# latest drf-jwt version throws error for any other value other than jwt. So returns None and pass it to other
# Authentication class
auth_header_value = request.environ.get('HTTP_AUTHORIZATION')
if auth_header_value and not auth_header_value.lower().startswith('jwt'):
return None

try:
user_and_auth = super(JwtAuthentication, self).authenticate(request)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,16 @@ def test_get_decoded_jwt_from_auth(self, is_jwt_authentication):

decoded_jwt = authentication.get_decoded_jwt_from_auth(mock_request_with_cookie)
self.assertEqual(expected_decoded_jwt, decoded_jwt)

def test_with_explicitly_jwt_authorization(self):
""" With JWT header it continues and validates the credentials and throws error. """
auth_header = '{token_name} {token}'.format(token_name='JWT', token='wrongvalue')
request = RequestFactory().get('/', HTTP_AUTHORIZATION=auth_header)
with self.assertRaises(AuthenticationFailed):
JwtAuthentication().authenticate(request)

def test_jwt_returns_none_for_bearer_header(self):
""" Returns a None for bearer header request. """
auth_header = '{token_name} {token}'.format(token_name='Bearer', token='abc123')
request = RequestFactory().get('/', HTTP_AUTHORIZATION=auth_header)
self.assertIsNone(JwtAuthentication().authenticate(request))

0 comments on commit 1f98132

Please sign in to comment.