dj-jwt-auth 1.7.0__py3-none-any.whl → 1.7.1__py3-none-any.whl
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.
- {dj_jwt_auth-1.7.0.dist-info → dj_jwt_auth-1.7.1.dist-info}/METADATA +1 -1
- {dj_jwt_auth-1.7.0.dist-info → dj_jwt_auth-1.7.1.dist-info}/RECORD +8 -8
- {dj_jwt_auth-1.7.0.dist-info → dj_jwt_auth-1.7.1.dist-info}/WHEEL +1 -1
- django_jwt/config.py +4 -1
- django_jwt/exceptions.py +6 -0
- django_jwt/middleware.py +3 -0
- tests/test.py +21 -0
- {dj_jwt_auth-1.7.0.dist-info → dj_jwt_auth-1.7.1.dist-info}/top_level.txt +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
django_jwt/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
django_jwt/config.py,sha256
|
|
3
|
-
django_jwt/exceptions.py,sha256=
|
|
4
|
-
django_jwt/middleware.py,sha256=
|
|
2
|
+
django_jwt/config.py,sha256=zPPlRw1tvE-DQGk0Q3avZmrYVG98GM9vigK1GqDAQeE,1703
|
|
3
|
+
django_jwt/exceptions.py,sha256=S8HeH_lu8XSsejhyW0qkl04MmXxxbN4-zrtyPywbBwc,311
|
|
4
|
+
django_jwt/middleware.py,sha256=jk3M9qumI0p4rVvmkZM1jAf5xzaVl5FmAqrR-jAO_Po,1288
|
|
5
5
|
django_jwt/pkce.py,sha256=j-v2ffCw0X3JW7ak8vfNeSZI-dACOvHbi1eLmJ0R8gM,685
|
|
6
6
|
django_jwt/roles.py,sha256=SaHK3o8T8USS4ZhG4SrHPlZQV2lMb2t1UZHT6IQtBvA,143
|
|
7
7
|
django_jwt/settings.py,sha256=pXQ8WUU4LGBe6PQxCLTLM_2_b1CCSgehqim3yJDqZdw,1922
|
|
@@ -13,9 +13,9 @@ django_jwt/templates/django-jwt-index.html,sha256=y8f0v2WbRAFxnIU799I_MZCVsjn1sb
|
|
|
13
13
|
django_jwt/templates/admin/login.html,sha256=Nihyu0IGvDDZVvQDITXozwlj6XCQ0B8gqlyHLqVNyJc,275
|
|
14
14
|
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
15
|
tests/models.py,sha256=tJlhRARVGfFIH6Gp1o00buZKcY2oAk7HNw2PMnkTEDs,295
|
|
16
|
-
tests/test.py,sha256=
|
|
16
|
+
tests/test.py,sha256=Llj8u4hyxezdUdCOnM5ogw_hLxC82tiSY6e14W42GjU,11089
|
|
17
17
|
tests/urls.py,sha256=D5FhDSVAudurkrpkCZZPnDvgXSgifwFVB3nAlYBg7uQ,212
|
|
18
|
-
dj_jwt_auth-1.7.
|
|
19
|
-
dj_jwt_auth-1.7.
|
|
20
|
-
dj_jwt_auth-1.7.
|
|
21
|
-
dj_jwt_auth-1.7.
|
|
18
|
+
dj_jwt_auth-1.7.1.dist-info/METADATA,sha256=AxY9nhrLPx8qkqcvIWfXe1TJSsjZ95d4cjFwfSCJ8zM,4416
|
|
19
|
+
dj_jwt_auth-1.7.1.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
20
|
+
dj_jwt_auth-1.7.1.dist-info/top_level.txt,sha256=58O7TdK-yECZcbmPc52KNlBFpjIUlENuZubCxaSOxus,17
|
|
21
|
+
dj_jwt_auth-1.7.1.dist-info/RECORD,,
|
django_jwt/config.py
CHANGED
|
@@ -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()
|
django_jwt/exceptions.py
CHANGED
django_jwt/middleware.py
CHANGED
|
@@ -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:
|
tests/test.py
CHANGED
|
@@ -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
|