dj-jwt-auth 1.9.4__py3-none-any.whl → 1.9.6__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dj-jwt-auth
3
- Version: 1.9.4
3
+ Version: 1.9.6
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
@@ -102,12 +102,9 @@ OR
102
102
  These functions should accept two arguments: user and request.
103
103
 
104
104
  ### Admin panel integration:
105
- To integrate admin panel with OIDC, add OIDC_ADMIN_ISSUER and OIDC_ADMIN_CLIENT_ID to settings.
106
- - OIDC_ADMIN_ISSUER - for admin-panel access through OIDC. By default will be used 'ES256' from OIDC_CONFIG_ROUTES. Example:
107
- ```
108
- OIDC_ADMIN_ISSUER = "https://keyCloak/realms/h/.well-known/openid-configuration"
109
- ```
105
+ To integrate admin panel with OIDC, add OIDC_ADMIN_CLIENT_ID to settings. Example:
110
106
  - OIDC_ADMIN_CLIENT_ID - by default "complete-anatomy"
107
+ By default will be used 'ES256' from OIDC_CONFIG_ROUTES as Issuer.
111
108
  To mapping roles to admin panel permissions, use OIDC_ADMIN_ROLES. Example:
112
109
 
113
110
  ```python
@@ -1,21 +1,21 @@
1
1
  django_jwt/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- django_jwt/config.py,sha256=zPPlRw1tvE-DQGk0Q3avZmrYVG98GM9vigK1GqDAQeE,1703
2
+ django_jwt/config.py,sha256=rJTLgFo42iuxZ4pk2tecmlp2fKcyX7QDDsOrnEKjC6c,1506
3
3
  django_jwt/exceptions.py,sha256=S8HeH_lu8XSsejhyW0qkl04MmXxxbN4-zrtyPywbBwc,311
4
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
- django_jwt/settings.py,sha256=e7-ghBcQAUXZXO8td4ZaGH5VvpYY5zPxJmGQLR9-NSM,1923
7
+ django_jwt/settings.py,sha256=N3v8B4lEM-bGLmAhXhF7hOfdcjKn6afbxDFx7CETcD0,1769
8
8
  django_jwt/urls.py,sha256=ZhcnRcQ1MBRh-bS7fTa-Vkz8yuWUhv-G_uRXKLnKAs0,320
9
9
  django_jwt/user.py,sha256=v2oCoAThstFg5x5cOA9nSKlYWZzCEqhFbz63WGhE_NM,6382
10
- django_jwt/utils.py,sha256=E_D_GxIVmKQYHzKTMEWPqR1zV4l0q40vPolxhcDGQdk,1641
11
- django_jwt/views.py,sha256=WG1xtflDEKbH0LnRiZXPmwCeIxj-B31VgI_4_OoCXlc,4754
10
+ django_jwt/utils.py,sha256=aZBCcGKpxA3rIye2DFEvNWrAmShYtS9Ku9tSc2D1T3k,1685
11
+ django_jwt/views.py,sha256=RcVoLgMeKuaKxDWipFc3RFAgxHqvJ_qwhkb0EjH-Mlg,4852
12
12
  django_jwt/templates/django-jwt-index.html,sha256=y8f0v2WbRAFxnIU799I_MZCVsjn1sbdh7bypjdWB0lA,1353
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=jhoJcCEsx5B9AibmoLQLDD3cEsyYzYy6dMdYhRnBVFo,338
16
16
  tests/test.py,sha256=HEy5DsEYrPmtWSdeDhgdeV2tZTYlepaWt82VoTBrta8,11828
17
17
  tests/urls.py,sha256=D5FhDSVAudurkrpkCZZPnDvgXSgifwFVB3nAlYBg7uQ,212
18
- dj_jwt_auth-1.9.4.dist-info/METADATA,sha256=3muLrnOkU5lsNtEK93A6PsfUwQI7eQPg7dNTZrt0QRM,4416
19
- dj_jwt_auth-1.9.4.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
20
- dj_jwt_auth-1.9.4.dist-info/top_level.txt,sha256=58O7TdK-yECZcbmPc52KNlBFpjIUlENuZubCxaSOxus,17
21
- dj_jwt_auth-1.9.4.dist-info/RECORD,,
18
+ dj_jwt_auth-1.9.6.dist-info/METADATA,sha256=dOvBDqstn_4LI-Ba2XMF729FEXH7N0WAlfynorOu4ok,4251
19
+ dj_jwt_auth-1.9.6.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
20
+ dj_jwt_auth-1.9.6.dist-info/top_level.txt,sha256=58O7TdK-yECZcbmPc52KNlBFpjIUlENuZubCxaSOxus,17
21
+ dj_jwt_auth-1.9.6.dist-info/RECORD,,
django_jwt/config.py CHANGED
@@ -1,4 +1,5 @@
1
1
  import json
2
+ from enum import StrEnum
2
3
  from functools import cache
3
4
  from urllib.parse import urljoin
4
5
 
@@ -9,6 +10,11 @@ from django_jwt import settings
9
10
  from django_jwt.exceptions import AlgorithmNotSupportedException, ConfigException
10
11
 
11
12
 
13
+ class SupportedAlgorithms(StrEnum):
14
+ ES256 = "ES256"
15
+ RS256 = "RS256"
16
+
17
+
12
18
  def ensure_well_known(url: str) -> str:
13
19
  if url.endswith(".well-known/openid-configuration"):
14
20
  return url
@@ -42,13 +48,5 @@ class Config:
42
48
  algorithm = RSAAlgorithm if key_data["kty"] == "RSA" else ECAlgorithm
43
49
  return algorithm.from_jwk(json.dumps(key_data))
44
50
 
45
- @cache
46
- def admin(self) -> dict:
47
- if settings.OIDC_ADMIN_ISSUER:
48
- response = requests.get(ensure_well_known(settings.OIDC_ADMIN_ISSUER))
49
- response.raise_for_status()
50
- return response.json()
51
- raise ConfigException("OIDC_ADMIN_ISSUER is not set")
52
-
53
51
 
54
52
  config = Config()
django_jwt/settings.py CHANGED
@@ -38,7 +38,6 @@ OIDC_USER_ON_UPDATE = getattr(
38
38
  )
39
39
 
40
40
  OIDC_CONFIG_ROUTES = getattr(settings, "OIDC_CONFIG_ROUTES", {})
41
- OIDC_ADMIN_ISSUER = getattr(settings, "OIDC_ADMIN_ISSUER", None)
42
41
  OIDC_ADMIN_CLIENT_ID = getattr(settings, "OIDC_ADMIN_CLIENT_ID", "gme-completeanatomy-admin")
43
42
  OIDC_ADMIN_SCOPE = getattr(settings, "OIDC_ADMIN_SCOPE", "openid")
44
43
  OIDC_ADMIN_ROLES = getattr(settings, "OIDC_ADMIN_ROLES", [])
@@ -49,9 +48,6 @@ OIDC_AUTHORIZATION_BACKEND = getattr(
49
48
  "django.contrib.auth.backends.ModelBackend",
50
49
  )
51
50
 
52
- if not OIDC_ADMIN_ISSUER:
53
- OIDC_ADMIN_ISSUER = OIDC_CONFIG_ROUTES.get("ES256", None)
54
-
55
51
  for role in OIDC_ADMIN_ROLES:
56
52
  assert isinstance(role, ROLE), f"Role must be a namedtuple, got {type(role)}"
57
53
 
django_jwt/utils.py CHANGED
@@ -7,7 +7,7 @@ import jwt
7
7
  import requests
8
8
 
9
9
  from django_jwt import settings
10
- from django_jwt.config import config
10
+ from django_jwt.config import config, SupportedAlgorithms
11
11
 
12
12
 
13
13
  def get_random_string(k: int = 32) -> str:
@@ -20,7 +20,7 @@ def get_alg(token: str) -> str:
20
20
 
21
21
 
22
22
  def get_access_token(code: str, redirect_uri: str, pkce_secret: str, client_id: str) -> str:
23
- token_endpoint = config.admin().get("token_endpoint")
23
+ token_endpoint = config.cfg(SupportedAlgorithms.ES256).get("token_endpoint")
24
24
  data = {
25
25
  "grant_type": "authorization_code",
26
26
  "client_id": client_id,
django_jwt/views.py CHANGED
@@ -11,7 +11,7 @@ from django.views import View
11
11
  from requests.exceptions import HTTPError
12
12
 
13
13
  from django_jwt import settings as jwt_settings
14
- from django_jwt.config import config
14
+ from django_jwt.config import SupportedAlgorithms, config
15
15
  from django_jwt.exceptions import BadRequestException, ConfigException
16
16
  from django_jwt.pkce import PKCESecret
17
17
  from django_jwt.user import UserHandler, role_handler
@@ -25,7 +25,7 @@ def silent_sso_check(request):
25
25
 
26
26
 
27
27
  def index_response(request, msg, status=400):
28
- logout_url = config.admin().get("end_session_endpoint")
28
+ logout_url = config.cfg(SupportedAlgorithms.ES256).get("end_session_endpoint")
29
29
  return render(
30
30
  request,
31
31
  "django-jwt-index.html",
@@ -44,11 +44,12 @@ class InitiateView(View):
44
44
  client_id = None
45
45
  scope = "openid"
46
46
  params = {}
47
+ algorithm = SupportedAlgorithms.ES256
47
48
 
48
49
  def get(self, request):
49
50
  pkce_secret = PKCESecret()
50
51
  redirect_uri = request.build_absolute_uri(reverse(self.callback_view_name))
51
- authorization_endpoint = config.admin().get("authorization_endpoint")
52
+ authorization_endpoint = config.cfg(self.algorithm).get("authorization_endpoint")
52
53
  state = base64.urlsafe_b64encode(get_random_string().encode()).decode()
53
54
  self.params = {
54
55
  "client_id": self.client_id,