cardo-python-utils 0.5.dev25__py3-none-any.whl → 0.5.dev27__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.4
2
2
  Name: cardo-python-utils
3
- Version: 0.5.dev25
3
+ Version: 0.5.dev27
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
@@ -1,4 +1,4 @@
1
- cardo_python_utils-0.5.dev25.dist-info/licenses/LICENSE,sha256=N-YtxDy8n5A1Mo7JKKItNIlboiK_pMOZ48ojx76jo3g,1046
1
+ cardo_python_utils-0.5.dev27.dist-info/licenses/LICENSE,sha256=N-YtxDy8n5A1Mo7JKKItNIlboiK_pMOZ48ojx76jo3g,1046
2
2
  python_utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  python_utils/choices.py,sha256=_sLNkSnQqhg55gGKNRsOQCJ75W6gnz8J8Q00528MEYk,2548
4
4
  python_utils/data_structures.py,sha256=ZqkZYPy20zyGYOVhwb9qst4vF_P7X2A9z5E36rMUC6I,16820
@@ -11,11 +11,11 @@ python_utils/math.py,sha256=p_v8a9nVSe9426nR8H_SM8hOQrkzESVpCnn3gntw7TA,5603
11
11
  python_utils/text.py,sha256=pw9CZeM_Lcw-6k4GyR-4D1Wix8A7F_V1u1IIZTIazW4,3792
12
12
  python_utils/time.py,sha256=7Wei3uJ02Bk-BFRf-e1axoG418XQOhrXPvTwNZgTdnw,9614
13
13
  python_utils/types_hinting.py,sha256=QVWzmXRgNxhvln14tEX_FbQYryuVYhjWJ0dVOnlF6G4,120
14
- python_utils/keycloak/utils.py,sha256=7lyMvAILMD6ooWZXWosHwFLnGikWztDiLK4kFKLQvjw,1826
14
+ python_utils/keycloak/utils.py,sha256=7ku8jj1L-iVRParKbWG6rRaUws0DxgZ-ExeV39b1Emk,1857
15
15
  python_utils/keycloak/django/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  python_utils/keycloak/django/service.py,sha256=FIEC6nYXlZHGgBAWDhOtWmkHoD2xdVxGcZETqKc6L-k,7430
17
17
  python_utils/keycloak/django/admin/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
- python_utils/keycloak/django/admin/auth.py,sha256=r6s_MMVLDCyNhYsH_t4J3A0HbnIDZRRSVvhdoRdrYrE,1724
18
+ python_utils/keycloak/django/admin/auth.py,sha256=GlYyokX_nbZiVHa_LlCCrdaKHa9oop7pX1IOspS4mPs,1920
19
19
  python_utils/keycloak/django/admin/user_group.py,sha256=SeXXHL3MRsCxWsdrxfEtXUYT6gqsoLgAaW5rKzyBqck,6063
20
20
  python_utils/keycloak/django/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
21
  python_utils/keycloak/django/api/drf.py,sha256=i4vZoZXta8IOsGO5YerAEfVyc9jMyD95lVePuaB4eeg,2919
@@ -25,7 +25,7 @@ python_utils/keycloak/django/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQ
25
25
  python_utils/keycloak/django/models/user_group.py,sha256=WU_KClfj-pboDIKUDHZQfQuhAPIPXgP-LrEvg9XJjmA,504
26
26
  python_utils/keycloak/django/tests/__init__.py,sha256=Nkt0a7LEHyjLvuEBZ7113VjjAWJlyZlMy-H-JZ5tNcs,252
27
27
  python_utils/keycloak/django/tests/conftest.py,sha256=h0YaOjy2UCBsl4tu-99cFFN91-7s1sGnZBY8cP6hjNI,3176
28
- cardo_python_utils-0.5.dev25.dist-info/METADATA,sha256=QrrQGUhgtfmrtzjMjCIGNkr_U7_bsOvGOGrFf6Hs6qc,2915
29
- cardo_python_utils-0.5.dev25.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
30
- cardo_python_utils-0.5.dev25.dist-info/top_level.txt,sha256=zAx6OfEsjJs8BEW3okSiG_j9gpkI69xWShzum6oBgKI,13
31
- cardo_python_utils-0.5.dev25.dist-info/RECORD,,
28
+ cardo_python_utils-0.5.dev27.dist-info/METADATA,sha256=B7B__6PGcEosCJwBqY4m90Dj2990NYlA5sjGUaB8VDE,2915
29
+ cardo_python_utils-0.5.dev27.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
30
+ cardo_python_utils-0.5.dev27.dist-info/top_level.txt,sha256=zAx6OfEsjJs8BEW3okSiG_j9gpkI69xWShzum6oBgKI,13
31
+ cardo_python_utils-0.5.dev27.dist-info/RECORD,,
@@ -6,15 +6,18 @@ from ...utils import get_keycloak_confidential_client_token
6
6
 
7
7
  class AdminAuthenticationBackend(OIDCAuthenticationBackend):
8
8
  def get_token(self, payload):
9
- return get_keycloak_confidential_client_token()
9
+ # Instead of passing client_id and client_secret,
10
+ # client_assertion with service account token will be used
11
+ payload.pop("client_id", None)
12
+ payload.pop("client_secret", None)
13
+
14
+ return get_keycloak_confidential_client_token(**payload)
10
15
 
11
16
  def _get_user_data(self, claims) -> dict:
12
17
  client_roles = (
13
- claims.get("resource_access", {})
14
- .get(getattr(settings, "OIDC_RP_CLIENT_ID", ""), {})
15
- .get("roles", [])
18
+ claims.get("resource_access", {}).get(getattr(settings, "OIDC_RP_CLIENT_ID", ""), {}).get("roles", [])
16
19
  )
17
- is_superuser = "Admin" in client_roles
20
+ is_superuser = "AdminPanel" in client_roles
18
21
 
19
22
  return {
20
23
  "username": claims.get("preferred_username"),
@@ -31,17 +31,19 @@ def get_confidential_client_service_account_token() -> str:
31
31
  return token
32
32
 
33
33
 
34
- def get_keycloak_confidential_client_token() -> dict:
34
+ def get_keycloak_confidential_client_token(**kwargs) -> dict:
35
35
  """
36
36
  Obtains token for a Keycloak confidential client with the client credentials grant,
37
37
  using a service account token for authentication.
38
38
  """
39
+
39
40
  response = requests.post(
40
41
  KEYCLOAK_TOKEN_ENDPOINT,
41
42
  data={
42
43
  "grant_type": KEYCLOAK_CLIENT_CREDENTIALS_GRANT_TYPE,
43
44
  "client_assertion_type": KEYCLOAK_CLIENT_ASSERTION_TYPE,
44
45
  "client_assertion": get_confidential_client_service_account_token(),
46
+ **kwargs,
45
47
  },
46
48
  )
47
49
  response.raise_for_status()