dj-jwt-auth 1.5.6__tar.gz → 1.5.8__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.
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/PKG-INFO +1 -1
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/dj_jwt_auth.egg-info/PKG-INFO +1 -1
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/django_jwt/pkce.py +3 -3
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/django_jwt/settings.py +4 -1
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/django_jwt/user.py +1 -1
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/django_jwt/utils.py +6 -0
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/django_jwt/views.py +6 -10
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/setup.cfg +1 -1
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/MANIFEST.in +0 -0
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/README.md +0 -0
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/dj_jwt_auth.egg-info/SOURCES.txt +0 -0
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/dj_jwt_auth.egg-info/dependency_links.txt +0 -0
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/dj_jwt_auth.egg-info/requires.txt +0 -0
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/dj_jwt_auth.egg-info/top_level.txt +0 -0
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/django_jwt/__init__.py +0 -0
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/django_jwt/config.py +0 -0
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/django_jwt/exceptions.py +0 -0
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/django_jwt/middleware.py +0 -0
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/django_jwt/roles.py +0 -0
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/django_jwt/templates/admin/login.html +0 -0
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/django_jwt/templates/django-jwt-index.html +0 -0
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/django_jwt/urls.py +0 -0
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/pyproject.toml +0 -0
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/setup.py +0 -0
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/tests/__init__.py +0 -0
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/tests/models.py +0 -0
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/tests/test.py +0 -0
- {dj-jwt-auth-1.5.6 → dj-jwt-auth-1.5.8}/tests/urls.py +0 -0
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import base64
|
|
2
2
|
import hashlib
|
|
3
|
-
|
|
4
|
-
import
|
|
3
|
+
|
|
4
|
+
from django_jwt.utils import get_random_string
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
class PKCESecret:
|
|
8
8
|
"""PKCE secret."""
|
|
9
9
|
|
|
10
10
|
def __init__(self, length: int = 128):
|
|
11
|
-
self.value =
|
|
11
|
+
self.value = get_random_string(length)
|
|
12
12
|
|
|
13
13
|
def __str__(self) -> str:
|
|
14
14
|
return self.value
|
|
@@ -42,8 +42,11 @@ OIDC_ADMIN_ISSUER = getattr(settings, "OIDC_ADMIN_ISSUER", None)
|
|
|
42
42
|
OIDC_ADMIN_CLIENT_ID = getattr(settings, "OIDC_ADMIN_CLIENT_ID", "cs-completeanatomy-admin")
|
|
43
43
|
OIDC_ADMIN_SCOPE = getattr(settings, "OIDC_ADMIN_SCOPE", "openid")
|
|
44
44
|
OIDC_ADMIN_ROLES = getattr(settings, "OIDC_ADMIN_ROLES", [])
|
|
45
|
+
OIDC_ADMIN_REDIRECT_URI = getattr(settings, "OIDC_ADMIN_REDIRECT_URI", None)
|
|
45
46
|
OIDC_AUTHORIZATION_BACKEND = getattr(
|
|
46
|
-
settings,
|
|
47
|
+
settings,
|
|
48
|
+
"OIDC_AUTHORIZATION_BACKEND",
|
|
49
|
+
"django.contrib.auth.backends.ModelBackend",
|
|
47
50
|
)
|
|
48
51
|
|
|
49
52
|
if not OIDC_ADMIN_ISSUER:
|
|
@@ -43,7 +43,7 @@ class UserHandler:
|
|
|
43
43
|
"""Collect user data from KeyCloak"""
|
|
44
44
|
|
|
45
45
|
user_data = oidc_handler.get_user_info(self.access_token)
|
|
46
|
-
log.info(f"User data: {
|
|
46
|
+
log.info(f"User data: {user_data}, access_token: {self.access_token}")
|
|
47
47
|
self.kwargs["email"] = user_data["email"].lower()
|
|
48
48
|
self.kwargs.update(mapper(user_data))
|
|
49
49
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import base64
|
|
2
2
|
import json
|
|
3
|
+
import random
|
|
4
|
+
import string
|
|
3
5
|
|
|
4
6
|
import jwt
|
|
5
7
|
import requests
|
|
@@ -8,6 +10,10 @@ from django_jwt import settings
|
|
|
8
10
|
from django_jwt.config import config
|
|
9
11
|
|
|
10
12
|
|
|
13
|
+
def get_random_string(k: int = 32) -> str:
|
|
14
|
+
return "".join(random.choices(string.ascii_letters + string.digits + "-._~", k=k))
|
|
15
|
+
|
|
16
|
+
|
|
11
17
|
def get_alg(token: str) -> str:
|
|
12
18
|
header = json.loads(base64.b64decode(token.split(".")[0] + "==="))
|
|
13
19
|
return header["alg"]
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import base64
|
|
2
|
-
import random
|
|
3
|
-
import string
|
|
4
2
|
from logging import getLogger
|
|
5
3
|
from urllib.parse import urlencode
|
|
6
4
|
|
|
7
|
-
from django.conf import settings
|
|
8
5
|
from django.contrib.auth import login
|
|
9
6
|
from django.core.cache import cache
|
|
10
7
|
from django.http.response import HttpResponse
|
|
@@ -18,7 +15,7 @@ from django_jwt.config import config
|
|
|
18
15
|
from django_jwt.exceptions import BadRequestException, ConfigException
|
|
19
16
|
from django_jwt.pkce import PKCESecret
|
|
20
17
|
from django_jwt.user import UserHandler, role_handler
|
|
21
|
-
from django_jwt.utils import get_access_token, oidc_handler
|
|
18
|
+
from django_jwt.utils import get_access_token, get_random_string, oidc_handler
|
|
22
19
|
|
|
23
20
|
log = getLogger(__name__)
|
|
24
21
|
|
|
@@ -60,12 +57,11 @@ class AbsView(View):
|
|
|
60
57
|
class StartOIDCAuthView(AbsView):
|
|
61
58
|
def get(self, request):
|
|
62
59
|
pkce_secret = PKCESecret()
|
|
63
|
-
redirect_uri =
|
|
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"))
|
|
64
63
|
authorization_endpoint = config.admin().get("authorization_endpoint")
|
|
65
|
-
state = base64.urlsafe_b64encode(
|
|
66
|
-
"".join(random.choices(string.ascii_letters + string.digits + "-._~", k=32)).encode()
|
|
67
|
-
).decode()
|
|
68
|
-
random_nonce = "".join(random.choices(string.ascii_letters + string.digits + "-._~", k=32))
|
|
64
|
+
state = base64.urlsafe_b64encode(get_random_string().encode()).decode()
|
|
69
65
|
params = {
|
|
70
66
|
"client_id": jwt_settings.OIDC_ADMIN_CLIENT_ID,
|
|
71
67
|
"redirect_uri": redirect_uri,
|
|
@@ -75,7 +71,7 @@ class StartOIDCAuthView(AbsView):
|
|
|
75
71
|
"code_challenge": pkce_secret.challenge,
|
|
76
72
|
"code_challenge_method": pkce_secret.challenge_method,
|
|
77
73
|
"ui_locales": "en",
|
|
78
|
-
"nonce":
|
|
74
|
+
"nonce": get_random_string(),
|
|
79
75
|
}
|
|
80
76
|
cache.set(state, str(pkce_secret), timeout=600)
|
|
81
77
|
log.info(f"OIDC Admin login: {authorization_endpoint}?{urlencode(params)}")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|