cardo-python-utils 0.5.dev6__tar.gz → 0.5.dev8__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.
- {cardo_python_utils-0.5.dev6/cardo_python_utils.egg-info → cardo_python_utils-0.5.dev8}/PKG-INFO +4 -5
- {cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8/cardo_python_utils.egg-info}/PKG-INFO +4 -5
- {cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/cardo_python_utils.egg-info/SOURCES.txt +8 -5
- {cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/cardo_python_utils.egg-info/requires.txt +2 -4
- {cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/pyproject.toml +2 -4
- cardo_python_utils-0.5.dev8/python_utils/django/keycloak/admin/__init__.py +0 -0
- cardo_python_utils-0.5.dev8/python_utils/django/keycloak/admin/auth.py +48 -0
- cardo_python_utils-0.5.dev6/python_utils/django/keycloak/admin.py → cardo_python_utils-0.5.dev8/python_utils/django/keycloak/admin/user_group.py +1 -49
- cardo_python_utils-0.5.dev8/python_utils/django/keycloak/api/__init__.py +0 -0
- cardo_python_utils-0.5.dev8/python_utils/django/keycloak/models/__init__.py +0 -0
- cardo_python_utils-0.5.dev6/python_utils/django/keycloak/user_groups_changelist.html +0 -7
- {cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/LICENSE +0 -0
- {cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/MANIFEST.in +0 -0
- {cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/README.rst +0 -0
- {cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/cardo_python_utils.egg-info/dependency_links.txt +0 -0
- {cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/cardo_python_utils.egg-info/top_level.txt +0 -0
- {cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/python_utils/__init__.py +0 -0
- {cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/python_utils/choices.py +0 -0
- {cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/python_utils/data_structures.py +0 -0
- {cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/python_utils/db.py +0 -0
- {cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/python_utils/django/keycloak/__init__.py +0 -0
- {cardo_python_utils-0.5.dev6/python_utils/django/keycloak → cardo_python_utils-0.5.dev8/python_utils/django/keycloak/api}/drf.py +0 -0
- {cardo_python_utils-0.5.dev6/python_utils/django/keycloak → cardo_python_utils-0.5.dev8/python_utils/django/keycloak/api}/ninja.py +0 -0
- /cardo_python_utils-0.5.dev6/python_utils/django/keycloak/models.py → /cardo_python_utils-0.5.dev8/python_utils/django/keycloak/models/user_group.py +0 -0
- {cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/python_utils/django/keycloak/service.py +0 -0
- {cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/python_utils/django/utils.py +0 -0
- {cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/python_utils/esma_choices.py +0 -0
- {cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/python_utils/exceptions.py +0 -0
- {cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/python_utils/imports.py +0 -0
- {cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/python_utils/math.py +0 -0
- {cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/python_utils/text.py +0 -0
- {cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/python_utils/time.py +0 -0
- {cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/python_utils/types_hinting.py +0 -0
- {cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/setup.cfg +0 -0
{cardo_python_utils-0.5.dev6/cardo_python_utils.egg-info → cardo_python_utils-0.5.dev8}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cardo-python-utils
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.dev8
|
|
4
4
|
Summary: Python library enhanced with a wide range of functions for different scenarios.
|
|
5
5
|
Author-email: CardoAI <hello@cardoai.com>
|
|
6
6
|
License: MIT
|
|
@@ -24,10 +24,9 @@ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
|
24
24
|
Requires-Python: >=3.8
|
|
25
25
|
Description-Content-Type: text/x-rst
|
|
26
26
|
License-File: LICENSE
|
|
27
|
-
Provides-Extra: django-keycloak
|
|
28
|
-
Requires-Dist: PyJWT>=2.10.1; extra == "django-keycloak
|
|
29
|
-
|
|
30
|
-
Requires-Dist: mozilla-django-oidc>=4.0.1; extra == "django-keycloak-admin"
|
|
27
|
+
Provides-Extra: django-keycloak
|
|
28
|
+
Requires-Dist: PyJWT>=2.10.1; extra == "django-keycloak"
|
|
29
|
+
Requires-Dist: mozilla-django-oidc>=4.0.1; extra == "django-keycloak"
|
|
31
30
|
Provides-Extra: django-keycloak-groups
|
|
32
31
|
Requires-Dist: python-keycloak>=5.8.1; extra == "django-keycloak-groups"
|
|
33
32
|
Provides-Extra: all
|
{cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8/cardo_python_utils.egg-info}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cardo-python-utils
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.dev8
|
|
4
4
|
Summary: Python library enhanced with a wide range of functions for different scenarios.
|
|
5
5
|
Author-email: CardoAI <hello@cardoai.com>
|
|
6
6
|
License: MIT
|
|
@@ -24,10 +24,9 @@ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
|
24
24
|
Requires-Python: >=3.8
|
|
25
25
|
Description-Content-Type: text/x-rst
|
|
26
26
|
License-File: LICENSE
|
|
27
|
-
Provides-Extra: django-keycloak
|
|
28
|
-
Requires-Dist: PyJWT>=2.10.1; extra == "django-keycloak
|
|
29
|
-
|
|
30
|
-
Requires-Dist: mozilla-django-oidc>=4.0.1; extra == "django-keycloak-admin"
|
|
27
|
+
Provides-Extra: django-keycloak
|
|
28
|
+
Requires-Dist: PyJWT>=2.10.1; extra == "django-keycloak"
|
|
29
|
+
Requires-Dist: mozilla-django-oidc>=4.0.1; extra == "django-keycloak"
|
|
31
30
|
Provides-Extra: django-keycloak-groups
|
|
32
31
|
Requires-Dist: python-keycloak>=5.8.1; extra == "django-keycloak-groups"
|
|
33
32
|
Provides-Extra: all
|
{cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/cardo_python_utils.egg-info/SOURCES.txt
RENAMED
|
@@ -20,9 +20,12 @@ python_utils/time.py
|
|
|
20
20
|
python_utils/types_hinting.py
|
|
21
21
|
python_utils/django/utils.py
|
|
22
22
|
python_utils/django/keycloak/__init__.py
|
|
23
|
-
python_utils/django/keycloak/admin.py
|
|
24
|
-
python_utils/django/keycloak/drf.py
|
|
25
|
-
python_utils/django/keycloak/models.py
|
|
26
|
-
python_utils/django/keycloak/ninja.py
|
|
27
23
|
python_utils/django/keycloak/service.py
|
|
28
|
-
python_utils/django/keycloak/
|
|
24
|
+
python_utils/django/keycloak/admin/__init__.py
|
|
25
|
+
python_utils/django/keycloak/admin/auth.py
|
|
26
|
+
python_utils/django/keycloak/admin/user_group.py
|
|
27
|
+
python_utils/django/keycloak/api/__init__.py
|
|
28
|
+
python_utils/django/keycloak/api/drf.py
|
|
29
|
+
python_utils/django/keycloak/api/ninja.py
|
|
30
|
+
python_utils/django/keycloak/models/__init__.py
|
|
31
|
+
python_utils/django/keycloak/models/user_group.py
|
{cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/cardo_python_utils.egg-info/requires.txt
RENAMED
|
@@ -10,11 +10,9 @@ pytest-django>=4.5
|
|
|
10
10
|
coverage>=6.0
|
|
11
11
|
tox>=3.25
|
|
12
12
|
|
|
13
|
-
[django-keycloak
|
|
14
|
-
mozilla-django-oidc>=4.0.1
|
|
15
|
-
|
|
16
|
-
[django-keycloak-api]
|
|
13
|
+
[django-keycloak]
|
|
17
14
|
PyJWT>=2.10.1
|
|
15
|
+
mozilla-django-oidc>=4.0.1
|
|
18
16
|
|
|
19
17
|
[django-keycloak-groups]
|
|
20
18
|
python-keycloak>=5.8.1
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "cardo-python-utils"
|
|
7
|
-
version = "0.5.
|
|
7
|
+
version = "0.5.dev8"
|
|
8
8
|
description = "Python library enhanced with a wide range of functions for different scenarios."
|
|
9
9
|
readme = "README.rst"
|
|
10
10
|
requires-python = ">=3.8"
|
|
@@ -31,10 +31,8 @@ classifiers = [
|
|
|
31
31
|
dependencies = []
|
|
32
32
|
|
|
33
33
|
[project.optional-dependencies]
|
|
34
|
-
django-keycloak
|
|
34
|
+
django-keycloak = [
|
|
35
35
|
"PyJWT>=2.10.1",
|
|
36
|
-
]
|
|
37
|
-
django-keycloak-admin = [
|
|
38
36
|
"mozilla-django-oidc>=4.0.1",
|
|
39
37
|
]
|
|
40
38
|
django-keycloak-groups = [
|
|
File without changes
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from django.conf import settings
|
|
2
|
+
from mozilla_django_oidc.auth import OIDCAuthenticationBackend
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class AdminAuthenticationBackend(OIDCAuthenticationBackend):
|
|
6
|
+
def _get_user_data(self, claims) -> dict:
|
|
7
|
+
client_roles = (
|
|
8
|
+
claims.get("resource_access", {})
|
|
9
|
+
.get(getattr(settings, "OIDC_RP_CLIENT_ID", ""), {})
|
|
10
|
+
.get("roles", [])
|
|
11
|
+
)
|
|
12
|
+
is_superuser = "Admin" in client_roles
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
"username": claims.get("preferred_username"),
|
|
16
|
+
"email": claims.get("email"),
|
|
17
|
+
"first_name": claims.get("given_name", ""),
|
|
18
|
+
"last_name": claims.get("family_name", ""),
|
|
19
|
+
"is_staff": claims.get("is_staff", False),
|
|
20
|
+
"is_superuser": is_superuser,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
def filter_users_by_claims(self, claims):
|
|
24
|
+
username = claims.get("preferred_username")
|
|
25
|
+
if not username:
|
|
26
|
+
return self.UserModel.objects.none()
|
|
27
|
+
return self.UserModel.objects.filter(username=username)
|
|
28
|
+
|
|
29
|
+
def create_user(self, claims):
|
|
30
|
+
return self.UserModel.objects.create_user(**self._get_user_data(claims))
|
|
31
|
+
|
|
32
|
+
def update_user(self, user, claims):
|
|
33
|
+
save_needed = False
|
|
34
|
+
|
|
35
|
+
for attr, value in self._get_user_data(claims).items():
|
|
36
|
+
if getattr(user, attr) != value:
|
|
37
|
+
setattr(user, attr, value)
|
|
38
|
+
save_needed = True
|
|
39
|
+
|
|
40
|
+
if save_needed:
|
|
41
|
+
user.save()
|
|
42
|
+
|
|
43
|
+
return user
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def has_admin_site_permission(request):
|
|
47
|
+
"""Admin site is not publicly accessible."""
|
|
48
|
+
return request.user.is_active
|
|
@@ -1,57 +1,9 @@
|
|
|
1
|
-
from django.conf import settings
|
|
2
1
|
from django.contrib import admin, messages
|
|
3
2
|
from django.core.cache import cache
|
|
4
3
|
from django.urls import path
|
|
5
4
|
from django.shortcuts import redirect
|
|
6
|
-
from mozilla_django_oidc.auth import OIDCAuthenticationBackend
|
|
7
5
|
|
|
8
|
-
from
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class KeycloakAuthenticationBackend(OIDCAuthenticationBackend):
|
|
12
|
-
def _get_user_data(self, claims) -> dict:
|
|
13
|
-
client_roles = (
|
|
14
|
-
claims.get("resource_access", {})
|
|
15
|
-
.get(getattr(settings, "OIDC_RP_CLIENT_ID", ""), {})
|
|
16
|
-
.get("roles", [])
|
|
17
|
-
)
|
|
18
|
-
is_superuser = "Admin" in client_roles
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
"username": claims.get("preferred_username"),
|
|
22
|
-
"email": claims.get("email"),
|
|
23
|
-
"first_name": claims.get("given_name", ""),
|
|
24
|
-
"last_name": claims.get("family_name", ""),
|
|
25
|
-
"is_staff": claims.get("is_staff", False),
|
|
26
|
-
"is_superuser": is_superuser,
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
def filter_users_by_claims(self, claims):
|
|
30
|
-
username = claims.get("preferred_username")
|
|
31
|
-
if not username:
|
|
32
|
-
return self.UserModel.objects.none()
|
|
33
|
-
return self.UserModel.objects.filter(username=username)
|
|
34
|
-
|
|
35
|
-
def create_user(self, claims):
|
|
36
|
-
return self.UserModel.objects.create_user(**self._get_user_data(claims))
|
|
37
|
-
|
|
38
|
-
def update_user(self, user, claims):
|
|
39
|
-
save_needed = False
|
|
40
|
-
|
|
41
|
-
for attr, value in self._get_user_data(claims).items():
|
|
42
|
-
if getattr(user, attr) != value:
|
|
43
|
-
setattr(user, attr, value)
|
|
44
|
-
save_needed = True
|
|
45
|
-
|
|
46
|
-
if save_needed:
|
|
47
|
-
user.save()
|
|
48
|
-
|
|
49
|
-
return user
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
def has_admin_site_permission(request):
|
|
53
|
-
"""Admin site is not publicly accessible."""
|
|
54
|
-
return request.user.is_active
|
|
6
|
+
from ..service import KeycloakService
|
|
55
7
|
|
|
56
8
|
|
|
57
9
|
class UserGroupAdminBase(admin.ModelAdmin):
|
|
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
|
{cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/python_utils/django/keycloak/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cardo_python_utils-0.5.dev6 → cardo_python_utils-0.5.dev8}/python_utils/django/keycloak/service.py
RENAMED
|
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
|