dj-jwt-auth 1.8.0__tar.gz → 1.9.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.8.0 → dj_jwt_auth-1.9.1}/PKG-INFO +1 -2
  2. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/README.md +1 -2
  3. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/dj_jwt_auth.egg-info/PKG-INFO +1 -2
  4. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/django_jwt/views.py +55 -38
  5. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/setup.cfg +1 -1
  6. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/MANIFEST.in +0 -0
  7. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/dj_jwt_auth.egg-info/SOURCES.txt +0 -0
  8. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/dj_jwt_auth.egg-info/dependency_links.txt +0 -0
  9. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/dj_jwt_auth.egg-info/requires.txt +0 -0
  10. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/dj_jwt_auth.egg-info/top_level.txt +0 -0
  11. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/django_jwt/__init__.py +0 -0
  12. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/django_jwt/config.py +0 -0
  13. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/django_jwt/exceptions.py +0 -0
  14. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/django_jwt/middleware.py +0 -0
  15. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/django_jwt/pkce.py +0 -0
  16. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/django_jwt/roles.py +0 -0
  17. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/django_jwt/settings.py +0 -0
  18. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/django_jwt/templates/admin/login.html +0 -0
  19. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/django_jwt/templates/django-jwt-index.html +0 -0
  20. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/django_jwt/urls.py +0 -0
  21. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/django_jwt/user.py +0 -0
  22. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/django_jwt/utils.py +0 -0
  23. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/pyproject.toml +0 -0
  24. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/setup.py +0 -0
  25. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/tests/__init__.py +0 -0
  26. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/tests/models.py +0 -0
  27. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.1}/tests/test.py +0 -0
  28. {dj_jwt_auth-1.8.0 → dj_jwt_auth-1.9.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.8.0
3
+ Version: 1.9.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
@@ -137,4 +137,3 @@ Login URL will be available at `/admin/oidc/`.
137
137
 
138
138
  ### Testing:
139
139
  Run command `python runtests.py` to run tests.
140
- To run specific test use `python runtests.py <test_name>`, like `python runtests.py "tests.test.OIDCHandlerTest.test_new_email_exists"`.
@@ -107,5 +107,4 @@ urlpatterns = [
107
107
  Login URL will be available at `/admin/oidc/`.
108
108
 
109
109
  ### Testing:
110
- Run command `python runtests.py` to run tests.
111
- To run specific test use `python runtests.py <test_name>`, like `python runtests.py "tests.test.OIDCHandlerTest.test_new_email_exists"`.
110
+ Run command `python runtests.py` to run tests.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dj-jwt-auth
3
- Version: 1.8.0
3
+ Version: 1.9.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
@@ -137,4 +137,3 @@ Login URL will be available at `/admin/oidc/`.
137
137
 
138
138
  ### Testing:
139
139
  Run command `python runtests.py` to run tests.
140
- To run specific test use `python runtests.py <test_name>`, like `python runtests.py "tests.test.OIDCHandlerTest.test_new_email_exists"`.
@@ -39,68 +39,85 @@ def index_response(request, msg, status=400):
39
39
  )
40
40
 
41
41
 
42
- class AbsView(View):
43
- def dispatch(self, request, *args, **kwargs):
44
- try:
45
- return super().dispatch(request, *args, **kwargs)
46
- except HTTPError as exc:
47
- log.warning(f"OIDC Admin HTTPError: {exc}")
48
- return index_response(request=request, msg=exc.response.text, status=exc.response.status_code)
49
- except ConfigException as exc:
50
- return HttpResponse(content=str(exc), status=500)
51
- except BadRequestException as exc:
52
- return index_response(request=request, msg=str(exc))
53
- except Exception as exc:
54
- return index_response(request=request, msg=str(exc))
42
+ class InitiateView(View):
43
+ callback_view_name = "receive_redirect_view"
44
+ client_id = None
45
+ scope = "openid"
46
+ params = {}
55
47
 
56
-
57
- class StartOIDCAuthView(AbsView):
58
48
  def get(self, request):
59
49
  pkce_secret = PKCESecret()
60
- redirect_uri = jwt_settings.OIDC_ADMIN_REDIRECT_URI
61
- if not redirect_uri:
62
- redirect_uri = request.build_absolute_uri(reverse("receive_redirect_view"))
50
+ redirect_uri = request.build_absolute_uri(reverse(self.callback_view_name))
63
51
  authorization_endpoint = config.admin().get("authorization_endpoint")
64
52
  state = base64.urlsafe_b64encode(get_random_string().encode()).decode()
65
- params = {
66
- "client_id": jwt_settings.OIDC_ADMIN_CLIENT_ID,
53
+ self.params = {
54
+ "client_id": self.client_id,
67
55
  "redirect_uri": redirect_uri,
68
56
  "response_type": "code",
69
57
  "state": state,
70
- "scope": jwt_settings.OIDC_ADMIN_SCOPE,
58
+ "scope": self.scope,
71
59
  "code_challenge": pkce_secret.challenge,
72
60
  "code_challenge_method": pkce_secret.challenge_method,
73
61
  "ui_locales": "en",
74
62
  "nonce": get_random_string(),
75
63
  }
76
64
  cache.set(state, str(pkce_secret), timeout=600)
77
- log.info(f"OIDC Admin login: {authorization_endpoint}?{urlencode(params)}")
78
- return redirect(f"{authorization_endpoint}?{urlencode(params)}")
65
+ log.info(f"OIDC Initiate: {authorization_endpoint}?{urlencode(self.params)}")
66
+ return redirect(f"{authorization_endpoint}?{urlencode(self.params)}")
79
67
 
80
68
 
81
- class ReceiveRedirectView(AbsView):
82
- def get(self, request):
69
+ class CallbackView(View):
70
+ callback_view_name = "receive_redirect_view"
71
+ user = None
72
+ payload = None
73
+
74
+ def fail(self, request, msg):
75
+ raise BadRequestException(msg)
76
+
77
+ def dispatch(self, request, *args, **kwargs):
83
78
  code = request.GET.get("code")
84
79
  state = request.GET.get("state")
85
80
  if not code or not state:
86
- log.warning(f"No code or state in the request {request.GET}")
87
- raise BadRequestException("No code or state in the request")
81
+ log.warning(f"OIDC No code or state in the request {request.GET}")
82
+ return self.fail(request, "No code or state in the request")
88
83
 
89
- redirect_uri = request.build_absolute_uri(reverse("receive_redirect_view"))
84
+ redirect_uri = request.build_absolute_uri(self.callback_view_name)
90
85
  if state := cache.get(state):
91
86
  token = get_access_token(code, redirect_uri, state)
92
- data = oidc_handler.decode_token(token)
93
- user = UserHandler(data, request, token).get_user()
94
- log.info(f"OIDC Admin login: {user}", extra={"data": data})
95
- roles = role_handler.apply(user, data)
96
- if not user.is_staff:
97
- raise BadRequestException(f"User {user.email} is not staff\nRoles: {roles}")
98
- login(request, user, backend=jwt_settings.OIDC_AUTHORIZATION_BACKEND)
99
- return redirect("admin:index")
87
+ self.payload = oidc_handler.decode_token(token)
88
+ self.user = UserHandler(self.payload, request, token).get_user()
89
+ return super().dispatch(request, *args, **kwargs)
90
+ return self.fail(request, "No PKCE secret found in cache")
100
91
 
101
- raise BadRequestException("No PKCE secret found in cache")
92
+
93
+ class StartOIDCAuthView(InitiateView):
94
+ client_id = jwt_settings.OIDC_ADMIN_CLIENT_ID
95
+ scope = jwt_settings.OIDC_ADMIN_SCOPE
96
+
97
+
98
+ class ReceiveRedirectView(CallbackView):
99
+ def dispatch(self, request, *args, **kwargs):
100
+ try:
101
+ return super().dispatch(request, *args, **kwargs)
102
+ except HTTPError as exc:
103
+ log.warning(f"OIDC Admin HTTPError: {exc}")
104
+ return index_response(request=request, msg=exc.response.text, status=exc.response.status_code)
105
+ except ConfigException as exc:
106
+ return HttpResponse(content=str(exc), status=500)
107
+ except BadRequestException as exc:
108
+ return index_response(request=request, msg=str(exc))
109
+ except Exception as exc:
110
+ return index_response(request=request, msg=str(exc))
111
+
112
+ def get(self, request):
113
+ log.info(f"OIDC Admin login: {self.user}", extra={"data": self.payload})
114
+ roles = role_handler.apply(self.user, self.payload)
115
+ if not self.user.is_staff:
116
+ raise BadRequestException(f"User {self.user.email} is not staff\nRoles: {roles}")
117
+ login(request, self.user, backend=jwt_settings.OIDC_AUTHORIZATION_BACKEND)
118
+ return redirect("admin:index")
102
119
 
103
120
 
104
- class LogoutView(AbsView):
121
+ class LogoutView(View):
105
122
  def get(self, request):
106
123
  return index_response(request, "Logged out", status=401)
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = dj-jwt-auth
3
- version = 1.8.0
3
+ version = 1.9.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/
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes