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