dj-jwt-auth 1.7.0__tar.gz → 1.7.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/PKG-INFO +1 -1
  2. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/dj_jwt_auth.egg-info/PKG-INFO +1 -1
  3. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/django_jwt/config.py +4 -1
  4. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/django_jwt/exceptions.py +6 -0
  5. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/django_jwt/middleware.py +3 -0
  6. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/setup.cfg +1 -1
  7. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/tests/test.py +21 -0
  8. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/MANIFEST.in +0 -0
  9. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/README.md +0 -0
  10. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/dj_jwt_auth.egg-info/SOURCES.txt +0 -0
  11. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/dj_jwt_auth.egg-info/dependency_links.txt +0 -0
  12. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/dj_jwt_auth.egg-info/requires.txt +0 -0
  13. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/dj_jwt_auth.egg-info/top_level.txt +0 -0
  14. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/django_jwt/__init__.py +0 -0
  15. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/django_jwt/pkce.py +0 -0
  16. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/django_jwt/roles.py +0 -0
  17. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/django_jwt/settings.py +0 -0
  18. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/django_jwt/templates/admin/login.html +0 -0
  19. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/django_jwt/templates/django-jwt-index.html +0 -0
  20. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/django_jwt/urls.py +0 -0
  21. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/django_jwt/user.py +0 -0
  22. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/django_jwt/utils.py +0 -0
  23. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/django_jwt/views.py +0 -0
  24. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/pyproject.toml +0 -0
  25. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/setup.py +0 -0
  26. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/tests/__init__.py +0 -0
  27. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/tests/models.py +0 -0
  28. {dj_jwt_auth-1.7.0 → dj_jwt_auth-1.7.1}/tests/urls.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dj-jwt-auth
3
- Version: 1.7.0
3
+ Version: 1.7.1
4
4
  Summary: A Django package for JSON Web Token validation and verification. Using PyJWT.
5
5
  Home-page: https://www.example.com/
6
6
  Author: Konstantin Seleznev
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dj-jwt-auth
3
- Version: 1.7.0
3
+ Version: 1.7.1
4
4
  Summary: A Django package for JSON Web Token validation and verification. Using PyJWT.
5
5
  Home-page: https://www.example.com/
6
6
  Author: Konstantin Seleznev
@@ -6,7 +6,7 @@ import requests
6
6
  from jwt.algorithms import ECAlgorithm, RSAAlgorithm
7
7
 
8
8
  from django_jwt import settings
9
- from django_jwt.exceptions import ConfigException
9
+ from django_jwt.exceptions import AlgorithmNotSupportedException, ConfigException
10
10
 
11
11
 
12
12
  def ensure_well_known(url: str) -> str:
@@ -24,6 +24,9 @@ class Config:
24
24
  if not self.route:
25
25
  raise ConfigException("OIDC_CONFIG_ROUTES is not set")
26
26
 
27
+ if alg not in self.route:
28
+ raise AlgorithmNotSupportedException(f"Algorithm {alg} is not supported")
29
+
27
30
  response = requests.get(ensure_well_known(self.route[alg]))
28
31
  response.raise_for_status()
29
32
  return response.json()
@@ -8,3 +8,9 @@ class BadRequestException(Exception):
8
8
  """Base class for exceptions in this module."""
9
9
 
10
10
  pass
11
+
12
+
13
+ class AlgorithmNotSupportedException(Exception):
14
+ """Base class for exceptions in this module."""
15
+
16
+ pass
@@ -5,6 +5,7 @@ from django.http import JsonResponse
5
5
  from django.utils.deprecation import MiddlewareMixin
6
6
  from jwt import ExpiredSignatureError
7
7
 
8
+ from django_jwt.exceptions import AlgorithmNotSupportedException
8
9
  from django_jwt.user import UserHandler
9
10
  from django_jwt.utils import oidc_handler
10
11
 
@@ -27,6 +28,8 @@ class JWTAuthMiddleware(MiddlewareMixin):
27
28
  try:
28
29
  info = oidc_handler.decode_token(raw_token)
29
30
  request.user = request._cached_user = UserHandler(info, request, raw_token).get_user()
31
+ except AlgorithmNotSupportedException as exc:
32
+ return JsonResponse(status=HTTPStatus.UNAUTHORIZED.value, data={"detail": str(exc)})
30
33
  except ExpiredSignatureError:
31
34
  return JsonResponse(status=HTTPStatus.UNAUTHORIZED.value, data={"detail": "expired token"})
32
35
  except UnicodeDecodeError as exc:
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = dj-jwt-auth
3
- version = 1.7.0
3
+ version = 1.7.1
4
4
  description = A Django package for JSON Web Token validation and verification. Using PyJWT.
5
5
  long_description = file: README.md
6
6
  url = https://www.example.com/
@@ -9,6 +9,8 @@ from django.urls import reverse
9
9
  from jwt.api_jwt import ExpiredSignatureError
10
10
 
11
11
  from django_jwt import settings
12
+ from django_jwt.config import config
13
+ from django_jwt.exceptions import ConfigException
12
14
  from django_jwt.middleware import JWTAuthMiddleware
13
15
  from django_jwt.roles import ROLE
14
16
  from django_jwt.user import role_handler
@@ -200,6 +202,25 @@ class OIDCHandlerTest(TestCase):
200
202
  # self.assertEqual(user_info.call_count, 1)
201
203
 
202
204
 
205
+ @patch("django_jwt.utils.get_alg", return_value="HS256")
206
+ class ConfigTest(TestCase):
207
+ def setUp(self):
208
+ self.middleware = JWTAuthMiddleware(get_response=lambda x: x)
209
+ self.request = Mock()
210
+ self.request.META = {"HTTP_AUTHORIZATION": "Bearer Token"}
211
+
212
+ @patch.object(config, "route", {})
213
+ def test_empty_routes(self, *_):
214
+ with self.assertRaises(ConfigException):
215
+ self.middleware.process_request(self.request)
216
+
217
+ @patch.object(config, "route", {"ES256": "http://localhost:8080"})
218
+ def test_not_supported_alg(self, *_):
219
+ response = self.middleware.process_request(self.request)
220
+ self.assertEqual(HTTPStatus.UNAUTHORIZED.value, response.status_code)
221
+ self.assertEqual(b'{"detail": "Algorithm HS256 is not supported"}', response.content)
222
+
223
+
203
224
  class RolesTest(TestCase):
204
225
  def setUp(self) -> None:
205
226
  self.user = User.objects.create(username="user")
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes